From bc3ea3ad292179026dfce7c6e0e5b748dcb741a1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Sat, 7 Apr 2018 15:51:07 +0200 Subject: [PATCH] add backup and restore --- check_process | 2 +- scripts/backup | 45 ++++++++++++++++++++++++ scripts/restore | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 scripts/backup create mode 100644 scripts/restore diff --git a/check_process b/check_process index f1c9e87..13a646a 100644 --- a/check_process +++ b/check_process @@ -16,7 +16,7 @@ upgrade=1 # latest published in community.json upgrade=1 from_commit=c3f4863564b17be1cb8193f6962668bcc0d92072 - backup_restore=0 + backup_restore=1 multi_instance=1 wrong_user=0 wrong_path=0 diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..bf8bc99 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,45 @@ +#!/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) + +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup "$final_path" + +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup "/etc/systemd/system/$app.service" diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..414c8c6 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,91 @@ +#!/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) + +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= + +test ! -d "$final_path" \ + || ynh_die "There is already a directory: $final_path " + +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= + +ynh_restore_file "$final_path" + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= + +# Define and install dependencies +ynh_install_app_dependencies mumble-server mailutils + +#================================================= +# RESTORE USER RIGHTS +#================================================= + +# Restore permissions on app files +chmod -R 770 "$final_path" +chown -R :mumble-server "$final_path" + +#================================================= +# Add user to ssl-cert so it can read certificates +#================================================= + +usermod --append --groups ssl-cert mumble-server + +#================================================= +# Disable default server installed by Debian's package +#================================================= + +systemctl stop mumble-server +systemctl disable mumble-server + +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +# Add Mumble as a YunoHost service +yunohost service add "$app" -l "/var/log/mumble-server/$app.log" + +#================================================= +# RESTORE SYSTEMD +#================================================= + +ynh_restore_file "/etc/systemd/system/$app.service" +systemctl enable "$app.service" + +systemctl restart "$app"