From 3db704557a11406d749afef37dd9e134b1bd5740 Mon Sep 17 00:00:00 2001 From: Richard Scorer Date: Thu, 3 Sep 2020 14:30:21 +0100 Subject: [PATCH] Add ability to set gzip compression level --- README.md | 3 +++ backup.sh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ffcfed..f44fe2c 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ docker container run -d \ - `INIT_BACKUP`: If set, create a backup when the container starts. - `INIT_RESTORE_LATEST`: If set, restores latest backup. - `TIMEOUT`: Wait a given number of seconds for the database to be ready and make the first backup, `10s` by default. After that time, the initial attempt for backup gives up and only the Cron job will try to make a backup. +- `GZIP_LEVEL`: Specify the level of gzip compression from 1 (quickest, least compressed) to 9 (slowest, most compressed), default is 6. If you want to make this image the perfect companion of your MySQL container, use [docker-compose](https://docs.docker.com/compose/). You can add more services that will be able to connect to the MySQL image using the name `my_mariadb`, note that you only expose the port `3306` internally to the servers and not to the host: @@ -62,6 +63,8 @@ services: - INIT_BACKUP=0 # Every day at 03:00 - CRON_TIME=0 3 * * * + # Make it small + - GZIP_LEVEL=9 restart: unless-stopped volumes: diff --git a/backup.sh b/backup.sh index 30314da..2a01db6 100755 --- a/backup.sh +++ b/backup.sh @@ -1,6 +1,7 @@ #!/bin/bash [ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; } [ -z "${MYSQL_PASS:=$MYSQL_PASSWORD}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; } +[ -z "${GZIP_LEVEL}" ] && { GZIP_LEVEL=6; } DATE=$(date +%Y%m%d%H%M) echo "=> Backup started at $(date "+%Y-%m-%d %H:%M:%S")" @@ -15,7 +16,7 @@ do LATEST=/backup/latest.$db.sql.gz if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" --databases "$db" $MYSQLDUMP_OPTS > "$FILENAME" then - gzip -f "$FILENAME" + gzip "-$GZIP_LEVEL" -f "$FILENAME" echo "==> Creating symlink to latest backup: $(basename "$FILENAME".gz)" rm "$LATEST" 2> /dev/null cd /backup && ln -s $(basename "$FILENAME".gz) $(basename "$LATEST") && cd -