2017-07-22 13:14:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-10-24 21:17:40 +00:00
|
|
|
function backup {
|
|
|
|
TIMESTAMP="$(date +'%Y%m%d%H%M%S')"
|
2017-07-22 13:14:20 +00:00
|
|
|
|
|
|
|
echo "${TIMESTAMP} - backuping zammad..."
|
|
|
|
|
|
|
|
# delete old backups
|
|
|
|
test -d ${BACKUP_DIR} && find ${BACKUP_DIR}/*_zammad_*.gz -type f -mtime +${HOLD_DAYS} -exec rm {} \;
|
|
|
|
|
|
|
|
# tar files
|
2017-07-22 13:23:51 +00:00
|
|
|
tar -czf ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz ${ZAMMAD_DIR}
|
2017-07-22 13:14:20 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
# 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
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
backup
|
2017-07-22 13:14:20 +00:00
|
|
|
|
|
|
|
# wait until next backup
|
|
|
|
sleep ${BACKUP_SLEEP}
|
|
|
|
done
|
|
|
|
fi
|
2017-10-24 20:50:44 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-10-24 21:17:40 +00:00
|
|
|
backup
|
2017-10-24 20:50:44 +00:00
|
|
|
fi
|