mirror of
https://github.com/fradelg/docker-mysql-cron-backup.git
synced 2025-01-18 16:22:33 +01:00
commit
4c71297f03
2 changed files with 4 additions and 3 deletions
|
@ -20,6 +20,7 @@ This docker image runs mysqldump to backup your databases periodically using cro
|
|||
MYSQL_USER the username of your mysql database
|
||||
MYSQL_PASS the password of your mysql database
|
||||
MYSQL_DB the database name to dump. Default: `--all-databases`
|
||||
MYSQLDUMP_OPTS command line arguments to pass to mysqldump. Example: `--single-transaction`
|
||||
CRON_TIME the interval of cron job to run mysqldump. `0 0 * * *` by default, which is every day at 00:00
|
||||
MAX_BACKUPS the number of backups to keep. When reaching the limit, the old backup will be discarded. No limit by default
|
||||
INIT_BACKUP if set, create a backup when the container starts
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#!/bin/bash
|
||||
[ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; }
|
||||
[ -z "${MYSQL_PASS}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; }
|
||||
[ -z "${MYSQL_PASS:=$MYSQL_PASSWORD}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; }
|
||||
|
||||
DATE=$(date +%Y%m%d%H%M)
|
||||
echo "=> Backup started at $DATE"
|
||||
databases=$(mysql -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" -e "SHOW DATABASES;" | tr -d "| " | grep -v Database)
|
||||
databases=${MYSQL_DATABASE:-${MYSQL_DB:-$(mysql -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" -e "SHOW DATABASES;" | tr -d "| " | grep -v Database)}}
|
||||
for db in $databases
|
||||
do
|
||||
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]]
|
||||
then
|
||||
echo "Dumping database: $db"
|
||||
FILENAME=/backup/$DATE.$db.sql
|
||||
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" --databases "$db" > "$FILENAME"
|
||||
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" --databases "$db" $MYSQLDUMP_OPTS > "$FILENAME"
|
||||
then
|
||||
gzip -f "$FILENAME"
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue