1
This commit is contained in:
commit
d7fd024277
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
output/
|
42
backup-mysql.sh
Executable file
42
backup-mysql.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
USER="root"
|
||||
PASSWORD="secretpass"
|
||||
GZIP="1"
|
||||
OUTPUT_DIR="./output"
|
||||
HOSTNAME="127.0.0.1"
|
||||
|
||||
USE_PASSWORD="0"
|
||||
USE_HOSTNAME="0"
|
||||
|
||||
PASSWORD_OPTIONS="-p${PASSWORD}"
|
||||
HOST_OPTIONS="-h ${HOSTNAME}"
|
||||
|
||||
if [ "${USE_HOSTNAME}" -eq "0" ]
|
||||
then
|
||||
HOST_OPTIONS=""
|
||||
fi
|
||||
|
||||
if [ "${USE_PASSWORD}" -eq "0" ]
|
||||
then
|
||||
PASSWORD_OPTIONS=""
|
||||
fi
|
||||
|
||||
databases=$(mysql ${HOST_OPTIONS} -u ${USER} ${PASSWORD_OPTIONS} --batch -s -r -e 'show databases')
|
||||
|
||||
for db in ${databases}; do
|
||||
if [[ "${db}" != "information_schema" ]] && [[ "${db}" != "performance_schema" ]] && [[ "${db}" != "mysql" ]] && [[ "${db}" != _* ]]
|
||||
then
|
||||
DUMP_DIR="${OUTPUT_DIR}/${db}"
|
||||
DUMP_FILENAME="${DUMP_DIR}/$(date +%Y%m%d_%H:%M:%S).${db}.sql"
|
||||
mkdir -vp "${DUMP_DIR}"
|
||||
|
||||
echo "Dumping database: ${db} into: ${DUMP_FILENAME}"
|
||||
if [ "${GZIP}" -gt "0" ]
|
||||
then
|
||||
mysqldump ${HOST_OPTIONS} -u ${USER} ${PASSWORD_OPTIONS} --default-character-set=utf8mb4 --routines=true --triggers=true --databases ${db} | gzip > "${DUMP_FILENAME}.gz"
|
||||
else
|
||||
mysqldump ${HOST_OPTIONS} -u ${USER} ${PASSWORD_OPTIONS} --default-character-set=utf8mb4 --routines=true --triggers=true --databases ${db} > "${DUMP_FILENAME}"
|
||||
fi
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue
Block a user