#!/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 () { find ${BACKUP_DIR}/*_zammad_*.gz -maxdepth 2 -mindepth 2 -type f -mtime +${HOLD_DAYS} -exec rm -r \; } 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 else echo "ADAPTER not found. if its sqlite backup is already saved in filebackup" fi }