trabajo-afectivo/contrib/backup/functions

59 lines
1.8 KiB
Text
Raw Normal View History

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 () {
test -d ${BACKUP_DIR} && 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
2017-02-12 10:09:47 +00:00
mysqldump --opt --single-transaction -u${DB_USER} -p${DB_PASS} ${DB_NAME} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.mysql.gz
2016-12-10 13:48:33 +00:00
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
}
function check_database_config_exists () {
if [ -f ${ZAMMAD_DIR}/${DATABASE_CONFIG} ]; then
get_db_credentials
else
echo "${ZAMMAD_DIR}/${DATABASE_CONFIG} is missing. is zammad configured yet?"
exit 1
fi
}