added backup script
This commit is contained in:
parent
e43ccb4475
commit
115ea3ad6f
3 changed files with 90 additions and 0 deletions
10
contrib/backup/config
Normal file
10
contrib/backup/config
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# zammad backup script config
|
||||
#
|
||||
|
||||
ZAMMAD_DIR="/opt/zammad"
|
||||
DATABASE_CONFIG="config/database.yml"
|
||||
BACKUP_DIR="/var/tmp/zammad_backup"
|
||||
HOLD_DAYS="10"
|
||||
DEBUG="yes"
|
50
contrib/backup/functions
Normal file
50
contrib/backup/functions
Normal file
|
@ -0,0 +1,50 @@
|
|||
#!/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
|
||||
}
|
||||
|
30
contrib/backup/zammad_backup.sh
Executable file
30
contrib/backup/zammad_backup.sh
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# zammad backup script
|
||||
#
|
||||
|
||||
PATH=/sbin:/bin:/usr/sbin:/usr/bin:
|
||||
|
||||
# import config
|
||||
. config
|
||||
|
||||
# import functions
|
||||
. functions
|
||||
|
||||
delete_old_backups
|
||||
|
||||
# check if database.yml 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
|
||||
|
||||
get_backup_date
|
||||
|
||||
backup_dir_create
|
||||
|
||||
backup_files
|
||||
|
||||
backup_db
|
Loading…
Reference in a new issue