- some rework on packaer.io postinstall
- added backup restore script
This commit is contained in:
parent
2203830f22
commit
6e5a277efc
5 changed files with 329 additions and 202 deletions
|
@ -56,3 +56,91 @@ function check_database_config_exists () {
|
|||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function restore_warning () {
|
||||
echo -e "The restore will delete your current config and database!\nBe sure to have a backup available!\n"
|
||||
echo -e "Enter 'yes' if you want to proceed!"
|
||||
read -s CHOOSE_RESTORE
|
||||
|
||||
if [ "${CHOOSE_RESTORE}" != "yes" ]; then
|
||||
echo "Restore aborted!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function get_restore_dates () {
|
||||
RESTORE_FILE_DATES="$(find ${BACKUP_DIR} -type f -iname '*_zammad_files.tar.gz' | sed -e "s#${BACKUP_DIR}/##g" -e "s#_zammad_files.tar.gz##g")"
|
||||
|
||||
if [ "${ADAPTER}" == "postgresql" ]; then
|
||||
DB_FILE_EXT="psql"
|
||||
elif [ "${ADAPTER}" == "mysql2" ]; then
|
||||
DB_FILE_EXT="mysql"
|
||||
fi
|
||||
|
||||
RESTORE_DB_DATES="$(find ${BACKUP_DIR} -type f -iname "*_zammad_db.${DB_FILE_EXT}.gz" | sed -e "s#${BACKUP_DIR}/##g" -e "s#_zammad_db.${DB_FILE_EXT}.gz##g")"
|
||||
}
|
||||
|
||||
function choose_restore_date () {
|
||||
echo "Enter file date to restore: ${RESTORE_FILE_DATES}"
|
||||
read -s RESTORE_FILE_DATE
|
||||
if [ ! -f "${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz" ];then
|
||||
echo "File ${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz does not exist!\nRestore aborted!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Enter db date to restore: ${RESTORE_DB_DATES}"
|
||||
read -s RESTORE_DB_DATE
|
||||
if [ ! -f "${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz" ];then
|
||||
echo "File ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_files.tar.gz does not exist!\nRestore aborted!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function detect_initcmd () {
|
||||
if [ -n "$(which systemctl 2> /dev/null)" ]; then
|
||||
INIT_CMD="systemctl"
|
||||
elif [ -n "$(which initctl 2> /dev/null)" ]; then
|
||||
INIT_CMD="initctl"
|
||||
else
|
||||
function sysvinit () {
|
||||
service $2 $1
|
||||
}
|
||||
INIT_CMD="sysvinit"
|
||||
fi
|
||||
|
||||
if [ "${DOCKER}" == "yes" ]; then
|
||||
INIT_CMD="initctl"
|
||||
fi
|
||||
|
||||
if [ "${DEBUG}" == "yes" ]; then
|
||||
echo "INIT CMD = ${INIT_CMD}"
|
||||
fi
|
||||
}
|
||||
|
||||
function start_zammad () {
|
||||
echo "# Starting Zammad"
|
||||
${INIT_CMD} start zammad
|
||||
}
|
||||
|
||||
function stop_zammad () {
|
||||
echo "# Stopping Zammad"
|
||||
${INIT_CMD} stop zammad
|
||||
}
|
||||
|
||||
function delete_current_files () {
|
||||
test -d ${ZAMMAD_DIR} && rm -rf ${ZAMMAD_DIR}
|
||||
}
|
||||
|
||||
function restore_zammad () {
|
||||
tar -C / -xzf ${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz
|
||||
|
||||
if [ "${ADAPTER}" == "postgresql" ]; then
|
||||
gunzip ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz | pg_restore -c ${DB_NAME}
|
||||
elif [ "${ADAPTER}" == "mysql2" ]; then
|
||||
gunzip ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz | mysql -u${DB_USER} -p${DB_PASS} ${DB_NAME}
|
||||
fi
|
||||
}
|
||||
|
||||
function restore_message () {
|
||||
echo "Zammad restored!"
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:
|
|||
. functions
|
||||
|
||||
# exec backup
|
||||
delete_old_backups
|
||||
|
||||
check_database_config_exists
|
||||
|
||||
delete_old_backups
|
||||
|
||||
get_backup_date
|
||||
|
||||
backup_dir_create
|
||||
|
|
35
contrib/backup/zammad_restore.sh
Executable file
35
contrib/backup/zammad_restore.sh
Executable file
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# zammad restore script
|
||||
#
|
||||
|
||||
PATH=/sbin:/bin:/usr/sbin:/usr/bin:
|
||||
|
||||
# import config
|
||||
. config
|
||||
|
||||
# import functions
|
||||
. functions
|
||||
|
||||
# exec restore
|
||||
restore_warning
|
||||
|
||||
check_database_config_exists
|
||||
|
||||
get_db_credentials
|
||||
|
||||
get_restore_dates
|
||||
|
||||
choose_restore_date
|
||||
|
||||
detect_initcmd
|
||||
|
||||
stop_zammad
|
||||
|
||||
delete_current_files
|
||||
|
||||
restore_zammad
|
||||
|
||||
start_zammad
|
||||
|
||||
restore_message
|
|
@ -213,6 +213,26 @@ function create_webserver_config () {
|
|||
${INIT_CMD} restart ${WEBSERVER_CMD}
|
||||
}
|
||||
|
||||
function update_or_install () {
|
||||
if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then
|
||||
update_database
|
||||
else
|
||||
create_database_password
|
||||
|
||||
if [ "${ADAPTER}" == "postgresql" ]; then
|
||||
echo "# Installing zammad on postgresql"
|
||||
create_postgresql_db
|
||||
elif [ "${ADAPTER}" == "mysql2" ]; then
|
||||
echo "# Installing zammad on mysql"
|
||||
create_mysql_db
|
||||
fi
|
||||
|
||||
update_database_yml
|
||||
|
||||
initialise_database
|
||||
fi
|
||||
}
|
||||
|
||||
function final_message () {
|
||||
echo -e "####################################################################################"
|
||||
echo -e "\nAdd your FQDN to servername directive in ${WEBSERVER_CONF}"
|
||||
|
|
|
@ -11,6 +11,7 @@ PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
|||
# import functions
|
||||
. /opt/zammad/contrib/packager.io/functions
|
||||
|
||||
# exec postinstall
|
||||
debug
|
||||
|
||||
detect_os
|
||||
|
@ -27,24 +28,7 @@ create_initscripts
|
|||
|
||||
stop_zammad
|
||||
|
||||
# check if database.yml exists
|
||||
if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then
|
||||
update_database
|
||||
else
|
||||
create_database_password
|
||||
|
||||
if [ "${ADAPTER}" == "postgresql" ]; then
|
||||
echo "# Installing zammad on postgresql"
|
||||
create_postgresql_db
|
||||
elif [ "${ADAPTER}" == "mysql2" ]; then
|
||||
echo "# Installing zammad on mysql"
|
||||
create_mysql_db
|
||||
fi
|
||||
|
||||
update_database_yml
|
||||
|
||||
initialise_database
|
||||
fi
|
||||
update_or_install
|
||||
|
||||
start_zammad
|
||||
|
||||
|
|
Loading…
Reference in a new issue