From 6ff4cf50cd2e0a43683821526f669db820ba88f2 Mon Sep 17 00:00:00 2001 From: Selamanse Date: Tue, 18 Jul 2017 13:38:42 +0200 Subject: [PATCH] Updates scripts --- scripts/backup | 53 ++++++++++++++++++++++++++++++++++++++++++ scripts/install | 1 + scripts/restore | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 scripts/backup create mode 100644 scripts/restore diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..4ccb894 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,53 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit on command errors and treat access to unset variables as an error +set -eu + +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Get the _common.sh file if it's not in the current directory + sudo cp ../settings/scripts/_common.sh ./_common.sh + sudo chmod a+rx _common.sh +fi +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# 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) +db_pwd=$(ynh_app_setting_get $app mysqlpwd) + +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= + +ynh_backup "$final_path" "${backup_dir}$final_path" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# BACKUP THE MONGODB DATABASE +#================================================= + +sudo mongodump -o "$final_path/dump" diff --git a/scripts/install b/scripts/install index 0729b02..a79748f 100644 --- a/scripts/install +++ b/scripts/install @@ -59,6 +59,7 @@ pkgdir=$(pwd) # Copy files to the right place final_path=/var/www/rocketchat +ynh_app_setting_set $app final_path $final_path sudo mkdir -p $final_path # download and extract rocketchat diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..d9ef6eb --- /dev/null +++ b/scripts/restore @@ -0,0 +1,62 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit on command errors and treat access to unset variables as an error +set -eu + +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Get the _common.sh file if it's not in the current directory + sudo cp ../settings/scripts/_common.sh ./_common.sh + sudo chmod a+rx _common.sh +fi +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# 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) +db_name=$(ynh_app_setting_get $app db_name) + +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= + +sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ + || 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" + +#================================================= +# RESTORE THE MONGODB +#================================================= + +sudo mongorestore --dbpath /var/lib/mongo "$final_path/dump"