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