From f1245b91a004d69d29876834fbfd398d07a0097b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sun, 15 Apr 2018 12:49:57 +0200 Subject: [PATCH] Add backup and restore --- check_process | 7 +++- manifest.json | 2 +- scripts/backup | 54 ++++++++++++++++++++++++ scripts/restore | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/upgrade | 8 ++-- 5 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 scripts/backup create mode 100644 scripts/restore diff --git a/check_process b/check_process index 47d9c15..321c9bc 100644 --- a/check_process +++ b/check_process @@ -15,7 +15,8 @@ setup_private=1 setup_public=0 upgrade=1 - backup_restore=0 + # upgrade=1 from_commit=c1345759860b9886b51a406366d1fcc090f05012 + backup_restore=1 multi_instance=1 incorrect_path=1 port_already_use=0 @@ -36,3 +37,7 @@ ;;; Options Email=jean-baptiste@holcroft.fr Notification=all +;;; Upgrade options + ; commit=c1345759860b9886b51a406366d1fcc090f05012 + name=Upgrade from old package version +manifest_arg=domain=DOMAIN&path=PATH diff --git a/manifest.json b/manifest.json index b499dcf..f34d0e7 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "requirements": { "yunohost": ">= 2.7.10" }, - "version": "0.13.1-1", + "version": "0.13.1-2", "multi_instance": true, "services": [ "nginx" diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..3e85111 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,54 @@ +#!/bin/bash + +#================================================= +# 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 + +#================================================= +# 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) + +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup "$final_path" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup "/etc/systemd/system/$app.service" + diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..a15f904 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,107 @@ +#!/bin/bash + +#================================================= +# 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 + +#================================================= +# 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 + +domain=$(ynh_app_setting_get "$app" domain) +path_url=$(ynh_app_setting_get "$app" path) +final_path=$(ynh_app_setting_get "$app" final_path) + +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= + +ynh_webpath_available $domain $path_url \ + || ynh_die "Path not available: ${domain}${path_url}" +test ! -d $final_path \ + || ynh_die "There is already a directory: $final_path " + +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= + +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= + +ynh_restore_file "$final_path" + +#================================================= +# RECREATE THE DEDICATED USER +#================================================= + +# Create the dedicated user (if not existing) +ynh_system_user_create "$app" + +#================================================= +# RESTORE USER RIGHTS +#================================================= + +# Restore permissions on app files +chown -R $app: $final_path +chmod 600 "$final_path/config.ini" + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= + +# Define and install dependencies +ynh_install_app_dependencies dh-autoreconf \ + python-pip python-dev python-lxml python-imaging python-virtualenv + +#================================================= +# INSTALL NODEJS +#================================================= + +ynh_install_nodejs 8 + +#================================================= +# RESTORE SYSTEMD +#================================================= + +ynh_restore_file "/etc/systemd/system/$app.service" +systemctl enable $app.service + +#================================================= +# START HASTEBIN +#================================================= + +systemctl start $app + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= + +systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index 5f465b8..d033db5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -40,11 +40,11 @@ fi #================================================= # Backup the current version of the app -# ynh_backup_before_upgrade -# ynh_clean_setup () { +ynh_backup_before_upgrade +ynh_clean_setup () { # restore it if the upgrade fails -# ynh_restore_upgradebackup -# } + ynh_restore_upgradebackup +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors