Fixed couple bugs and upgraded the scripts
This commit is contained in:
parent
4a117f39c7
commit
06e41dbd30
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
output/
|
output/
|
||||||
|
.env
|
||||||
|
7
Makefile
Normal file
7
Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
all:
|
||||||
|
echo OK
|
||||||
|
backup:
|
||||||
|
bash backup-mysql.sh
|
||||||
|
|
||||||
|
cleanup-empty-files:
|
||||||
|
bash cleanup-empty-files.sh
|
@ -2,13 +2,23 @@
|
|||||||
|
|
||||||
USER="root"
|
USER="root"
|
||||||
PASSWORD="secretpass"
|
PASSWORD="secretpass"
|
||||||
GZIP="1"
|
GZIP_ENABLED="1"
|
||||||
OUTPUT_DIR="./output"
|
OUTPUT_DIR="./output"
|
||||||
HOSTNAME="127.0.0.1"
|
HOSTNAME="127.0.0.1"
|
||||||
|
|
||||||
USE_PASSWORD="0"
|
USE_PASSWORD="0"
|
||||||
USE_HOSTNAME="0"
|
USE_HOSTNAME="0"
|
||||||
|
|
||||||
|
# automatically export all variables
|
||||||
|
set -a
|
||||||
|
source .env
|
||||||
|
set +a
|
||||||
|
|
||||||
|
if [ "${DEBUG}" -gt "0" ]
|
||||||
|
then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
|
||||||
PASSWORD_OPTIONS="-p${PASSWORD}"
|
PASSWORD_OPTIONS="-p${PASSWORD}"
|
||||||
HOST_OPTIONS="-h ${HOSTNAME}"
|
HOST_OPTIONS="-h ${HOSTNAME}"
|
||||||
|
|
||||||
@ -32,7 +42,7 @@ for db in ${databases}; do
|
|||||||
mkdir -vp "${DUMP_DIR}"
|
mkdir -vp "${DUMP_DIR}"
|
||||||
|
|
||||||
echo "Dumping database: ${db} into: ${DUMP_FILENAME}"
|
echo "Dumping database: ${db} into: ${DUMP_FILENAME}"
|
||||||
if [ "${GZIP}" -gt "0" ]
|
if [ "${GZIP_ENABLED}" -gt "0" ]
|
||||||
then
|
then
|
||||||
mysqldump ${HOST_OPTIONS} -u ${USER} ${PASSWORD_OPTIONS} --default-character-set=utf8mb4 --routines=true --triggers=true --databases ${db} | gzip > "${DUMP_FILENAME}.gz"
|
mysqldump ${HOST_OPTIONS} -u ${USER} ${PASSWORD_OPTIONS} --default-character-set=utf8mb4 --routines=true --triggers=true --databases ${db} | gzip > "${DUMP_FILENAME}.gz"
|
||||||
else
|
else
|
||||||
@ -40,3 +50,5 @@ for db in ${databases}; do
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
set +x
|
||||||
|
24
cleanup-empty-files.sh
Executable file
24
cleanup-empty-files.sh
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
USER="root"
|
||||||
|
PASSWORD="secretpass"
|
||||||
|
GZIP_ENABLED="1"
|
||||||
|
OUTPUT_DIR="./output"
|
||||||
|
HOSTNAME="127.0.0.1"
|
||||||
|
|
||||||
|
USE_PASSWORD="0"
|
||||||
|
USE_HOSTNAME="0"
|
||||||
|
|
||||||
|
# automatically export all variables
|
||||||
|
set -a
|
||||||
|
source .env
|
||||||
|
set +a
|
||||||
|
|
||||||
|
if [ "${DEBUG}" -gt "0" ]
|
||||||
|
then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
|
||||||
|
find "${OUTPUT_DIR}" -type f -size 0 -exec rm -v {} \;
|
||||||
|
|
||||||
|
set +x
|
@ -4,10 +4,20 @@ USER="root"
|
|||||||
PASSWORD="secretpass"
|
PASSWORD="secretpass"
|
||||||
OUTPUT_DIR="./output"
|
OUTPUT_DIR="./output"
|
||||||
HOSTNAME="127.0.0.1"
|
HOSTNAME="127.0.0.1"
|
||||||
|
GZIP_ENABLED="1"
|
||||||
|
|
||||||
USE_PASSWORD="0"
|
USE_PASSWORD="0"
|
||||||
USE_HOSTNAME="0"
|
USE_HOSTNAME="0"
|
||||||
|
|
||||||
|
set -a # automatically export all variables
|
||||||
|
source .env
|
||||||
|
set +a
|
||||||
|
|
||||||
|
if [ "${DEBUG}" -gt "0" ]
|
||||||
|
then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
|
||||||
PASSWORD_OPTIONS="-p${PASSWORD}"
|
PASSWORD_OPTIONS="-p${PASSWORD}"
|
||||||
HOST_OPTIONS="-h ${HOSTNAME}"
|
HOST_OPTIONS="-h ${HOSTNAME}"
|
||||||
|
|
||||||
@ -34,16 +44,16 @@ for db in ${databases}; do
|
|||||||
file "${DUMP_FILENAME}" | grep "gzip compressed data" >/dev/null
|
file "${DUMP_FILENAME}" | grep "gzip compressed data" >/dev/null
|
||||||
if [ "$?" -eq "0" ]
|
if [ "$?" -eq "0" ]
|
||||||
then
|
then
|
||||||
GZIP="1"
|
GZIP_ENABLED="1"
|
||||||
else
|
else
|
||||||
GZIP="0"
|
GZIP_ENABLED="0"
|
||||||
fi
|
fi
|
||||||
echo "Restoring database: ${db} from: ${DUMP_FILENAME}"
|
echo "Restoring database: ${db} from: ${DUMP_FILENAME}"
|
||||||
echo "Trying to create the DB:"
|
echo "Trying to create the DB:"
|
||||||
mysql ${HOST_OPTIONS} -u ${USER} ${PASSWORD_OPTIONS} --default-character-set=utf8mb4 -e "CREATE DATABASE ${db} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
mysql ${HOST_OPTIONS} -u ${USER} ${PASSWORD_OPTIONS} --default-character-set=utf8mb4 -e "CREATE DATABASE ${db} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||||
|
|
||||||
echo "Restoring DB from backup file"
|
echo "Restoring DB from backup file"
|
||||||
if [ "${GZIP}" -gt "0" ]
|
if [ "${GZIP_ENABLED}" -gt "0" ]
|
||||||
then
|
then
|
||||||
gunzip "${DUMP_FILENAME}" | mysql ${HOST_OPTIONS} -u ${USER} ${PASSWORD_OPTIONS} --default-character-set=utf8mb4 ${db}
|
gunzip "${DUMP_FILENAME}" | mysql ${HOST_OPTIONS} -u ${USER} ${PASSWORD_OPTIONS} --default-character-set=utf8mb4 ${db}
|
||||||
else
|
else
|
||||||
@ -51,3 +61,5 @@ for db in ${databases}; do
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
set +x
|
||||||
|
Loading…
Reference in New Issue
Block a user