From 74dd3641111ea51a6df46444193ab2d5420ef51c Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 5 Jan 2017 01:21:31 +0100 Subject: [PATCH] =?UTF-8?q?Upgrade=20s=C3=A9curis=C3=A9=20par=20un=20resto?= =?UTF-8?q?re?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/upgrade | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index a8e1afc..d06a36c 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,5 @@ #!/bin/bash -set -eu - # Load common variables and helpers source ./_common.sh @@ -10,6 +8,23 @@ app=$APPNAME dbname=$app dbuser=$app +# Backup the current version of the app, restore it if the upgrade fails +sudo yunohost backup delete $app-before-upgrade +sudo yunohost backup create --ignore-hooks --apps $app --name $app-before-upgrade +EXIT_PROPERLY () { + exit_code=$? + if [ "$exit_code" -eq 0 ]; then + exit 0 # Quitte sans erreur si le script se termine correctement. + fi + trap '' EXIT + set +eu + sudo yunohost app remove $app # Supprime l'application avant de la restaurer. + sudo yunohost backup restore --ignore-hooks $app-before-upgrade --apps $app --force # Restore the backup if upgrade failed + ynh_die "Upgrade failed. The app was restored to the way it was before the failed upgrade." +} +set -eu +trap EXIT_PROPERLY EXIT + # Source app helpers source /usr/share/yunohost/helpers