From db19ca11308cf9d4866daef4fbaeed3e95abe029 Mon Sep 17 00:00:00 2001
From: Allan Jacquet-Cretides <Jumanjii@users.noreply.github.com>
Date: Sun, 7 Nov 2021 23:26:56 +0100
Subject: [PATCH 01/81] Add missing space in if with square bracket

A missing space at the end of an if condition was generating a warning message.
/restore.sh: line 14: [: missing `]'

Adding it delete this error message
---
 restore.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/restore.sh b/restore.sh
index 575624e..131d6a5 100755
--- a/restore.sh
+++ b/restore.sh
@@ -11,7 +11,7 @@ set -o pipefail
 
 SQL=$(gunzip -c "$1")
 DB_NAME=${MYSQL_DATABASE:-${MYSQL_DB}}
-if [ -z "${DB_NAME}"]
+if [ -z "${DB_NAME}" ]
 then
     DB_NAME=$(echo "$SQL" | grep -oE '(Database: (.+))' | cut -d ' ' -f 2)
 fi

From f2cefb1f9fa4dbae7ee6dbc53782b9adee430977 Mon Sep 17 00:00:00 2001
From: Jan Wagner <waja@cyconet.org>
Date: Mon, 8 Nov 2021 20:56:01 +0100
Subject: [PATCH 02/81] Adding dependabot config

---
 .github/dependabot.yml | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 .github/dependabot.yml

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..a8dc5a4
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,19 @@
+version: 2
+updates:
+  - package-ecosystem: github-actions
+    directory: "/"
+    schedule:
+      interval: daily
+      time: "04:00"
+    pull-request-branch-name:
+      separator: "-"
+    open-pull-requests-limit: 10
+  - package-ecosystem: docker
+    directory: "/"
+    schedule:
+      interval: daily
+      time: "04:00"
+    target-branch: "master"
+    pull-request-branch-name:
+      separator: "-"
+    open-pull-requests-limit: 10

From 6f5e7b0eedc5b0165981e4d4f7adfafb53bc3b46 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 8 Nov 2021 22:09:42 +0000
Subject: [PATCH 03/81] Bump alpine from 3.12 to 3.14.2

Bumps alpine from 3.12 to 3.14.2.

---
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 bedf025..d0e980f 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.12
+FROM alpine:3.14.2
 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
 
 RUN apk add --update \

From 566cbc7c67042c152e8fc03c3250c5f453c81a85 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 15 Nov 2021 04:27:07 +0000
Subject: [PATCH 04/81] Bump alpine from 3.14.2 to 3.14.3

Bumps alpine from 3.14.2 to 3.14.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 d0e980f..9bdcf0d 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.14.2
+FROM alpine:3.14.3
 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
 
 RUN apk add --update \

From f2ac763df9f791b50fd157e126f1e38202787668 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Thu, 25 Nov 2021 04:27:29 +0000
Subject: [PATCH 05/81] Bump alpine from 3.14.3 to 3.15.0

Bumps alpine from 3.14.3 to 3.15.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 9bdcf0d..d19d572 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.14.3
+FROM alpine:3.15.0
 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
 
 RUN apk add --update \

From 9c7c4d74e3bf54e57f3248edc47abd30c1d02ace Mon Sep 17 00:00:00 2001
From: skimpax <3287732+skimpax@users.noreply.github.com>
Date: Thu, 30 Dec 2021 18:37:52 +0100
Subject: [PATCH 06/81] Specify password in a file via MYSQL_PASS_FILE

---
 backup.sh  | 4 ++++
 restore.sh | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/backup.sh b/backup.sh
index 615d6a1..ebb4cb7 100755
--- a/backup.sh
+++ b/backup.sh
@@ -1,5 +1,9 @@
 #!/bin/bash
+
 [ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; }
+# If provided, take password from file
+[ -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; }
 [ -z "${GZIP_LEVEL}" ] && { GZIP_LEVEL=6; }
 
diff --git a/restore.sh b/restore.sh
index 131d6a5..07ecbae 100755
--- a/restore.sh
+++ b/restore.sh
@@ -1,5 +1,9 @@
 #!/bin/bash
+
 [ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; }
+# If provided, take password from file
+[ -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; }
 
 if [ "$#" -ne 1 ]

From 9f81b63bcd3df0e27aab5a93dc6651840acafb47 Mon Sep 17 00:00:00 2001
From: skimpax <3287732+skimpax@users.noreply.github.com>
Date: Thu, 30 Dec 2021 18:38:06 +0100
Subject: [PATCH 07/81] Ignore 'sys' table when backuping

---
 backup.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/backup.sh b/backup.sh
index ebb4cb7..6b75964 100755
--- a/backup.sh
+++ b/backup.sh
@@ -12,7 +12,11 @@ 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)}}
 for db in ${DATABASES}
 do
-  if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]]
+  if  [[ "$db" != "information_schema" ]] \
+      && [[ "$db" != "performance_schema" ]] \
+      && [[ "$db" != "mysql" ]] \
+      && [[ "$db" != "sys" ]] \
+      && [[ "$db" != _* ]]
   then
     echo "==> Dumping database: $db"
     FILENAME=/backup/$DATE.$db.sql

From a365376ebe7d6c83e21cc5852b65979ec239dcd0 Mon Sep 17 00:00:00 2001
From: skimpax <3287732+skimpax@users.noreply.github.com>
Date: Thu, 30 Dec 2021 18:38:31 +0100
Subject: [PATCH 08/81] Add double quotes

---
 backup.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backup.sh b/backup.sh
index 6b75964..71ba385 100755
--- a/backup.sh
+++ b/backup.sh
@@ -21,7 +21,7 @@ do
     echo "==> Dumping database: $db"
     FILENAME=/backup/$DATE.$db.sql
     LATEST=/backup/latest.$db.sql.gz
-    if mysqldump --single-transaction -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" $MYSQLDUMP_OPTS > "$FILENAME"
+    if mysqldump --single-transaction -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" "$MYSQLDUMP_OPTS" > "$FILENAME"
     then
       gzip "-$GZIP_LEVEL" -f "$FILENAME"
       echo "==> Creating symlink to latest backup: $(basename "$FILENAME".gz)"

From 203280de70cc3a539800f0775cd9a89c1bdbba5b Mon Sep 17 00:00:00 2001
From: skimpax <3287732+skimpax@users.noreply.github.com>
Date: Thu, 30 Dec 2021 18:39:02 +0100
Subject: [PATCH 09/81] Update readme for docker secrets example

---
 README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/README.md b/README.md
index a09bec0..e2cd2e8 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ docker container run -d \
 - `MYSQL_PORT`: The port number of your mysql database.
 - `MYSQL_USER`: The username of your mysql database.
 - `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`.
 - `MYSQLDUMP_OPTS`: Command line arguments to pass to mysqldump. Example: `--single-transaction`.
 - `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.
@@ -31,6 +32,8 @@ docker container run -d \
 
 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:
 
+### Docker-compose with MYSQL_PASS env var:
+
 ```yaml
 version: "2"
 services:
@@ -70,6 +73,61 @@ volumes:
   data:
 ```
 
+### Docker-compose using docker secrets:
+
+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.
+
+Alternatively, secret can be stored in docker secrets engine (iow. not in host filesystem).
+
+```yaml
+version: "3.7"
+
+secrets:
+  mysql_root_password:
+    # Place your secret file somewhere on your host filesystem, with your password inside
+    file: ./secrets/mysql_root_password
+
+services:
+  mariadb:
+    image: mariadb:10
+    container_name: my_mariadb
+    expose:
+      - 3306
+    volumes:
+      - data:/var/lib/mysql
+      - ${VOLUME_PATH}/backup:/backup
+    environment:
+      - MYSQL_DATABASE=${DATABASE_NAME}
+      - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password
+    secrets:
+      - mysql_root_password
+    restart: unless-stopped
+
+  backup:
+    build: .
+    image: fradelg/mysql-cron-backup
+    depends_on:
+      - mariadb
+    volumes:
+      - ${VOLUME_PATH}/backup:/backup
+    environment:
+      - MYSQL_HOST=my_mariadb
+      - MYSQL_USER=root
+      - MYSQL_PASS_FILE=/run/secrets/mysql_root_password
+      - MAX_BACKUPS=10
+      - INIT_BACKUP=1
+      - CRON_TIME=0 0 * * *
+    secrets:
+      - mysql_root_password
+    restart: unless-stopped
+
+volumes:
+  data:
+
+```
+
 ## Restore from a backup
 
 ### List all available backups :

From 74ad0295737c48c8f032971aa1d4ff51c5e7cebb Mon Sep 17 00:00:00 2001
From: skimpax <3287732+skimpax@users.noreply.github.com>
Date: Sat, 15 Jan 2022 13:54:58 +0100
Subject: [PATCH 10/81] Remove double quotes around MYSQLDUMP_OPTS

---
 backup.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backup.sh b/backup.sh
index 71ba385..6b75964 100755
--- a/backup.sh
+++ b/backup.sh
@@ -21,7 +21,7 @@ do
     echo "==> Dumping database: $db"
     FILENAME=/backup/$DATE.$db.sql
     LATEST=/backup/latest.$db.sql.gz
-    if mysqldump --single-transaction -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" "$MYSQLDUMP_OPTS" > "$FILENAME"
+    if mysqldump --single-transaction -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" $MYSQLDUMP_OPTS > "$FILENAME"
     then
       gzip "-$GZIP_LEVEL" -f "$FILENAME"
       echo "==> Creating symlink to latest backup: $(basename "$FILENAME".gz)"

From 8992f162d797bdbc94160df1b560a87c09a6477e Mon Sep 17 00:00:00 2001
From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com>
Date: Fri, 4 Feb 2022 20:44:11 +0100
Subject: [PATCH 11/81] support saving non-gzipped sql files

---
 README.md  |  1 +
 backup.sh  | 25 +++++++++++++++++--------
 restore.sh | 11 +++++++++--
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index e2cd2e8..8464811 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,7 @@ docker container run -d \
 - `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.
+- `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.
 
 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 6b75964..76a3d5a 100755
--- a/backup.sh
+++ b/backup.sh
@@ -20,19 +20,28 @@ do
   then
     echo "==> Dumping database: $db"
     FILENAME=/backup/$DATE.$db.sql
-    LATEST=/backup/latest.$db.sql.gz
-    if mysqldump --single-transaction -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" $MYSQLDUMP_OPTS > "$FILENAME"
+    LATEST=/backup/latest.$db.sql
+    if mysqldump --single-transaction -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" "$MYSQLDUMP_OPTS" > "$FILENAME"
     then
-      gzip "-$GZIP_LEVEL" -f "$FILENAME"
-      echo "==> Creating symlink to latest backup: $(basename "$FILENAME".gz)"
+      EXT=
+      if [ -z "${USE_PLAIN_SQL}" ]
+      then
+        echo "==> Compressing $db with LEVEL $GZIP_LEVEL"
+        gzip "-$GZIP_LEVEL" -f "$FILENAME"
+        EXT=.gz
+        FILENAME=$FILENAME$EXT
+        LATEST=$LATEST$EXT
+      fi
+      BASENAME=$(basename "$FILENAME")
+      echo "==> Creating symlink to latest backup: $BASENAME"
       rm "$LATEST" 2> /dev/null
-      cd /backup || exit && ln -s "$(basename "$FILENAME".gz)" "$(basename "$LATEST")"
+      cd /backup || exit && ln -s "$BASENAME" "$(basename "$LATEST")"
       if [ -n "$MAX_BACKUPS" ]
       then
-        while [ "$(find /backup -maxdepth 1 -name "*.$db.sql.gz" -type f | wc -l)" -gt "$MAX_BACKUPS" ]
+        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.gz" -type f | sort | head -n 1)
-          echo "==> Max number of backups ($MAX_BACKUPS) reached. Deleting ${TARGET} ..."
+          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
diff --git a/restore.sh b/restore.sh
index 07ecbae..536a890 100755
--- a/restore.sh
+++ b/restore.sh
@@ -13,13 +13,20 @@ fi
 
 set -o pipefail
 
-SQL=$(gunzip -c "$1")
+if [ -z "${USE_PLAIN_SQL}" ]
+then 
+    SQL=$(gunzip -c "$1")
+else
+    SQL=$(cat "$1")
+fi
+
 DB_NAME=${MYSQL_DATABASE:-${MYSQL_DB}}
 if [ -z "${DB_NAME}" ]
 then
+    echo "=> Searching database name in $1"
     DB_NAME=$(echo "$SQL" | grep -oE '(Database: (.+))' | cut -d ' ' -f 2)
 fi
-[ -z "${DB_NAME}" ] && { echo "=> database name cannot be found" && exit 1; }
+[ -z "${DB_NAME}" ] && { echo "=> Database name not found" && exit 1; }
 
 echo "=> Restore database $DB_NAME from $1"
 

From f7418224036f8c089547918059c148b25d337853 Mon Sep 17 00:00:00 2001
From: "Fco. Javier Delgado del Hoyo" <frandelhoyo@gmail.com>
Date: Sat, 5 Feb 2022 13:01:53 +0100
Subject: [PATCH 12/81] fix wrong placement of MYSQLDUMP_OPTS variable

---
 Dockerfile | 3 ++-
 README.md  | 2 +-
 backup.sh  | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index d19d572..a1ee8c1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -29,7 +29,8 @@ COPY --from=binary /go/bin/dockerize /usr/local/bin
 ENV CRON_TIME="0 3 * * sun" \
     MYSQL_HOST="mysql" \
     MYSQL_PORT="3306" \
-    TIMEOUT="10s"
+    TIMEOUT="10s" \
+    MYSQLDUMP_OPTS="--quick"
 
 COPY ["run.sh", "backup.sh", "restore.sh", "/"]
 RUN mkdir /backup && \
diff --git a/README.md b/README.md
index 8464811..4280622 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ docker container run -d \
 - `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`.
-- `MYSQLDUMP_OPTS`: Command line arguments to pass to mysqldump. Example: `--single-transaction`.
+- `MYSQLDUMP_OPTS`: Command line arguments to pass to mysqldump (see [mysqldump documentation](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.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.
 - `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.
diff --git a/backup.sh b/backup.sh
index 76a3d5a..7082e01 100755
--- a/backup.sh
+++ b/backup.sh
@@ -21,7 +21,7 @@ do
     echo "==> Dumping database: $db"
     FILENAME=/backup/$DATE.$db.sql
     LATEST=/backup/latest.$db.sql
-    if mysqldump --single-transaction -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" "$MYSQLDUMP_OPTS" > "$FILENAME"
+    if mysqldump --single-transaction "$MYSQLDUMP_OPTS" -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" > "$FILENAME"
     then
       EXT=
       if [ -z "${USE_PLAIN_SQL}" ]

From db6014ab1ac5ed05fc468c8bb526c2c9f4724a7d Mon Sep 17 00:00:00 2001
From: Motaz Abuthiab <moty66@gmail.com>
Date: Tue, 22 Feb 2022 08:49:54 +0100
Subject: [PATCH 13/81] fix issue with multiple dump extra options

mysqldump will fail if the env variable has multiple options,

issue: https://github.com/fradelg/docker-mysql-cron-backup/issues/72
---
 backup.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/backup.sh b/backup.sh
index 7082e01..b3bce4f 100755
--- a/backup.sh
+++ b/backup.sh
@@ -21,7 +21,7 @@ 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" "$db" > "$FILENAME"
+    if mysqldump --single-transaction $MYSQLDUMP_OPTS -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" > "$FILENAME"
     then
       EXT=
       if [ -z "${USE_PLAIN_SQL}" ]

From eb42488f004b37ea7374d8e3ff97748c14efcfff Mon Sep 17 00:00:00 2001
From: Motaz Abuthiab <moty66@gmail.com>
Date: Tue, 22 Feb 2022 08:50:03 +0100
Subject: [PATCH 14/81] fix issue with multiple dump extra options

mysqldump will fail if the env variable has multiple options,

issue: https://github.com/fradelg/docker-mysql-cron-backup/issues/72

From 331adf57b08fea1e7f244f8612c08da228563609 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 2 Mar 2022 04:35:02 +0000
Subject: [PATCH 15/81] Bump actions/checkout from 2 to 3

Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [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/v2...v3)

---
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 7a4203a..8aab2e9 100644
--- a/.github/workflows/image.yml
+++ b/.github/workflows/image.yml
@@ -13,7 +13,7 @@ jobs:
     runs-on: ubuntu-20.04
     steps:
       - name: Checkout the code
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
       - 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@v2
+        uses: actions/checkout@v3
       # https://github.com/docker/setup-qemu-action
       - name: Set up QEMU
         uses: docker/setup-qemu-action@v1

From ca54b7769ef511fbf2fa92db5d25d0f2220a8e9a Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 18 Mar 2022 04:22:42 +0000
Subject: [PATCH 16/81] Bump alpine from 3.15.0 to 3.15.1

Bumps alpine from 3.15.0 to 3.15.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 a1ee8c1..1bc8a52 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.15.0
+FROM alpine:3.15.1
 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
 
 RUN apk add --update \

From f30f90ad61c16c5bad457dd2f49a1b79c4c098e1 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Thu, 24 Mar 2022 04:25:15 +0000
Subject: [PATCH 17/81] Bump alpine from 3.15.1 to 3.15.2

Bumps alpine from 3.15.1 to 3.15.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 1bc8a52..e642713 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.15.1
+FROM alpine:3.15.2
 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
 
 RUN apk add --update \

From 546533416e038fa5bcd0c499a919abdcfb92f53e Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 29 Mar 2022 04:27:05 +0000
Subject: [PATCH 18/81] Bump alpine from 3.15.2 to 3.15.3

Bumps alpine from 3.15.2 to 3.15.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 e642713..84724c8 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.15.2
+FROM alpine:3.15.3
 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
 
 RUN apk add --update \

From f1ba971fa0c3c273f455cc7fc2f0c2d853c16e2e Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 5 Apr 2022 04:26:24 +0000
Subject: [PATCH 19/81] Bump alpine from 3.15.3 to 3.15.4

Bumps alpine from 3.15.3 to 3.15.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 84724c8..8cc0a2b 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.15.3
+FROM alpine:3.15.4
 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
 
 RUN apk add --update \

From 7e9b1fdbcf75c6e91f84467f805acaa2dbf46629 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 6 May 2022 04:25:29 +0000
Subject: [PATCH 20/81] Bump docker/setup-buildx-action from 1 to 2

Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 1 to 2.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](https://github.com/docker/setup-buildx-action/compare/v1...v2)

---
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 8aab2e9..9f290f7 100644
--- a/.github/workflows/image.yml
+++ b/.github/workflows/image.yml
@@ -27,7 +27,7 @@ jobs:
         uses: docker/setup-qemu-action@v1
       # https://github.com/docker/setup-buildx-action
       - name: Set up Docker Buildx
-        uses: docker/setup-buildx-action@v1
+        uses: docker/setup-buildx-action@v2
       - name: Get latest release version number
         id: docker-tag
         uses: yuya-takeyama/docker-tag-from-github-ref-action@v1

From 040b3e4e77f4cd7470f912a2b178f94ca35a92d7 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 7 May 2022 09:53:43 +0000
Subject: [PATCH 21/81] Bump docker/setup-qemu-action from 1 to 2

Bumps [docker/setup-qemu-action](https://github.com/docker/setup-qemu-action) from 1 to 2.
- [Release notes](https://github.com/docker/setup-qemu-action/releases)
- [Commits](https://github.com/docker/setup-qemu-action/compare/v1...v2)

---
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 9f290f7..6dba542 100644
--- a/.github/workflows/image.yml
+++ b/.github/workflows/image.yml
@@ -24,7 +24,7 @@ jobs:
         uses: actions/checkout@v3
       # https://github.com/docker/setup-qemu-action
       - name: Set up QEMU
-        uses: docker/setup-qemu-action@v1
+        uses: docker/setup-qemu-action@v2
       # https://github.com/docker/setup-buildx-action
       - name: Set up Docker Buildx
         uses: docker/setup-buildx-action@v2

From e8396b9fda394cc9179bfbcc974b2e3558341252 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 24 May 2022 04:27:53 +0000
Subject: [PATCH 22/81] Bump alpine from 3.15.4 to 3.16.0

Bumps alpine from 3.15.4 to 3.16.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 8cc0a2b..9b3497b 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.15.4
+FROM alpine:3.16.0
 LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
 
 RUN apk add --update \

From aca23ddb93471884efd558448d100a2873d14cd0 Mon Sep 17 00:00:00 2001
From: Alexey Kovtunovich <kovtalex@gmail.com>
Date: Tue, 14 Jun 2022 18:18:01 +0300
Subject: [PATCH 23/81] add SSL arguments

---
 README.md  | 1 +
 backup.sh  | 4 ++--
 restore.sh | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 4280622..3b21b68 100644
--- a/README.md
+++ b/README.md
@@ -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_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)).
+- `MYSQL_SSL_OPTS`: Command line arguments to use [SSL](https://dev.mysql.com/doc/refman/8.0/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.
 - `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.
diff --git a/backup.sh b/backup.sh
index b3bce4f..d251ed7 100755
--- a/backup.sh
+++ b/backup.sh
@@ -9,7 +9,7 @@
 
 DATE=$(date +%Y%m%d%H%M)
 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}
 do
   if  [[ "$db" != "information_schema" ]] \
@@ -21,7 +21,7 @@ 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" "$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
       EXT=
       if [ -z "${USE_PLAIN_SQL}" ]
diff --git a/restore.sh b/restore.sh
index 536a890..284f653 100755
--- a/restore.sh
+++ b/restore.sh
@@ -30,7 +30,7 @@ fi
 
 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" "$DB_NAME" $MYSQL_SSL_OPTS
 then
     echo "=> Restore succeeded"
 else

From 6f512df392f067a1e9a91834e61791ab81a5d5b1 Mon Sep 17 00:00:00 2001
From: Alexey Kovtunovich <kovtalex@gmail.com>
Date: Tue, 14 Jun 2022 18:32:06 +0300
Subject: [PATCH 24/81] fixed link to SSL configuration manual

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 3b21b68..5d6cfe6 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ docker container run -d \
 - `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`.
-- `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/5.6/en/using-encrypted-connections.html).
 - `MYSQL_SSL_OPTS`: Command line arguments to use [SSL](https://dev.mysql.com/doc/refman/8.0/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.
 - `MAX_BACKUPS`: The number of backups to keep. When reaching the limit, the old backup will be discarded. No limit by default.

From 35ff2141ea1285fd881a4e52d9ddfae396066639 Mon Sep 17 00:00:00 2001
From: Alexey Kovtunovich <kovtalex@gmail.com>
Date: Tue, 14 Jun 2022 18:33:57 +0300
Subject: [PATCH 25/81] fixed link to SSL configuration manual

---
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 5d6cfe6..bcd60ff 100644
--- a/README.md
+++ b/README.md
@@ -21,8 +21,8 @@ docker container run -d \
 - `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`.
-- `MYSQLDUMP_OPTS`: Command line arguments to pass to mysqldump (see [mysqldump documentation](https://dev.mysql.com/doc/refman/5.6/en/using-encrypted-connections.html).
-- `MYSQL_SSL_OPTS`: Command line arguments to use [SSL](https://dev.mysql.com/doc/refman/8.0/en/using-encrypted-connections.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.
 - `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.

From 2b43049ff95843e7d52ba64599997627da394c05 Mon Sep 17 00:00:00 2001
From: Alexey Kovtunovich <kovtalex@gmail.com>
Date: Sat, 18 Jun 2022 12:25:46 +0300
Subject: [PATCH 26/81] fix restore.sh - mysql cmd

---
 restore.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/restore.sh b/restore.sh
index 284f653..15d6b81 100755
--- a/restore.sh
+++ b/restore.sh
@@ -30,7 +30,7 @@ fi
 
 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" $MYSQL_SSL_OPTS
+if echo "$SQL" | mysql -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $MYSQL_SSL_OPTS "$DB_NAME"
 then
     echo "=> Restore succeeded"
 else

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 27/81] 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 28/81] 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 29/81] 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 30/81] 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 31/81] 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 32/81] 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 33/81] 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 34/81] 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 35/81] 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 36/81] 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 37/81] 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 38/81] 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 39/81] 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 40/81] 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 41/81] 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 42/81] 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 43/81] 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 44/81] 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 45/81] 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 46/81] 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 47/81] 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 48/81] 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 49/81] 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 50/81] 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 51/81] 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 52/81] 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 53/81] 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 54/81] 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 55/81] 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 56/81] 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 57/81] 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 58/81] 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 59/81] 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 60/81] 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 61/81] 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 62/81] 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 63/81] 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 64/81] 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 65/81] 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 66/81] 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 67/81] 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 68/81] 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 69/81] 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 70/81] 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 71/81] 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 72/81] 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 73/81] 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 74/81] 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 75/81] 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 76/81] 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 77/81] [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 78/81] 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 79/81] 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 80/81] 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 81/81] 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