2017-07-22 13:14:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-11-20 22:59:01 +00:00
|
|
|
set -e
|
|
|
|
|
2020-02-24 16:50:19 +00:00
|
|
|
: "${ZAMMAD_DIR:=/opt/zammad}"
|
|
|
|
: "${BACKUP_DIR:=/var/tmp/zammad}"
|
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}"
|
2018-05-10 18:23:58 +00:00
|
|
|
: "${POSTGRESQL_HOST:=zammad-postgresql}"
|
|
|
|
: "${POSTGRESQL_PORT:=5432}"
|
|
|
|
: "${POSTGRESQL_DB:=zammad_production}"
|
2017-12-03 18:41:55 +00:00
|
|
|
|
2017-11-11 10:35:43 +00:00
|
|
|
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
|
2017-11-26 20:25:57 +00:00
|
|
|
echo "waiting for railsserver to be ready..."
|
|
|
|
sleep 60
|
2017-11-11 10:35:43 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-10-28 11:50:18 +00:00
|
|
|
function zammad_backup {
|
|
|
|
TIMESTAMP="$(date +'%Y%m%d%H%M%S')"
|
2017-07-22 13:14:20 +00:00
|
|
|
|
2017-10-28 11:50:18 +00:00
|
|
|
echo "${TIMESTAMP} - backuping zammad..."
|
2017-07-22 13:14:20 +00:00
|
|
|
|
2017-10-28 11:50:18 +00:00
|
|
|
# delete old backups
|
2019-02-04 20:47:54 +00:00
|
|
|
if [ -d "${BACKUP_DIR}" ] && [ -n "$(ls "${BACKUP_DIR}")" ]; then
|
2021-04-24 17:50:55 +00:00
|
|
|
find "${BACKUP_DIR}"/*_zammad_*.gz -type f -mtime +"${HOLD_DAYS}" -delete
|
2017-11-21 17:50:45 +00:00
|
|
|
fi
|
2017-07-22 13:14:20 +00:00
|
|
|
|
2017-12-03 18:41:55 +00:00
|
|
|
if [ "${NO_FILE_BACKUP}" != "yes" ]; then
|
|
|
|
# tar files
|
2019-02-04 20:47:54 +00:00
|
|
|
tar -czf "${BACKUP_DIR}"/"${TIMESTAMP}"_zammad_files.tar.gz "${ZAMMAD_DIR}"
|
2017-12-03 18:41:55 +00:00
|
|
|
fi
|
2017-07-22 13:14:20 +00:00
|
|
|
|
2017-10-28 11:50:18 +00:00
|
|
|
#db backup
|
2020-02-26 23:33:46 +00:00
|
|
|
pg_dump --dbname=postgresql://"${POSTGRESQL_USER}:${POSTGRESQL_PASSWORD}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DB}" | gzip > "${BACKUP_DIR}"/"${TIMESTAMP}"_zammad_db.psql.gz
|
2022-11-04 18:30:32 +00:00
|
|
|
|
|
|
|
echo "backup finished :)"
|
2017-10-24 21:17:40 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 11:50:18 +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
|
2017-07-22 13:14:20 +00:00
|
|
|
|
|
|
|
# wait until next backup
|
2019-02-04 20:47:54 +00:00
|
|
|
sleep "${BACKUP_SLEEP}"
|
2017-07-22 13:14:20 +00:00
|
|
|
done
|
|
|
|
fi
|
2017-10-24 20:50:44 +00:00
|
|
|
|
|
|
|
if [ "$1" = 'zammad-backup-once' ]; then
|
2017-10-28 11:50:18 +00:00
|
|
|
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
|
2017-12-03 18:41:55 +00:00
|
|
|
|
|
|
|
if [ "$1" = 'zammad-backup-db' ]; then
|
|
|
|
NO_FILE_BACKUP="yes"
|
|
|
|
|
|
|
|
zammad_backup
|
|
|
|
fi
|