zammad-docker-compose/containers/zammad-postgresql/backup.sh

57 lines
1.2 KiB
Bash
Raw Normal View History

#!/bin/bash
2017-11-20 22:59:01 +00:00
set -e
2018-05-07 16:23:05 +00:00
: "${ZAMMAD_RAILSSERVER_HOST:=zammad-railsserver}"
2018-05-03 16:33:42 +00:00
: "${ZAMMAD_RAILSSERVER_PORT:=3000}"
function check_railsserver_available {
2018-05-03 16:33:20 +00:00
until (echo > /dev/tcp/${ZAMMAD_RAILSSERVER_HOST}/${ZAMMAD_RAILSSERVER_PORT}) &> /dev/null; do
echo "waiting for railsserver to be ready..."
sleep 60
done
}
function zammad_backup {
TIMESTAMP="$(date +'%Y%m%d%H%M%S')"
echo "${TIMESTAMP} - backuping zammad..."
# delete old backups
2017-11-21 17:50:45 +00:00
if [ -d "${BACKUP_DIR}" ] && [ -n "$(ls ${BACKUP_DIR})" ]; then
find ${BACKUP_DIR}/*_zammad_*.gz -type f -mtime +${HOLD_DAYS} -exec rm {} \;
fi
if [ "${NO_FILE_BACKUP}" != "yes" ]; then
# tar files
tar -czf ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz ${ZAMMAD_DIR}
fi
#db backup
pg_dump --dbname=postgresql://postgres@zammad-postgresql:5432/zammad_production | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.psql.gz
2017-10-24 21:17:40 +00:00
}
if [ "$1" = 'zammad-backup' ]; then
check_railsserver_available
2017-10-24 21:17:40 +00:00
while true; do
2017-11-11 10:34:18 +00:00
zammad_backup
# wait until next backup
sleep ${BACKUP_SLEEP}
done
fi
2017-10-24 20:50:44 +00:00
if [ "$1" = 'zammad-backup-once' ]; then
check_railsserver_available
2017-10-24 20:50:44 +00:00
2017-11-11 10:34:18 +00:00
zammad_backup
2017-10-24 20:50:44 +00:00
fi
if [ "$1" = 'zammad-backup-db' ]; then
NO_FILE_BACKUP="yes"
zammad_backup
fi