From f64b1c10b504ff0d71a292a58316f922b74546f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Sat, 28 Oct 2017 13:50:18 +0200 Subject: [PATCH] added check_railsserver_available function to postgresql backup --- containers/zammad-postgresql/backup.sh | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/containers/zammad-postgresql/backup.sh b/containers/zammad-postgresql/backup.sh index 6c2ba27..601fdf6 100644 --- a/containers/zammad-postgresql/backup.sh +++ b/containers/zammad-postgresql/backup.sh @@ -1,26 +1,31 @@ #!/bin/bash -function backup { - TIMESTAMP="$(date +'%Y%m%d%H%M%S')" +function zammad_backup { + TIMESTAMP="$(date +'%Y%m%d%H%M%S')" - echo "${TIMESTAMP} - backuping zammad..." + echo "${TIMESTAMP} - backuping zammad..." - # delete old backups - test -d ${BACKUP_DIR} && find ${BACKUP_DIR}/*_zammad_*.gz -type f -mtime +${HOLD_DAYS} -exec rm {} \; + # delete old backups + test -d ${BACKUP_DIR} && find ${BACKUP_DIR}/*_zammad_*.gz -type f -mtime +${HOLD_DAYS} -exec rm {} \; - # tar files - tar -czf ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz ${ZAMMAD_DIR} + # tar files + tar -czf ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz ${ZAMMAD_DIR} - #db backup - pg_dump --dbname=postgresql://postgres@zammad-postgresql:5432/zammad_production | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.psql.gz + #db backup + pg_dump --dbname=postgresql://postgres@zammad-postgresql:5432/zammad_production | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.psql.gz } -if [ "$1" = 'zammad-backup' ]; then +function check_railsserver_available { # wait for zammad process coming up until (echo > /dev/tcp/zammad-railsserver/3000) &> /dev/null; do echo "backup waiting for zammads railsserver to be ready..." sleep 2 done +} + +if [ "$1" = 'zammad-backup' ]; then + + check_railsserver_available while true; do backup @@ -31,11 +36,7 @@ if [ "$1" = 'zammad-backup' ]; then fi if [ "$1" = 'zammad-backup-once' ]; then - # wait for zammad process coming up - until (echo > /dev/tcp/zammad-railsserver/3000) &> /dev/null; do - echo "backup waiting for zammads railsserver to be ready..." - sleep 2 - done + check_railsserver_available backup fi