From 1341f750a61fc68c10f7e3cccb9ddc138bae4a78 Mon Sep 17 00:00:00 2001 From: Rafi594 Date: Sat, 23 Feb 2019 11:06:32 +0100 Subject: [PATCH] Add backup and restore --- conf/config.js | 2 +- scripts/backup | 73 ++++++++++++++++++++++++++++++ scripts/restore | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 scripts/backup create mode 100644 scripts/restore diff --git a/conf/config.js b/conf/config.js index 71d04d1..fa7a9f8 100644 --- a/conf/config.js +++ b/conf/config.js @@ -159,7 +159,7 @@ module.exports = { // @type array // @default ["sqlite", "text"] // - messageStorage: ["sqlite", "text"], + messageStorage: ["sqlite"], // // Log settings diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..d8e5bf5 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,73 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source ../settings/scripts/_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 +#================================================= +ynh_print_info "Loading installation settings..." + +app=$YNH_APP_INSTANCE_NAME + +final_path=$(ynh_app_setting_get $app final_path) +config_path=$(ynh_app_setting_get $app config_path) +domain=$(ynh_app_setting_get $app domain) + +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= +ynh_print_info "Backing up the main app directory..." + +ynh_backup "$final_path" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= +ynh_print_info "Backing up nginx web server configuration..." + +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= +ynh_print_info "Backing up logrotate configuration..." + +ynh_backup "/etc/logrotate.d/$app" + +#================================================= +# BACKUP SYSTEMD +#================================================= +ynh_print_info "Backing up systemd configuration..." + +ynh_backup "/etc/systemd/system/$app.service" + +#================================================= +# BACKUP CONFIG +#================================================= +ynh_print_info "Backing up config path..." + +ynh_backup "$config_path" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." \ No newline at end of file diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..04ff82b --- /dev/null +++ b/scripts/restore @@ -0,0 +1,118 @@ + +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source ../settings/scripts/_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 +#================================================= +ynh_print_info "Loading 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) +config_path=$(ynh_app_setting_get $app config_path) + +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= +ynh_print_info "Validating restoration parameters..." + +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_print_info "Restoring the app main directory..." + +ynh_restore_file "$final_path" + +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_print_info "Recreating the dedicated system user..." + +# Create the dedicated user (if not existing) +ynh_system_user_create $app + +#================================================= +# RESTORE USER RIGHTS +#================================================= + +# Restore permissions to app files +chown -R $app: $final_path +chown -R $app: $config_path + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_print_info "Reinstalling dependencies..." + +ynh_install_nodejs $nodejs_version + +#================================================= +# RESTORE THE CONFIG +#================================================= +ynh_print_info "Restoring the config path..." + +ynh_restore_file "$config_path" + +#================================================= +# RESTORE SYSTEMD +#================================================= +ynh_print_info "Restoring the systemd configuration..." + +ynh_restore_file "/etc/systemd/system/$app.service" +systemctl enable $app.service + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= + +ynh_restore_file "/etc/logrotate.d/$app" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= +ynh_print_info "Reloading nginx web server and The Lounge..." + +systemctl restart thelounge +sleep 4 +systemctl reload nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info "Restoration completed for $app" \ No newline at end of file