From 281b5f317f37a41d3e1827d9e266379a3886d442 Mon Sep 17 00:00:00 2001 From: Jensa Date: Fri, 12 May 2023 20:51:57 +0200 Subject: [PATCH] timed backup script with backup time (#339) * Update backup.sh - new zammad-timed-backup which uses fixed backup time $BACKUP_TIME * Update docker-compose.yml - $BACKUP_TIME added - timed backup as command * merge request and linting fixes * arithmetic linting fix * not related to merge request but fixes linting in check_railsserver_available --- docker-compose.yml | 3 ++- scripts/backup.sh | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 614a98b..ed438f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,10 +10,11 @@ services: - zammad-postgresql entrypoint: /usr/local/bin/backup.sh environment: - - BACKUP_SLEEP=86400 + - BACKUP_TIME=03:00 - HOLD_DAYS=10 - POSTGRESQL_USER=${POSTGRES_USER} - POSTGRESQL_PASSWORD=${POSTGRES_PASS} + - TZ=Europe/Berlin image: postgres:${POSTGRES_VERSION} restart: ${RESTART} volumes: diff --git a/scripts/backup.sh b/scripts/backup.sh index 3874ed6..9821c18 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -11,7 +11,7 @@ set -e : "${POSTGRESQL_DB:=zammad_production}" function check_railsserver_available { - until (echo > /dev/tcp/${ZAMMAD_RAILSSERVER_HOST}/${ZAMMAD_RAILSSERVER_PORT}) &> /dev/null; do + until (echo > "/dev/tcp/$ZAMMAD_RAILSSERVER_HOST/$ZAMMAD_RAILSSERVER_PORT") &> /dev/null; do echo "waiting for railsserver to be ready..." sleep 60 done @@ -43,10 +43,15 @@ if [ "$1" = 'zammad-backup' ]; then check_railsserver_available while true; do + NOW_TIMESTAMP=$(date +%s) + TOMORROW_DATE=$(date -d@"$((NOW_TIMESTAMP + 24*60*60))" +%Y-%m-%d) + zammad_backup - # wait until next backup - sleep "${BACKUP_SLEEP}" + NEXT_TIMESTAMP=$(date -d "$TOMORROW_DATE $BACKUP_TIME" +%s) + NOW_TIMESTAMP=$(date +%s) + + sleep $((NEXT_TIMESTAMP - NOW_TIMESTAMP)) done fi