mirror of
https://github.com/fradelg/docker-mysql-cron-backup.git
synced 2025-01-18 16:22:33 +01:00
commit
d172e583b0
3 changed files with 4 additions and 3 deletions
|
@ -22,6 +22,7 @@ docker container run -d \
|
||||||
- `MYSQL_PASS_FILE`: The file in container where to find the password of your mysql database (cf. docker secrets). You should use either MYSQL_PASS_FILE or MYSQL_PASS (see examples below).
|
- `MYSQL_PASS_FILE`: The file in container where to find the password of your mysql database (cf. docker secrets). You should use either MYSQL_PASS_FILE or MYSQL_PASS (see examples below).
|
||||||
- `MYSQL_DATABASE`: The database name to dump. Default: `--all-databases`.
|
- `MYSQL_DATABASE`: The database name to dump. Default: `--all-databases`.
|
||||||
- `MYSQLDUMP_OPTS`: Command line arguments to pass to mysqldump (see [mysqldump documentation](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html)).
|
- `MYSQLDUMP_OPTS`: Command line arguments to pass to mysqldump (see [mysqldump documentation](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html)).
|
||||||
|
- `MYSQL_SSL_OPTS`: Command line arguments to use [SSL](https://dev.mysql.com/doc/refman/5.6/en/using-encrypted-connections.html).
|
||||||
- `CRON_TIME`: The interval of cron job to run mysqldump. `0 3 * * sun` by default, which is every Sunday at 03:00. It uses UTC timezone.
|
- `CRON_TIME`: The interval of cron job to run mysqldump. `0 3 * * sun` by default, which is every Sunday at 03:00. It uses UTC timezone.
|
||||||
- `MAX_BACKUPS`: The number of backups to keep. When reaching the limit, the old backup will be discarded. No limit by default.
|
- `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.
|
- `INIT_BACKUP`: If set, create a backup when the container starts.
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
DATE=$(date +%Y%m%d%H%M)
|
DATE=$(date +%Y%m%d%H%M)
|
||||||
echo "=> Backup started at $(date "+%Y-%m-%d %H:%M:%S")"
|
echo "=> Backup started at $(date "+%Y-%m-%d %H:%M:%S")"
|
||||||
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)}}
|
DATABASES=${MYSQL_DATABASE:-${MYSQL_DB:-$(mysql -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $MYSQL_SSL_OPTS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database)}}
|
||||||
for db in ${DATABASES}
|
for db in ${DATABASES}
|
||||||
do
|
do
|
||||||
if [[ "$db" != "information_schema" ]] \
|
if [[ "$db" != "information_schema" ]] \
|
||||||
|
@ -21,7 +21,7 @@ do
|
||||||
echo "==> Dumping database: $db"
|
echo "==> Dumping database: $db"
|
||||||
FILENAME=/backup/$DATE.$db.sql
|
FILENAME=/backup/$DATE.$db.sql
|
||||||
LATEST=/backup/latest.$db.sql
|
LATEST=/backup/latest.$db.sql
|
||||||
if mysqldump --single-transaction $MYSQLDUMP_OPTS -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" > "$FILENAME"
|
if mysqldump --single-transaction $MYSQLDUMP_OPTS -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $MYSQL_SSL_OPTS "$db" > "$FILENAME"
|
||||||
then
|
then
|
||||||
EXT=
|
EXT=
|
||||||
if [ -z "${USE_PLAIN_SQL}" ]
|
if [ -z "${USE_PLAIN_SQL}" ]
|
||||||
|
|
|
@ -30,7 +30,7 @@ fi
|
||||||
|
|
||||||
echo "=> Restore database $DB_NAME from $1"
|
echo "=> Restore database $DB_NAME from $1"
|
||||||
|
|
||||||
if echo "$SQL" | mysql -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$DB_NAME"
|
if echo "$SQL" | mysql -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $MYSQL_SSL_OPTS "$DB_NAME"
|
||||||
then
|
then
|
||||||
echo "=> Restore succeeded"
|
echo "=> Restore succeeded"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue