Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #359 - Backup is constantly running. #367

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ services:
environment:
- BACKUP_TIME=03:00
- HOLD_DAYS=10
- TZ=Europe/Berlin
- POSTGRESQL_DB=${POSTGRES_DB}
- POSTGRESQL_HOST=${POSTGRES_HOST}
- POSTGRESQL_USER=${POSTGRES_USER}
- POSTGRESQL_PASSWORD=${POSTGRES_PASS}
- TZ=Europe/Berlin
- POSTGRESQL_PASS=${POSTGRES_PASS}
- POSTGRESQL_PORT=${POSTGRES_PORT}
image: postgres:${POSTGRES_VERSION}
restart: ${RESTART}
volumes:
Expand Down
12 changes: 8 additions & 4 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ set -e

: "${ZAMMAD_DIR:=/opt/zammad/var}"
: "${BACKUP_DIR:=/var/tmp/zammad}"
: "${BACKUP_TIME:=03:00}"
: "${ZAMMAD_RAILSSERVER_HOST:=zammad-railsserver}"
: "${ZAMMAD_RAILSSERVER_PORT:=3000}"
: "${POSTGRESQL_DB:=zammad_production}"
: "${POSTGRESQL_HOST:=zammad-postgresql}"
: "${POSTGRESQL_PORT:=5432}"
: "${POSTGRESQL_DB:=zammad_production}"
: "${POSTGRESQL_USER:=zammad}"
: "${POSTGRESQL_PASS:=zammad}"


function check_railsserver_available {
until (echo > "/dev/tcp/$ZAMMAD_RAILSSERVER_HOST/$ZAMMAD_RAILSSERVER_PORT") &> /dev/null; do
Expand All @@ -20,7 +24,7 @@ function check_railsserver_available {
function zammad_backup {
TIMESTAMP="$(date +'%Y%m%d%H%M%S')"

echo "${TIMESTAMP} - backuping zammad..."
echo "${TIMESTAMP} - backing up zammad..."

# delete old backups
if [ -d "${BACKUP_DIR}" ] && [ -n "$(ls "${BACKUP_DIR}")" ]; then
Expand All @@ -33,7 +37,7 @@ function zammad_backup {
fi

#db backup
pg_dump --dbname=postgresql://"${POSTGRESQL_USER}:${POSTGRESQL_PASSWORD}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DB}" | gzip > "${BACKUP_DIR}"/"${TIMESTAMP}"_zammad_db.psql.gz
pg_dump --dbname=postgresql://"${POSTGRESQL_USER}:${POSTGRESQL_PASS}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DB}" | gzip > "${BACKUP_DIR}"/"${TIMESTAMP}"_zammad_db.psql.gz

echo "backup finished :)"
}
Expand All @@ -45,7 +49,7 @@ if [ "$1" = 'zammad-backup' ]; then
while true; do
NOW_TIMESTAMP=$(date +%s)
TOMORROW_DATE=$(date -d@"$((NOW_TIMESTAMP + 24*60*60))" +%Y-%m-%d)

zammad_backup

NEXT_TIMESTAMP=$(date -d "$TOMORROW_DATE $BACKUP_TIME" +%s)
Expand Down