2016-12-10 13:48:33 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# zammad backup script functions
|
|
|
|
#
|
|
|
|
|
|
|
|
function get_backup_date () {
|
|
|
|
TIMESTAMP="$(date +'%Y%m%d%H%M%S')"
|
|
|
|
|
|
|
|
if [ "${DEBUG}" == "yes" ]; then
|
|
|
|
echo "timestamp is ${TIMESTAMP}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_old_backups () {
|
2016-12-11 08:49:57 +00:00
|
|
|
find ${BACKUP_DIR}/*_zammad_*.gz -type f -mtime +${HOLD_DAYS} -exec rm -r \;
|
2016-12-10 13:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_db_credentials () {
|
|
|
|
DB_ADAPTER="$(grep 'adapter:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*adapter:\(\| \)//g')"
|
|
|
|
DB_NAME="$(grep 'database:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*database:\(\| \) //g')"
|
|
|
|
DB_USER="$(grep 'username:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*username:\(\| \)//g')"
|
|
|
|
DB_PASS="$(grep 'password:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*password:\(\| \)//g')"
|
|
|
|
|
|
|
|
if [ "${DEBUG}" == "yes" ]; then
|
|
|
|
echo "adapter=${DB_ADAPTER} dbname=${DB_NAME} dbuser=${DB_USER} dbpass=${DB_PASS}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_dir_create () {
|
|
|
|
test -d ${BACKUP_DIR} || mkdir -p ${BACKUP_DIR}
|
|
|
|
|
|
|
|
if [ "${DEBUG}" == "yes" ]; then
|
|
|
|
echo "backup dir is ${BACKUP_DIR}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_files () {
|
|
|
|
tar -czf ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz ${ZAMMAD_DIR}
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_db () {
|
|
|
|
if [ "${DB_ADAPTER}" == "mysql2" ]; then
|
|
|
|
mysqldump --opt --single-transaction ${DB_NAME} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.mysql.gz
|
|
|
|
elif [ "${DB_ADAPTER}" == "postgresql" ]; then
|
|
|
|
su -c "pg_dump ${DB_NAME} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.psql.gz" postgres
|
2016-12-11 08:49:57 +00:00
|
|
|
else
|
2016-12-10 13:48:33 +00:00
|
|
|
echo "ADAPTER not found. if its sqlite backup is already saved in filebackup"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|