From d63eb376c4653134a9bffb6af1169f2e9445eabf Mon Sep 17 00:00:00 2001 From: David Lundgren Date: Tue, 15 Dec 2020 10:08:30 -0600 Subject: [PATCH] Allow for slight customization of the mssql db backup interval (#1008) * Allow for slight customization of the mssql db backup interval * Honor env TZ if set and clean up -u in sleep calculation --- util/MsSql/backup-db.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/MsSql/backup-db.sh b/util/MsSql/backup-db.sh index d7234d66b..e5b4f8f84 100644 --- a/util/MsSql/backup-db.sh +++ b/util/MsSql/backup-db.sh @@ -1,9 +1,14 @@ #!/bin/sh +BACKUP_INTERVAL=${BACKUP_INTERVAL:-next day} +BACKUP_INTERVAL_FORMAT=${BACKUP_INTERVAL_FORMAT:-%Y-%m-%d 00:00:00} while true do # Sleep until next day - [ "$1" = "loop" ] && sleep $((24 * 3600 - (`date +%_H` * 3600 + `date +%_M` * 60 + `date +%_S`))) + if [ "$1" = "loop" ]; then + interval_start=`date "+${BACKUP_INTERVAL_FORMAT} %z" -d "${BACKUP_INTERVAL}"` + sleep $((`date +%_s -d "${interval_start}"` - `date +%_s`)) + fi # Backup timestamp export now=$(date +%Y%m%d_%H%M%S)