From 400bb8c95e26cdd68340d89d60aacaad7b11a90b Mon Sep 17 00:00:00 2001 From: "g.nardiello" Date: Thu, 5 Jan 2023 11:47:54 +0100 Subject: [PATCH 1/2] 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 8eb4379305e9ec0bb13ce80492f7be468b434c91 Mon Sep 17 00:00:00 2001 From: Giuseppe Nardiello Date: Tue, 17 Jan 2023 22:57:09 +0100 Subject: [PATCH 2/2] 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..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