aboutsummaryrefslogtreecommitdiff
path: root/scripts/backup
diff options
context:
space:
mode:
authornemsia <nemsia@nemsia.org>2018-05-03 15:42:48 +0200
committerGitHub <noreply@github.com>2018-05-03 15:42:48 +0200
commit56e9231be42fc514bf0e8c7e2bbfd16a9c8e575b (patch)
tree1819ff84a1da9f743c14ad54d4857ed7d5ef1bb1 /scripts/backup
parent52ea3880731fe09d724ac0b831605583682068cf (diff)
parentb67376ec30c52e5d0ff2014fb89149a5e8fd2215 (diff)
downloadmastodon_ynh-56e9231be42fc514bf0e8c7e2bbfd16a9c8e575b.tar.gz
mastodon_ynh-56e9231be42fc514bf0e8c7e2bbfd16a9c8e575b.tar.bz2
mastodon_ynh-56e9231be42fc514bf0e8c7e2bbfd16a9c8e575b.zip
Merge pull request #76 from Jibec/master
Refactoring
Diffstat (limited to 'scripts/backup')
-rw-r--r--scripts/backup89
1 files changed, 61 insertions, 28 deletions
diff --git a/scripts/backup b/scripts/backup
index ffcac0e..5e134ac 100644
--- a/scripts/backup
+++ b/scripts/backup
@@ -1,47 +1,80 @@
#!/bin/bash
-# Exit on command errors and treat unset variables as an error
-set -eu
+#=================================================
+# GENERIC START
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
if [ ! -e _common.sh ]; then
- # Get file fonction if not been to the current directory
- sudo cp ../settings/scripts/_common.sh ./_common.sh
- sudo chmod a+rx _common.sh
+ # Get the _common.sh file if it's not in the current directory
+ cp ../settings/scripts/_common.sh ./_common.sh
+ cp ../settings/scripts/_future.sh ./_future.sh
+ chmod a+rx _common.sh _future.sh
fi
-# Loads the generic functions usually used in the script
source _common.sh
-# Source app helpers
source /usr/share/yunohost/helpers
+source _future.sh
+
+#=================================================
+# MANAGE SCRIPT FAILURE
+#=================================================
+
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
+#=================================================
+# LOAD SETTINGS
+#=================================================
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
+final_path=$(ynh_app_setting_get "$app" final_path)
+db_name=$(ynh_sanitize_dbid "$app")
+
+#=================================================
+# 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"
-# Copy the app files
-final_path="/opt/${app}"
-ynh_backup "$final_path" "sources" 1
+#=================================================
+# BACKUP THE MYSQL DATABASE
+#=================================================
-# final_path on nginx
-sudo sed -i "s@$final_path@__FINALPATH__@g" /etc/nginx/conf.d/${domain}.d/${app}.conf
+ynh_psql_dump_db "$db_name" > db.sql
+
+#=================================================
+# SPECIFIC BACKUP
+#=================================================
+# BACKUP SYSTEMD
+#=================================================
+
+ynh_backup "/etc/systemd/system/$app-web.service"
+ynh_backup "/etc/systemd/system/$app-sidekiq.service"
+ynh_backup "/etc/systemd/system/$app-streaming.service"
+
+#=================================================
+# BACKUP THE CRON FILE
+#=================================================
# Copy the nginx conf files
-ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
-ynh_backup "/etc/cron.d/${app}" "cron.conf"
-ynh_backup "/etc/systemd/system/mastodon-web.service" "systemd_web.service"
-ynh_backup "/etc/systemd/system/mastodon-sidekiq.service" "systemd_sidekiq.service"
-ynh_backup "/etc/systemd/system/mastodon-streaming.service" "systemd_streaming.service"
-ynh_backup "/etc/apt/sources.list.d/backports.list" "apt_backports.list"
-ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list"
+ynh_backup "/etc/cron.d/$app"
-# final_path on nginx
-sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/${domain}.d/${app}.conf
+#=================================================
+# BACKUP THE sources.list FILES
+#=================================================
-# Backup db
-sudo su - postgres <<COMMANDS
-pg_dump --role=mastodon -U postgres --no-password mastodon_production > mastodon_db.sql
-COMMANDS
-ynh_backup "/var/lib/postgresql/${app}_db.sql" "${app}_db.sql"
-# Fix backup fail on yunohost 2.6
-#ynh_secure_remove /var/lib/postgresql/mastodon_db.sql
+ynh_backup "/etc/apt/sources.list.d/backports.list" "apt_backports.list"
+ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list"