From b7b640623da2aa5fd6eeefb8f38dd74fab1f8af8 Mon Sep 17 00:00:00 2001 From: frju365 Date: Sun, 11 Feb 2018 19:22:11 +0100 Subject: [PATCH] Big Refactoring --- scripts/backup | 68 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/scripts/backup b/scripts/backup index 5ddf19d..f963e1f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,32 +1,68 @@ #!/bin/bash -set -eu -# Source app helpers +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Get the _common.sh file if it's not in the current directory + cp ../settings/scripts/_common.sh ./_common.sh + chmod a+rx _common.sh +fi +source _common.sh source /usr/share/yunohost/helpers -# Récupère les infos de l'application. +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get $app db_name) -# The parameter $1 is the backup directory location -# which will be compressed afterward +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= -# Backup sources & data -ynh_backup "$final_path" "sources" +ynh_backup "$final_path" -# Copy Nginx and YunoHost parameters to make the script "standalone" -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "nginx.conf" +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= -ynh_backup "/etc/yunohost/apps/$app/" "yunohost" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -# Copy dedicated php-fpm process to backup folder -ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "php-fpm.conf" +#================================================= +# BACKUP THE PHP-FPM CONFIGURATION +#================================================= -# Backup db -root_pwd=$(sudo cat /etc/yunohost/mysql) -sudo mysqldump -u root -p$root_pwd --no-create-db $db_user --result-file="db.sql" -ynh_backup "db.sql" "backupdb.sql" +ynh_backup "/etc/php5/fpm/pool.d/$app.conf" +ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" +#================================================= +# BACKUP THE MYSQL DATABASE +#================================================= + +ynh_mysql_dump_db "$db_name" > db.sql + + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup "/etc/logrotate.d/$app"