From 6b192172851f23c50fe9cd8832503aa22918a12a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Jul 2022 04:23:29 +0000 Subject: [PATCH 01/55] Bump alpine from 3.16.0 to 3.16.1 Bumps alpine from 3.16.0 to 3.16.1. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9b3497b..b2107ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.16.0 +FROM alpine:3.16.1 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From bde69eaf1afe4696061d9ed642b99503b915906e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Aug 2022 04:21:29 +0000 Subject: [PATCH 02/55] Bump alpine from 3.16.1 to 3.16.2 Bumps alpine from 3.16.1 to 3.16.2. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b2107ec..fdf3895 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.16.1 +FROM alpine:3.16.2 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 9b542daf425568c2210cc1b8cbbf594ed7e4f64d Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Mon, 15 Aug 2022 10:20:22 +0200 Subject: [PATCH 03/55] use docker --username instead of docker -u --- .github/workflows/image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 6dba542..8d51bd3 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -32,7 +32,7 @@ jobs: id: docker-tag uses: yuya-takeyama/docker-tag-from-github-ref-action@v1 - name: Login to Docker Hub - run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin - name: Build multiarch image run: | docker buildx build --push \ From 37a840010341a1c3a58c2bf7ce979f9e615ebd78 Mon Sep 17 00:00:00 2001 From: Skimpax <2030318-skimpax@users.noreply.gitlab.com> Date: Sat, 15 Oct 2022 07:49:01 +0200 Subject: [PATCH 04/55] Add ability to use secrets for mysql access --- backup.sh | 12 ++++++++++-- restore.sh | 12 ++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/backup.sh b/backup.sh index d251ed7..450bb41 100755 --- a/backup.sh +++ b/backup.sh @@ -1,10 +1,18 @@ #!/bin/bash +# Get hostname: try read from file, else get from env +[ -z "${MYSQL_HOST_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_HOST_FILE}"); } +[ -z "${MYSQL_HOST}" ] && { echo "=> MYSQL_HOST cannot be empty" && exit 1; } +# Get username: try read from file, else get from env +[ -z "${MYSQL_USER_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_USER_FILE}"); } [ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; } -# If provided, take password from file +# Get password: try read from file, else get from env, else get from MYSQL_PASSWORD env [ -z "${MYSQL_PASS_FILE}" ] || { MYSQL_PASS=$(head -1 "${MYSQL_PASS_FILE}"); } -# Alternatively, take it from env var [ -z "${MYSQL_PASS:=$MYSQL_PASSWORD}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; } +# Get database name(s): try read from file, else get from env +# Note: when from file, there can be one database name per line in that file +[ -z "${MYSQL_DATABASE_FILE}" ] || { MYSQL_DATABASE=$(cat "${MYSQL_DATABASE_FILE}"); } +# Get level from env, else use 6 [ -z "${GZIP_LEVEL}" ] && { GZIP_LEVEL=6; } DATE=$(date +%Y%m%d%H%M) diff --git a/restore.sh b/restore.sh index 15d6b81..e17b61c 100755 --- a/restore.sh +++ b/restore.sh @@ -1,10 +1,14 @@ #!/bin/bash +# Get hostname: try read from file, else get from env +[ -z "${MYSQL_HOST_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_HOST_FILE}"); } +[ -z "${MYSQL_HOST}" ] && { echo "=> MYSQL_HOST cannot be empty" && exit 1; } +# Get username: try read from file, else get from env +[ -z "${MYSQL_USER_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_USER_FILE}"); } [ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; } -# If provided, take password from file +# Get password: try read from file, else get from env, else get from MYSQL_PASSWORD env [ -z "${MYSQL_PASS_FILE}" ] || { MYSQL_PASS=$(head -1 "${MYSQL_PASS_FILE}"); } -# Alternatively, take it from env var -[ -z "${MYSQL_PASS}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; } +[ -z "${MYSQL_PASS:=$MYSQL_PASSWORD}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; } if [ "$#" -ne 1 ] then @@ -14,7 +18,7 @@ fi set -o pipefail if [ -z "${USE_PLAIN_SQL}" ] -then +then SQL=$(gunzip -c "$1") else SQL=$(cat "$1") From 4abf8c5d9d379052c36d5c4759efe67ee4ddd8b4 Mon Sep 17 00:00:00 2001 From: Skimpax <2030318-skimpax@users.noreply.gitlab.com> Date: Sat, 15 Oct 2022 07:55:10 +0200 Subject: [PATCH 05/55] Update Readme for secrets use --- README.md | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bcd60ff..8dc88b9 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,11 @@ docker container run -d \ - `MYSQL_HOST`: The host/ip of your mysql database. - `MYSQL_PORT`: The port number of your mysql database. - `MYSQL_USER`: The username of your mysql database. +- `MYSQL_USER_FILE`: The file in container where to find the user of your mysql database (cf. docker secrets). You should use either MYSQL_USER_FILE or MYSQL_USER (see examples below). - `MYSQL_PASS`: The password of your mysql database. - `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_FILE`: The file in container where to find the database name in your mysql database (cf. docker secrets). You should use either MYSQL_DATABASE or MYSQL_DATABASE_FILE (see examples below). - `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. @@ -79,17 +81,23 @@ volumes: The database root password passed to docker container by using [docker secrets](https://docs.docker.com/engine/swarm/). -In example below, docker is in classic 'docker engine mode' (iow. not swarm mode) and secret source is a local file on host filesystem. +In example below, docker is in classic 'docker engine mode' (iow. not swarm mode) and secret sources are local files on host filesystem. -Alternatively, secret can be stored in docker secrets engine (iow. not in host filesystem). +Alternatively, secrets can be stored in docker secrets engine (iow. not in host filesystem). ```yaml version: "3.7" secrets: + # Place your secret file somewhere on your host filesystem, with your password inside mysql_root_password: - # Place your secret file somewhere on your host filesystem, with your password inside file: ./secrets/mysql_root_password + mysql_user: + file: ./secrets/mysql_user + mysql_password: + file: ./secrets/mysql_password + mysql_database: + file: ./secrets/mysql_database services: mariadb: @@ -101,10 +109,15 @@ services: - data:/var/lib/mysql - ${VOLUME_PATH}/backup:/backup environment: - - MYSQL_DATABASE=${DATABASE_NAME} - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password + - MYSQL_USER_FILE=/run/secrets/mysql_user + - MYSQL_PASSWORD_FILE=/run/secrets/mysql_password + - MYSQL_DATABASE_FILE=/run/secrets/mysql_database secrets: - mysql_root_password + - mysql_user + - mysql_password + - mysql_database restart: unless-stopped backup: @@ -116,13 +129,18 @@ services: - ${VOLUME_PATH}/backup:/backup environment: - MYSQL_HOST=my_mariadb - - MYSQL_USER=root - - MYSQL_PASS_FILE=/run/secrets/mysql_root_password + # Alternatively to MYSQL_USER_FILE, we can use MYSQL_USER=root to use root user instead + - MYSQL_USER_FILE=/run/secrets/mysql_user + # Alternatively, we can use /run/secrets/mysql_root_password when using root user + - MYSQL_PASS_FILE=/run/secrets/mysql_password + - MYSQL_DATABASE_FILE=/run/secrets/mysql_database - MAX_BACKUPS=10 - INIT_BACKUP=1 - CRON_TIME=0 0 * * * secrets: - - mysql_root_password + - mysql_user + - mysql_password + - mysql_database restart: unless-stopped volumes: From 7bc94755f21625d210a4c0ac23e45e91b5310a5c Mon Sep 17 00:00:00 2001 From: Skimpax <2030318-skimpax@users.noreply.gitlab.com> Date: Sun, 16 Oct 2022 21:46:12 +0200 Subject: [PATCH 06/55] Fix copy/paste errors --- backup.sh | 2 +- restore.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backup.sh b/backup.sh index 450bb41..33ff1b1 100755 --- a/backup.sh +++ b/backup.sh @@ -1,7 +1,7 @@ #!/bin/bash # Get hostname: try read from file, else get from env -[ -z "${MYSQL_HOST_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_HOST_FILE}"); } +[ -z "${MYSQL_HOST_FILE}" ] || { MYSQL_HOST=$(head -1 "${MYSQL_HOST_FILE}"); } [ -z "${MYSQL_HOST}" ] && { echo "=> MYSQL_HOST cannot be empty" && exit 1; } # Get username: try read from file, else get from env [ -z "${MYSQL_USER_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_USER_FILE}"); } diff --git a/restore.sh b/restore.sh index e17b61c..0607d6f 100755 --- a/restore.sh +++ b/restore.sh @@ -1,7 +1,7 @@ #!/bin/bash # Get hostname: try read from file, else get from env -[ -z "${MYSQL_HOST_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_HOST_FILE}"); } +[ -z "${MYSQL_HOST_FILE}" ] || { MYSQL_HOST=$(head -1 "${MYSQL_HOST_FILE}"); } [ -z "${MYSQL_HOST}" ] && { echo "=> MYSQL_HOST cannot be empty" && exit 1; } # Get username: try read from file, else get from env [ -z "${MYSQL_USER_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_USER_FILE}"); } From d1f887f83c4567665e32dbbf4e0b246be6db4260 Mon Sep 17 00:00:00 2001 From: Skimpax <2030318-skimpax@users.noreply.gitlab.com> Date: Sun, 16 Oct 2022 21:46:32 +0200 Subject: [PATCH 07/55] Add details in README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8dc88b9..923ec5e 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,16 @@ docker container run -d \ ## Variables + - `MYSQL_HOST`: The host/ip of your mysql database. +- `MYSQL_HOST_FILE`: The file in container where to find the host of your mysql database (cf. docker secrets). You should use either MYSQL_HOST_FILE or MYSQL_HOST (see examples below). - `MYSQL_PORT`: The port number of your mysql database. - `MYSQL_USER`: The username of your mysql database. - `MYSQL_USER_FILE`: The file in container where to find the user of your mysql database (cf. docker secrets). You should use either MYSQL_USER_FILE or MYSQL_USER (see examples below). - `MYSQL_PASS`: The password of your mysql database. - `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_FILE`: The file in container where to find the database name in your mysql database (cf. docker secrets). You should use either MYSQL_DATABASE or MYSQL_DATABASE_FILE (see examples below). +- `MYSQL_DATABASE_FILE`: The file in container where to find the database name(s) in your mysql database (cf. docker secrets). In that file, there can be several database names: one per line. You should use either MYSQL_DATABASE or MYSQL_DATABASE_FILE (see examples below). - `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. From 3d32ab2a139d0b3cdff2d3db884bdfa4921ca666 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Nov 2022 04:06:23 +0000 Subject: [PATCH 08/55] Bump alpine from 3.16.2 to 3.16.3 Bumps alpine from 3.16.2 to 3.16.3. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fdf3895..1a4dcd5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.16.2 +FROM alpine:3.16.3 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From e975214636f34afe6547527e2998ada8e842327c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 23 Nov 2022 04:08:05 +0000 Subject: [PATCH 09/55] Bump alpine from 3.16.3 to 3.17.0 Bumps alpine from 3.16.3 to 3.17.0. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1a4dcd5..c06ccf7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.16.3 +FROM alpine:3.17.0 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 218bc5778c0785833dfc63a88dd574bb8bdd7e81 Mon Sep 17 00:00:00 2001 From: "g.nardiello" <giuseppe@nards.it> Date: Thu, 5 Jan 2023 11:44:39 +0100 Subject: [PATCH 10/55] Fixed if on line 4 to accept default 0 value --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 95f8009..6882b95 100755 --- a/run.sh +++ b/run.sh @@ -1,7 +1,7 @@ #!/bin/bash tail -F /mysql_backup.log & -if [ "${INIT_BACKUP}" -gt "0" ]; then +if [ "${INIT_BACKUP:-0}" -gt "0" ]; then echo "=> Create a backup on the startup" /backup.sh elif [ -n "${INIT_RESTORE_LATEST}" ]; then From 400bb8c95e26cdd68340d89d60aacaad7b11a90b Mon Sep 17 00:00:00 2001 From: "g.nardiello" <giuseppe@nards.it> Date: Thu, 5 Jan 2023 11:47:54 +0100 Subject: [PATCH 11/55] Added sort algorithm to RESTORE_LATEST script --- run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 95f8009..a5151f4 100755 --- a/run.sh +++ b/run.sh @@ -11,7 +11,8 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then echo "waiting database container..." sleep 1 done - find /backup -maxdepth 1 -name '*.sql.gz' | tail -1 | xargs /restore.sh + # The [^l] is needed to exclude the latest backup file, and sort only data-tagged backups + find /backup -maxdepth 1 -name '[^l]*.sql.gz' | sort | tail -1 | xargs /restore.sh fi echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf From 39d39915e464041792909d4c1d590f7cf45366d3 Mon Sep 17 00:00:00 2001 From: "g.nardiello" <giuseppe@nards.it> Date: Thu, 5 Jan 2023 11:55:04 +0100 Subject: [PATCH 12/55] Added file-based HEALTHCHECK --- Dockerfile | 5 ++++- run.sh | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c06ccf7..fdfa250 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,4 +41,7 @@ RUN mkdir /backup && \ VOLUME ["/backup"] -CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh +HEALTHCHECK --interval=2s --retries=1800 \ + CMD stat /HEALTLY.status || exit 1 + +ENTRYPOINT dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh \ No newline at end of file diff --git a/run.sh b/run.sh index 95f8009..862a566 100755 --- a/run.sh +++ b/run.sh @@ -14,6 +14,8 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then find /backup -maxdepth 1 -name '*.sql.gz' | tail -1 | xargs /restore.sh fi +touch /HEALTLY.status + echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf crontab /tmp/crontab.conf echo "=> Running cron task manager in foreground" From 74aa80e2b362ec0bc11251c17d4c8859443dc3e5 Mon Sep 17 00:00:00 2001 From: "g.nardiello" <giuseppe@nards.it> Date: Thu, 5 Jan 2023 11:59:16 +0100 Subject: [PATCH 13/55] Added EXIT_BACKUP feature with gracefully shutdown --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- run.sh | 21 +++++++++++++++++- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 923ec5e..1786703 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ docker container run -d \ - `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_RESTORE_LATEST`: If set, restores latest backup. +- `EXIT_BACKUP`: If set, create a backup when the container stops. - `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. - `USE_PLAIN_SQL`: If set, back up and restore plain SQL files without gzip. @@ -184,4 +185,65 @@ mysql-cron-backup: docker container exec <your_mysql_backup_container_name> /restore.sh /backup/<your_sql_backup_gz_file> ``` -if no database name is specified, `restore.sh` will try to find the database name from the backup file. \ No newline at end of file +if no database name is specified, `restore.sh` will try to find the database name from the backup file. + +### Automatic backup and restore on container starts and stops + +Set `INIT_RESTORE_LATEST` to automatic restore the last backup on startup. +Set `EXIT_BACKUP` to automatic create a last backup on shutdown. + +```yaml + mysql-cron-backup: + image: fradelg/mysql-cron-backup + depends_on: + - mariadb + volumes: + - ${VOLUME_PATH}/backup:/backup + environment: + - MYSQL_HOST=my_mariadb + - MYSQL_USER=${MYSQL_USER} + - MYSQL_PASS=${MYSQL_PASSWORD} + - MAX_BACKUPS=15 + - INIT_RESTORE_LATEST=1 + - EXIT_BACKUP=1 + # Every day at 03:00 + - CRON_TIME=0 3 * * * + # Make it small + - GZIP_LEVEL=9 + restart: unless-stopped + +volumes: + data: +``` + +Docker database image could expose a directory you could add files as init sql script. + +```yaml + mysql: + image: mysql + expose: + - 3306 + volumes: + - data:/var/lib/mysql + # If there is not scheme, restore using the init script (if exists) + - ./init-script.sql:/docker-entrypoint-initdb.d/database.sql.gz + environment: + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} + - MYSQL_DATABASE=${DATABASE_NAME} + restart: unless-stopped +``` + +```yaml + mariadb: + image: mariadb + expose: + - 3306 + volumes: + - data:/var/lib/mysql + # If there is not scheme, restore using the init script (if exists) + - ./init-script.sql:/docker-entrypoint-initdb.d/database.sql.gz + environment: + - MYSQL_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD} + - MYSQL_DATABASE=${DATABASE_NAME} + restart: unless-stopped +``` \ No newline at end of file diff --git a/run.sh b/run.sh index 95f8009..ea11ae7 100755 --- a/run.sh +++ b/run.sh @@ -14,7 +14,26 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then find /backup -maxdepth 1 -name '*.sql.gz' | tail -1 | xargs /restore.sh fi +function final_backup { + echo "=> Captured trap for final backup" + DATE=$(date +%Y%m%d%H%M) + echo "=> Requested last backup at $(date "+%Y-%m-%d %H:%M:%S")" + exec /backup.sh + exit 0 +} + +if [ -n "${EXIT_BACKUP}" ]; then + echo "=> Listening on container shutdown gracefully to make last backup before close" + trap final_backup SIGHUP SIGINT SIGTERM +fi + echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf crontab /tmp/crontab.conf echo "=> Running cron task manager in foreground" -exec crond -f -l 8 -L /mysql_backup.log +crond -f -l 8 -L /mysql_backup.log & + +echo "Listening on crond, and wait..." + +while : ; do sleep 1 ; done + +echo "Script is shutted down." \ No newline at end of file From f8307fd40f7e54a870d9e518169be1abdb118f1a Mon Sep 17 00:00:00 2001 From: "g.nardiello" <giuseppe@nards.it> Date: Fri, 6 Jan 2023 08:43:40 +0100 Subject: [PATCH 14/55] Improved docs for Healthcheck --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 923ec5e..8d3a2dd 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ docker container run -d \ fradelg/mysql-cron-backup ``` +### Healthcheck + + +Healthcheck is provided as a basic init control. +Container is **Healthly** after the database init phase, that is after `INIT_BACKUP` or `INIT_RESTORE_LATEST` happends without check if there is an error, **Starting** otherwise. Not other checks are actually provided. + ## Variables From ee27961c60a594ad274a2da8c348b62fffe20bbc Mon Sep 17 00:00:00 2001 From: "g.nardiello" <giuseppe@nards.it> Date: Fri, 6 Jan 2023 09:29:31 +0100 Subject: [PATCH 15/55] Delete strategy moved to new file, as could custom --- Dockerfile | 4 ++-- backup.sh | 8 +------- delete.sh | 7 +++++++ 3 files changed, 10 insertions(+), 9 deletions(-) create mode 100755 delete.sh diff --git a/Dockerfile b/Dockerfile index c06ccf7..be861f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,10 +32,10 @@ ENV CRON_TIME="0 3 * * sun" \ TIMEOUT="10s" \ MYSQLDUMP_OPTS="--quick" -COPY ["run.sh", "backup.sh", "restore.sh", "/"] +COPY ["run.sh", "backup.sh", "restore.sh", "/delete.sh", "/"] RUN mkdir /backup && \ chmod 777 /backup && \ - chmod 755 /run.sh /backup.sh /restore.sh && \ + chmod 755 /run.sh /backup.sh /restore.sh /delete.sh && \ touch /mysql_backup.log && \ chmod 666 /mysql_backup.log diff --git a/backup.sh b/backup.sh index 33ff1b1..70f7761 100755 --- a/backup.sh +++ b/backup.sh @@ -46,13 +46,7 @@ do cd /backup || exit && ln -s "$BASENAME" "$(basename "$LATEST")" if [ -n "$MAX_BACKUPS" ] then - while [ "$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | wc -l)" -gt "$MAX_BACKUPS" ] - do - TARGET=$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | sort | head -n 1) - echo "==> Max number of ($MAX_BACKUPS) backups reached. Deleting ${TARGET} ..." - rm -rf "${TARGET}" - echo "==> Backup ${TARGET} deleted" - done + exec /delete.sh fi else rm -rf "$FILENAME" diff --git a/delete.sh b/delete.sh new file mode 100755 index 0000000..59f138c --- /dev/null +++ b/delete.sh @@ -0,0 +1,7 @@ +while [ "$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | wc -l)" -gt "$MAX_BACKUPS" ] +do + TARGET=$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | sort | head -n 1) + echo "==> Max number of ($MAX_BACKUPS) backups reached. Deleting ${TARGET} ..." + rm -rf "${TARGET}" + echo "==> Backup ${TARGET} deleted" +done \ No newline at end of file From 6b6656c540a779178df315346d984d2830bdce88 Mon Sep 17 00:00:00 2001 From: "g.nardiello" <giuseppe@nards.it> Date: Fri, 6 Jan 2023 09:29:31 +0100 Subject: [PATCH 16/55] Delete strategy moved to new file, as could custom --- Dockerfile | 4 ++-- backup.sh | 9 ++------- delete.sh | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100755 delete.sh diff --git a/Dockerfile b/Dockerfile index c06ccf7..be861f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,10 +32,10 @@ ENV CRON_TIME="0 3 * * sun" \ TIMEOUT="10s" \ MYSQLDUMP_OPTS="--quick" -COPY ["run.sh", "backup.sh", "restore.sh", "/"] +COPY ["run.sh", "backup.sh", "restore.sh", "/delete.sh", "/"] RUN mkdir /backup && \ chmod 777 /backup && \ - chmod 755 /run.sh /backup.sh /restore.sh && \ + chmod 755 /run.sh /backup.sh /restore.sh /delete.sh && \ touch /mysql_backup.log && \ chmod 666 /mysql_backup.log diff --git a/backup.sh b/backup.sh index 33ff1b1..678ec3d 100755 --- a/backup.sh +++ b/backup.sh @@ -46,13 +46,8 @@ do cd /backup || exit && ln -s "$BASENAME" "$(basename "$LATEST")" if [ -n "$MAX_BACKUPS" ] then - while [ "$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | wc -l)" -gt "$MAX_BACKUPS" ] - do - TARGET=$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | sort | head -n 1) - echo "==> Max number of ($MAX_BACKUPS) backups reached. Deleting ${TARGET} ..." - rm -rf "${TARGET}" - echo "==> Backup ${TARGET} deleted" - done + # Execute the delete script, delete older backup or other custom delete script + /delete.sh $db $EXT fi else rm -rf "$FILENAME" diff --git a/delete.sh b/delete.sh new file mode 100755 index 0000000..929ed7b --- /dev/null +++ b/delete.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +db=$1 +EXT=$2 + +# This file could be customized to create custom delete strategy + +while [ "$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | wc -l)" -gt "$MAX_BACKUPS" ] +do + TARGET=$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | sort | head -n 1) + echo "==> Max number of ($MAX_BACKUPS) backups reached. Deleting ${TARGET} ..." + rm -rf "${TARGET}" + echo "==> Backup ${TARGET} deleted" +done \ No newline at end of file From a2675a3c0615d1dceb177b61b1415c2a09d804f1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 10 Jan 2023 04:06:46 +0000 Subject: [PATCH 17/55] Bump alpine from 3.17.0 to 3.17.1 Bumps alpine from 3.17.0 to 3.17.1. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index be861f9..051b26d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.17.0 +FROM alpine:3.17.1 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 81f5e3dc69f8cc7e5dd390b98a7cedeabb8efb5b Mon Sep 17 00:00:00 2001 From: Giuseppe Nardiello <giuseppe@nards.it> Date: Tue, 10 Jan 2023 23:55:38 +0100 Subject: [PATCH 18/55] Corrected *Healthy* typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d3a2dd..b4d98fb 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ docker container run -d \ Healthcheck is provided as a basic init control. -Container is **Healthly** after the database init phase, that is after `INIT_BACKUP` or `INIT_RESTORE_LATEST` happends without check if there is an error, **Starting** otherwise. Not other checks are actually provided. +Container is **Healthy** after the database init phase, that is after `INIT_BACKUP` or `INIT_RESTORE_LATEST` happends without check if there is an error, **Starting** otherwise. Not other checks are actually provided. ## Variables From 9bd732897e84fa87428717208b1371f367211384 Mon Sep 17 00:00:00 2001 From: Giuseppe Nardiello <giuseppe@nards.it> Date: Tue, 17 Jan 2023 22:23:34 +0100 Subject: [PATCH 19/55] Better wait for crond --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index ea11ae7..b2e745b 100755 --- a/run.sh +++ b/run.sh @@ -34,6 +34,6 @@ crond -f -l 8 -L /mysql_backup.log & echo "Listening on crond, and wait..." -while : ; do sleep 1 ; done +tail -f /dev/null & wait $! echo "Script is shutted down." \ No newline at end of file From 8eb4379305e9ec0bb13ce80492f7be468b434c91 Mon Sep 17 00:00:00 2001 From: Giuseppe Nardiello <giuseppe@nards.it> Date: Tue, 17 Jan 2023 22:57:09 +0100 Subject: [PATCH 20/55] Changed find regex to explain date-format --- run.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/run.sh b/run.sh index a5151f4..50d9786 100755 --- a/run.sh +++ b/run.sh @@ -11,8 +11,9 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then echo "waiting database container..." sleep 1 done - # The [^l] is needed to exclude the latest backup file, and sort only data-tagged backups - find /backup -maxdepth 1 -name '[^l]*.sql.gz' | sort | tail -1 | xargs /restore.sh + # Needed to exclude the 'latest.<database>.sql.gz' file, consider only filenames starting with number + # Only data-tagged backups, eg. '202212250457.database.sql.gz', must be trapped by the regex + find /backup -maxdepth 1 -name '[0-9]*.*.sql.gz' | sort | tail -1 | xargs /restore.sh fi echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf From b0ae6e075deea0d97dac15ed7a301ae87b626c91 Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Thu, 19 Jan 2023 19:57:03 +0100 Subject: [PATCH 21/55] update to ubuntu 22.04 --- .github/workflows/image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 8d51bd3..6705901 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -10,14 +10,14 @@ on: jobs: test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout the code uses: actions/checkout@v3 - name: Test Bash scripts run: sudo apt-get -qq update && sudo apt-get install -y devscripts shellcheck && make test build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: test steps: - name: Checkout the code From 47977b7846b1c40c061a7bc218549557749aeb77 Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Thu, 19 Jan 2023 19:57:20 +0100 Subject: [PATCH 22/55] ignore data dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6320cd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data \ No newline at end of file From 1f5f594e14501ab85c14b231afdba8d3a0cd85ca Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Thu, 19 Jan 2023 20:01:21 +0100 Subject: [PATCH 23/55] add parenthesis to function syntax --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 5ebe1b3..320047c 100755 --- a/run.sh +++ b/run.sh @@ -16,7 +16,7 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then find /backup -maxdepth 1 -name '[0-9]*.*.sql.gz' | sort | tail -1 | xargs /restore.sh fi -function final_backup { +function final_backup () { echo "=> Captured trap for final backup" DATE=$(date +%Y%m%d%H%M) echo "=> Requested last backup at $(date "+%Y-%m-%d %H:%M:%S")" From d6217926f275b8b19a4b2f0f32b0319122e5b8d5 Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Thu, 19 Jan 2023 20:14:48 +0100 Subject: [PATCH 24/55] fix minor issues --- Makefile | 2 +- backup.sh | 2 +- run.sh | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index dc20422..ca5d51c 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ test: # Checking for syntax errors set -e; for SCRIPT in *.sh; \ do \ - sh -n $$SCRIPT; \ + bash -n $$SCRIPT; \ done # Checking for bashisms (currently not failing, but only listing) diff --git a/backup.sh b/backup.sh index 678ec3d..747cd82 100755 --- a/backup.sh +++ b/backup.sh @@ -47,7 +47,7 @@ do if [ -n "$MAX_BACKUPS" ] then # Execute the delete script, delete older backup or other custom delete script - /delete.sh $db $EXT + /delete.sh "$db" $EXT fi else rm -rf "$FILENAME" diff --git a/run.sh b/run.sh index 320047c..5990e0a 100755 --- a/run.sh +++ b/run.sh @@ -16,9 +16,8 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then find /backup -maxdepth 1 -name '[0-9]*.*.sql.gz' | sort | tail -1 | xargs /restore.sh fi -function final_backup () { +function final_backup { echo "=> Captured trap for final backup" - DATE=$(date +%Y%m%d%H%M) echo "=> Requested last backup at $(date "+%Y-%m-%d %H:%M:%S")" exec /backup.sh exit 0 From 96ca5bb74ae3785e39ee9ca529d05436c30ae582 Mon Sep 17 00:00:00 2001 From: Giuseppe Nardiello <giuseppe@nards.it> Date: Fri, 20 Jan 2023 12:04:19 +0100 Subject: [PATCH 25/55] Corrected HEALTHY.status typo --- Dockerfile | 2 +- run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index fdfa250..ad9ed2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,6 +42,6 @@ RUN mkdir /backup && \ VOLUME ["/backup"] HEALTHCHECK --interval=2s --retries=1800 \ - CMD stat /HEALTLY.status || exit 1 + CMD stat /HEALTHY.status || exit 1 ENTRYPOINT dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh \ No newline at end of file diff --git a/run.sh b/run.sh index 862a566..79e05ab 100755 --- a/run.sh +++ b/run.sh @@ -14,7 +14,7 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then find /backup -maxdepth 1 -name '*.sql.gz' | tail -1 | xargs /restore.sh fi -touch /HEALTLY.status +touch /.status echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf crontab /tmp/crontab.conf From 25729c7bc374664d75dbbb7b2c1aa4cc5166e18f Mon Sep 17 00:00:00 2001 From: Giuseppe Nardiello <giuseppe@nards.it> Date: Fri, 20 Jan 2023 12:04:42 +0100 Subject: [PATCH 26/55] Corrected HEALTHY.status typo --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 79e05ab..e2cb596 100755 --- a/run.sh +++ b/run.sh @@ -14,7 +14,7 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then find /backup -maxdepth 1 -name '*.sql.gz' | tail -1 | xargs /restore.sh fi -touch /.status +touch /HEALTHY.status echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf crontab /tmp/crontab.conf From 9edf0dedaf66fc8cc65da26082eec7c12e467c61 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Feb 2023 05:06:41 +0000 Subject: [PATCH 27/55] Bump alpine from 3.17.1 to 3.17.2 Bumps alpine from 3.17.1 to 3.17.2. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2a95ed6..10165ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.17.1 +FROM alpine:3.17.2 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 982600303d571ff1d4434809b25bf55edbf26e4e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Mar 2023 05:01:41 +0000 Subject: [PATCH 28/55] Bump alpine from 3.17.2 to 3.17.3 Bumps alpine from 3.17.2 to 3.17.3. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 10165ba..caad82c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.17.2 +FROM alpine:3.17.3 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From e1a26c194cf1ba6906ad1c305448e1340b2a240a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 May 2023 05:01:16 +0000 Subject: [PATCH 29/55] Bump alpine from 3.17.3 to 3.18.0 Bumps alpine from 3.17.3 to 3.18.0. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index caad82c..40d95cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.17.3 +FROM alpine:3.18.0 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From d772d22dd440fa6656779e1106118e05ad6db72e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Jun 2023 05:00:59 +0000 Subject: [PATCH 30/55] Bump alpine from 3.18.0 to 3.18.2 Bumps alpine from 3.18.0 to 3.18.2. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 40d95cb..188cfe9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.18.0 +FROM alpine:3.18.2 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From b7c09ddc1c9807a0a58542cdf4f9ce5b5e275888 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Aug 2023 04:55:47 +0000 Subject: [PATCH 31/55] Bump alpine from 3.18.2 to 3.18.3 Bumps alpine from 3.18.2 to 3.18.3. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 188cfe9..fdc2638 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go get github.com/robfig/glock RUN glock sync -n < GLOCKFILE RUN go install -FROM alpine:3.18.2 +FROM alpine:3.18.3 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From bcf82ae4e6c1f42aa9416f5e2c64d316d176bbd4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 04:59:56 +0000 Subject: [PATCH 32/55] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> --- .github/workflows/image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 6705901..88f1311 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout the code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Test Bash scripts run: sudo apt-get -qq update && sudo apt-get install -y devscripts shellcheck && make test build: @@ -21,7 +21,7 @@ jobs: needs: test steps: - name: Checkout the code - uses: actions/checkout@v3 + uses: actions/checkout@v4 # https://github.com/docker/setup-qemu-action - name: Set up QEMU uses: docker/setup-qemu-action@v2 From 895f17a082527c96b7b9a1a5e4a84fda7747cf95 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 05:03:02 +0000 Subject: [PATCH 33/55] Bump docker/setup-buildx-action from 2 to 3 Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2 to 3. - [Release notes](https://github.com/docker/setup-buildx-action/releases) - [Commits](https://github.com/docker/setup-buildx-action/compare/v2...v3) --- updated-dependencies: - dependency-name: docker/setup-buildx-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> --- .github/workflows/image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 88f1311..80d5cc9 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -27,7 +27,7 @@ jobs: uses: docker/setup-qemu-action@v2 # https://github.com/docker/setup-buildx-action - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Get latest release version number id: docker-tag uses: yuya-takeyama/docker-tag-from-github-ref-action@v1 From 554424bbc5e3dfc8ca619ed8d77c42f595aa307d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Sep 2023 17:07:34 +0000 Subject: [PATCH 34/55] Bump docker/setup-qemu-action from 2 to 3 Bumps [docker/setup-qemu-action](https://github.com/docker/setup-qemu-action) from 2 to 3. - [Release notes](https://github.com/docker/setup-qemu-action/releases) - [Commits](https://github.com/docker/setup-qemu-action/compare/v2...v3) --- updated-dependencies: - dependency-name: docker/setup-qemu-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> --- .github/workflows/image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 80d5cc9..b472c36 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -24,7 +24,7 @@ jobs: uses: actions/checkout@v4 # https://github.com/docker/setup-qemu-action - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 # https://github.com/docker/setup-buildx-action - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 From 4be928f6d021ca845d199ce921ce2a93d6cdc3bd Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Fri, 15 Sep 2023 19:56:06 +0200 Subject: [PATCH 35/55] Upgrade dockerize to 0.7.0 (#110) * update dockerize docker instructions * login to docker hub using action --- .github/workflows/image.yml | 5 ++++- Dockerfile | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index b472c36..e639e5f 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -32,7 +32,10 @@ jobs: id: docker-tag uses: yuya-takeyama/docker-tag-from-github-ref-action@v1 - name: Login to Docker Hub - run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - name: Build multiarch image run: | docker buildx build --push \ diff --git a/Dockerfile b/Dockerfile index fdc2638..95ad9bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,16 @@ -FROM golang:1.15.8-alpine3.12 AS binary +FROM golang:1.20.4-alpine3.18 AS binary RUN apk -U add openssl git -ARG DOCKERIZE_VERSION=v0.6.1 +ARG DOCKERIZE_VERSION=v0.7.0 WORKDIR /go/src/github.com/jwilder RUN git clone https://github.com/jwilder/dockerize.git && \ cd dockerize && \ git checkout ${DOCKERIZE_VERSION} WORKDIR /go/src/github.com/jwilder/dockerize -RUN go get github.com/robfig/glock -RUN glock sync -n < GLOCKFILE -RUN go install +ENV GO111MODULE=on +RUN go mod tidy +RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . FROM alpine:3.18.3 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" From e52061d4fab332d3b07234a1a3914f82ba5a385c Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Sun, 17 Sep 2023 11:01:33 +0200 Subject: [PATCH 36/55] Test docker image before pushing to docker hub (#111) * update dockerize docker instructions * use go with alpine * login to docker hub using action too * test docker image before building * extract command from the entrypoint * change volume path * user docker compose run and cmd instead entrypoint --- .github/workflows/image.yml | 10 ++++++++++ Dockerfile | 2 +- restore.sh | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index e639e5f..1fe4d25 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -16,6 +16,16 @@ jobs: uses: actions/checkout@v4 - name: Test Bash scripts run: sudo apt-get -qq update && sudo apt-get install -y devscripts shellcheck && make test + - name: Test image + env: + VOLUME_PATH: /tmp/mariadb + DATABASE_NAME: foo + MARIADB_ROOT_PASSWORD: abcd + run: | + docker-compose up -d mariadb + docker-compose run backup /backup.sh + docker-compose run backup /restore.sh /backup/latest.foo.sql.gz + docker-compose stop build: runs-on: ubuntu-22.04 needs: test diff --git a/Dockerfile b/Dockerfile index 95ad9bc..851a5c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,4 +44,4 @@ VOLUME ["/backup"] HEALTHCHECK --interval=2s --retries=1800 \ CMD stat /HEALTHY.status || exit 1 -ENTRYPOINT dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh \ No newline at end of file +CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh diff --git a/restore.sh b/restore.sh index 0607d6f..6c03634 100755 --- a/restore.sh +++ b/restore.sh @@ -13,6 +13,7 @@ if [ "$#" -ne 1 ] then echo "You must pass the path of the backup file to restore" + exit 1 fi set -o pipefail From 549f30ef6fd56011e1b19af82e979365497b1b60 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Sep 2023 04:49:58 +0000 Subject: [PATCH 37/55] Bump alpine from 3.18.3 to 3.18.4 Bumps alpine from 3.18.3 to 3.18.4. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 851a5c2..55b0e95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.18.3 +FROM alpine:3.18.4 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From f8addec08ff1b25e5c8e800763803058b7732ad7 Mon Sep 17 00:00:00 2001 From: nikgli <niklagligorovski@outlook.com> Date: Thu, 2 Nov 2023 14:28:58 +0800 Subject: [PATCH 38/55] Fixed access denied (at least one of) the PROCESS privilege(s) is required error --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6627b0d..dad5be3 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,8 @@ services: - CRON_TIME=0 3 * * * # Make it small - GZIP_LEVEL=9 + # As of MySQL 8.0.21 this is needed + - MYSQLDUMP_OPTS=--no-tablespaces restart: unless-stopped volumes: From a84b82077fb52680f887dfc15701d3c0507f6d96 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Dec 2023 04:59:07 +0000 Subject: [PATCH 39/55] Bump alpine from 3.18.4 to 3.18.5 Bumps alpine from 3.18.4 to 3.18.5. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 55b0e95..5318e57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.18.4 +FROM alpine:3.18.5 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 9c84748595070927a1d9e76d7bfc85fb1acc8368 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Dec 2023 04:20:17 +0000 Subject: [PATCH 40/55] Bump alpine from 3.18.5 to 3.19.0 Bumps alpine from 3.18.5 to 3.19.0. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5318e57..26e3c72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.18.5 +FROM alpine:3.19.0 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From d20b5ea8a9b1ddfb80519b28de4ed6375367c458 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 04:23:47 +0000 Subject: [PATCH 41/55] Bump alpine from 3.19.0 to 3.19.1 Bumps alpine from 3.19.0 to 3.19.1. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 26e3c72..60c89dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.19.0 +FROM alpine:3.19.1 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From efe543062965af7f8d0cb0b1fd12f6b1e8d41799 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 May 2024 04:30:24 +0000 Subject: [PATCH 42/55] Bump alpine from 3.19.1 to 3.20.0 Bumps alpine from 3.19.1 to 3.20.0. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 60c89dd..ddbd6ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.19.1 +FROM alpine:3.20.0 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 7fbc2fb79e1b4a0f5a63289edf88200fc204d284 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 21 Jun 2024 04:44:44 +0000 Subject: [PATCH 43/55] Bump alpine from 3.20.0 to 3.20.1 Bumps alpine from 3.20.0 to 3.20.1. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ddbd6ab..c3fb7e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.20.0 +FROM alpine:3.20.1 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 9e325e3ef7d0e9f4baf06c6d366bb7b60e7a8c14 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 04:19:30 +0000 Subject: [PATCH 44/55] Bump alpine from 3.20.1 to 3.20.2 Bumps alpine from 3.20.1 to 3.20.2. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c3fb7e3..0c0de4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.20.1 +FROM alpine:3.20.2 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 23cf857487cd668c1e3d16a8cf10570825a9cc50 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 04:30:04 +0000 Subject: [PATCH 45/55] Bump alpine from 3.20.2 to 3.20.3 Bumps alpine from 3.20.2 to 3.20.3. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0c0de4c..51fbf16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.20.2 +FROM alpine:3.20.3 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 353430ff83f7177125f011fdc7068d2c6af6279f Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Tue, 10 Sep 2024 19:25:10 +0200 Subject: [PATCH 46/55] move to docker v2 --- .github/workflows/image.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 1fe4d25..d1b827f 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -22,10 +22,10 @@ jobs: DATABASE_NAME: foo MARIADB_ROOT_PASSWORD: abcd run: | - docker-compose up -d mariadb - docker-compose run backup /backup.sh - docker-compose run backup /restore.sh /backup/latest.foo.sql.gz - docker-compose stop + docker compose up -d mariadb + docker compose run backup /backup.sh + docker compose run backup /restore.sh /backup/latest.foo.sql.gz + docker compose stop build: runs-on: ubuntu-22.04 needs: test @@ -50,4 +50,4 @@ jobs: run: | docker buildx build --push \ --tag fradelg/mysql-cron-backup:${{ steps.docker-tag.outputs.tag }} \ - --platform linux/amd64,linux/arm/v7,linux/arm64 . \ No newline at end of file + --platform linux/amd64,linux/arm/v7,linux/arm64 . From 07213e81358665a17117297f95104898989d0958 Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Tue, 10 Sep 2024 19:37:59 +0200 Subject: [PATCH 47/55] use service name for dns --- docker-compose.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index d0b693f..e154335 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,6 @@ version: "2" services: mariadb: image: mariadb:10 - container_name: my_mariadb expose: - 3306 volumes: @@ -21,7 +20,7 @@ services: volumes: - ${VOLUME_PATH}/backup:/backup environment: - - MYSQL_HOST=my_mariadb + - MYSQL_HOST=mariadb - MYSQL_USER=root - MYSQL_PASS=${MARIADB_ROOT_PASSWORD} - MAX_BACKUPS=1 @@ -30,4 +29,4 @@ services: restart: unless-stopped volumes: - data: \ No newline at end of file + data: From a715b4946cd805a0f26aba557b721904696e8c66 Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Tue, 10 Sep 2024 19:47:30 +0200 Subject: [PATCH 48/55] add health check --- docker-compose.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index e154335..6dfbf75 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,6 +2,7 @@ version: "2" services: mariadb: image: mariadb:10 + container_name: my_mariadb expose: - 3306 volumes: @@ -10,17 +11,23 @@ services: environment: - MYSQL_DATABASE=${DATABASE_NAME} - MYSQL_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD} + - MYSQL_ALLOW_EMPTY_ROOT_PASSWORD=yes restart: unless-stopped + healthcheck: + test: ["CMD", "healthcheck.sh", "--su-mysql", "--connect"] + timeout: 5s + retries: 10 backup: build: . image: fradelg/mysql-cron-backup depends_on: - - mariadb + mariadb: + condition: service_healthy volumes: - ${VOLUME_PATH}/backup:/backup environment: - - MYSQL_HOST=mariadb + - MYSQL_HOST=my_mariadb - MYSQL_USER=root - MYSQL_PASS=${MARIADB_ROOT_PASSWORD} - MAX_BACKUPS=1 From dac06953c32e804bf39f6599dc6fc14f4c123464 Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Tue, 10 Sep 2024 19:52:19 +0200 Subject: [PATCH 49/55] do not mask docker username --- .github/workflows/image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index d1b827f..5827146 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -44,7 +44,7 @@ jobs: - name: Login to Docker Hub uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKER_USERNAME }} + username: fradelg password: ${{ secrets.DOCKER_PASSWORD }} - name: Build multiarch image run: | From aebb29ab640d935698301a0412dbc3969429de2b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 Dec 2024 04:39:42 +0000 Subject: [PATCH 50/55] Bump alpine from 3.20.3 to 3.21.0 Bumps alpine from 3.20.3 to 3.21.0. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 51fbf16..e363c48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.20.3 +FROM alpine:3.21.0 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ From 823343381d42e055998106cb492ae18908cc8dc0 Mon Sep 17 00:00:00 2001 From: Tobias Janke <git@tojanke.de> Date: Sun, 8 Dec 2024 11:12:39 +0100 Subject: [PATCH 51/55] [Feature] Remove duplicate database dumps to save storage space (#127) * Replace gzip with deterministic bzip2 compression * Exclude comments from SQL dump * Add option to remove duplicates using fdupes * Revert change to bzip2 as gzip can be deterministic using no-name parameter --- Dockerfile | 3 ++- README.md | 1 + backup.sh | 9 +++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 51fbf16..e6887c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,8 @@ RUN apk add --update \ mysql-client \ gzip \ openssl \ - mariadb-connector-c && \ + mariadb-connector-c \ + fdupes && \ rm -rf /var/cache/apk/* COPY --from=binary /go/bin/dockerize /usr/local/bin diff --git a/README.md b/README.md index dad5be3..16a2d65 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Container is **Healthy** after the database init phase, that is after `INIT_BACK - `GZIP_LEVEL`: Specify the level of gzip compression from 1 (quickest, least compressed) to 9 (slowest, most compressed), default is 6. - `USE_PLAIN_SQL`: If set, back up and restore plain SQL files without gzip. - `TZ`: Specify TIMEZONE in Container. E.g. "Europe/Berlin". Default is UTC. +- `REMOVE_DUPLICATES`: Use [fdupes](https://github.com/adrianlopezroche/fdupes) to remove duplicate database dumps 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: diff --git a/backup.sh b/backup.sh index 747cd82..d7db8a7 100755 --- a/backup.sh +++ b/backup.sh @@ -29,13 +29,13 @@ do echo "==> Dumping database: $db" FILENAME=/backup/$DATE.$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" $MYSQL_SSL_OPTS "$db" > "$FILENAME" + if mysqldump --single-transaction --skip-comments $MYSQLDUMP_OPTS -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $MYSQL_SSL_OPTS "$db" > "$FILENAME" then EXT= if [ -z "${USE_PLAIN_SQL}" ] then echo "==> Compressing $db with LEVEL $GZIP_LEVEL" - gzip "-$GZIP_LEVEL" -f "$FILENAME" + gzip "-$GZIP_LEVEL" -n -f "$FILENAME" EXT=.gz FILENAME=$FILENAME$EXT LATEST=$LATEST$EXT @@ -44,6 +44,11 @@ do echo "==> Creating symlink to latest backup: $BASENAME" rm "$LATEST" 2> /dev/null cd /backup || exit && ln -s "$BASENAME" "$(basename "$LATEST")" + if [ -n "$REMOVE_DUPLICATES" ] + then + echo "=> Removing duplicate database dumps" + fdupes -idN /backup/ + fi if [ -n "$MAX_BACKUPS" ] then # Execute the delete script, delete older backup or other custom delete script From dc253cd1ea27e6582500877137bc9e26143ee6b0 Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Sun, 8 Dec 2024 12:52:35 +0100 Subject: [PATCH 52/55] stick to client 10.11 version --- Dockerfile | 18 +++++++++--------- docker-compose.yaml | 11 ++++++----- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 969c917..73a2588 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,17 +12,17 @@ ENV GO111MODULE=on RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o /go/bin/dockerize . -FROM alpine:3.21.0 +FROM alpine:3.20.3 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>" RUN apk add --update \ - tzdata \ - bash \ - mysql-client \ - gzip \ - openssl \ - mariadb-connector-c \ - fdupes && \ + tzdata \ + bash \ + gzip \ + openssl \ + mysql-client=~10.11 \ + mariadb-connector-c \ + fdupes && \ rm -rf /var/cache/apk/* COPY --from=binary /go/bin/dockerize /usr/local/bin @@ -43,6 +43,6 @@ RUN mkdir /backup && \ VOLUME ["/backup"] HEALTHCHECK --interval=2s --retries=1800 \ - CMD stat /HEALTHY.status || exit 1 + CMD stat /HEALTHY.status || exit 1 CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh diff --git a/docker-compose.yaml b/docker-compose.yaml index 6dfbf75..5ac0e9d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,8 +1,9 @@ -version: "2" services: mariadb: - image: mariadb:10 + image: mariadb:10.11 container_name: my_mariadb + security_opt: + - seccomp:unconfined expose: - 3306 volumes: @@ -14,7 +15,7 @@ services: - MYSQL_ALLOW_EMPTY_ROOT_PASSWORD=yes restart: unless-stopped healthcheck: - test: ["CMD", "healthcheck.sh", "--su-mysql", "--connect"] + test: [ "CMD", "healthcheck.sh", "--su-mysql", "--connect" ] timeout: 5s retries: 10 @@ -34,6 +35,6 @@ services: - INIT_BACKUP=1 - CRON_TIME=0 0 * * * restart: unless-stopped - -volumes: + +volumes: data: From cff595e6340c44ac53132dd4fed93872f85f0ca4 Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com> Date: Sun, 8 Dec 2024 13:56:43 +0100 Subject: [PATCH 53/55] disable skip comments only when needed --- backup.sh | 8 +++++++- docker-compose.yaml | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/backup.sh b/backup.sh index d7db8a7..ead820e 100755 --- a/backup.sh +++ b/backup.sh @@ -29,7 +29,13 @@ do echo "==> Dumping database: $db" FILENAME=/backup/$DATE.$db.sql LATEST=/backup/latest.$db.sql - if mysqldump --single-transaction --skip-comments $MYSQLDUMP_OPTS -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $MYSQL_SSL_OPTS "$db" > "$FILENAME" + BASIC_OPTS="--single-transaction" + if [ -n "$REMOVE_DUPLICATES" ] + then + echo "WARNING: disabling comments in backup to remove deuplicate backups. Automatic database name detection won't work so set MYSQL_DATABASE on restore" + BASIC_OPTS="$BASIC_OPTS" --skip-comments + fi + if mysqldump $BASIC_OPTS $MYSQLDUMP_OPTS -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $MYSQL_SSL_OPTS "$db" > "$FILENAME" then EXT= if [ -z "${USE_PLAIN_SQL}" ] diff --git a/docker-compose.yaml b/docker-compose.yaml index 5ac0e9d..64dcef0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -30,6 +30,7 @@ services: environment: - MYSQL_HOST=my_mariadb - MYSQL_USER=root + - MYSQL_DATABASE=${DATABASE_NAME} - MYSQL_PASS=${MARIADB_ROOT_PASSWORD} - MAX_BACKUPS=1 - INIT_BACKUP=1 From 8a15e59c1fef2a2f6f29f9839822b9e903691e0f Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <fradelg@Fcos-Air.home> Date: Mon, 9 Dec 2024 12:23:08 +0100 Subject: [PATCH 54/55] skip only timestamps when needed --- backup.sh | 5 ++--- docker-compose.yaml | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/backup.sh b/backup.sh index ead820e..499575d 100755 --- a/backup.sh +++ b/backup.sh @@ -32,8 +32,7 @@ do BASIC_OPTS="--single-transaction" if [ -n "$REMOVE_DUPLICATES" ] then - echo "WARNING: disabling comments in backup to remove deuplicate backups. Automatic database name detection won't work so set MYSQL_DATABASE on restore" - BASIC_OPTS="$BASIC_OPTS" --skip-comments + BASIC_OPTS="$BASIC_OPTS --skip-dump-date" fi if mysqldump $BASIC_OPTS $MYSQLDUMP_OPTS -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $MYSQL_SSL_OPTS "$db" > "$FILENAME" then @@ -52,7 +51,7 @@ do cd /backup || exit && ln -s "$BASENAME" "$(basename "$LATEST")" if [ -n "$REMOVE_DUPLICATES" ] then - echo "=> Removing duplicate database dumps" + echo "==> Removing duplicate database dumps" fdupes -idN /backup/ fi if [ -n "$MAX_BACKUPS" ] diff --git a/docker-compose.yaml b/docker-compose.yaml index 64dcef0..5ac0e9d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -30,7 +30,6 @@ services: environment: - MYSQL_HOST=my_mariadb - MYSQL_USER=root - - MYSQL_DATABASE=${DATABASE_NAME} - MYSQL_PASS=${MARIADB_ROOT_PASSWORD} - MAX_BACKUPS=1 - INIT_BACKUP=1 From 1d3c439b654fa1d5400ccaf318d8b0ff8a051a1d Mon Sep 17 00:00:00 2001 From: "Fco. Javier Delgado del Hoyo" <fradelg@Fcos-Air.home> Date: Mon, 9 Dec 2024 12:32:31 +0100 Subject: [PATCH 55/55] split test and build jobs --- .github/workflows/{image.yml => build.yml} | 22 +----------------- .github/workflows/test.yml | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 21 deletions(-) rename .github/workflows/{image.yml => build.yml} (59%) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/image.yml b/.github/workflows/build.yml similarity index 59% rename from .github/workflows/image.yml rename to .github/workflows/build.yml index 5827146..fab409a 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/build.yml @@ -1,34 +1,14 @@ + name: build docker image on: - workflow_dispatch: push: - branches: - - "**" tags: - "**" jobs: - test: - runs-on: ubuntu-22.04 - steps: - - name: Checkout the code - uses: actions/checkout@v4 - - name: Test Bash scripts - run: sudo apt-get -qq update && sudo apt-get install -y devscripts shellcheck && make test - - name: Test image - env: - VOLUME_PATH: /tmp/mariadb - DATABASE_NAME: foo - MARIADB_ROOT_PASSWORD: abcd - run: | - docker compose up -d mariadb - docker compose run backup /backup.sh - docker compose run backup /restore.sh /backup/latest.foo.sql.gz - docker compose stop build: runs-on: ubuntu-22.04 - needs: test steps: - name: Checkout the code uses: actions/checkout@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4460983 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: build docker image + +on: + workflow_dispatch: + push: + branches: + - "**" + +jobs: + test: + runs-on: ubuntu-22.04 + steps: + - name: Checkout the code + uses: actions/checkout@v4 + - name: Test Bash scripts + run: sudo apt-get -qq update && sudo apt-get install -y devscripts shellcheck && make test + - name: Test image + env: + VOLUME_PATH: /tmp/mariadb + DATABASE_NAME: foo + MARIADB_ROOT_PASSWORD: abcd + run: | + docker compose up -d mariadb + docker compose run backup /backup.sh + docker compose run backup /restore.sh /backup/latest.foo.sql.gz + docker compose stop