Merge pull request #32 from rscorer/feature/gzip-level

Add ability to set gzip compression level
This commit is contained in:
Fco. Javier Delgado del Hoyo 2020-09-03 19:21:35 +02:00 committed by GitHub
commit d06c483950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -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:

View file

@ -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 -