1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/framagames_ynh.git synced 2024-09-03 18:36:28 +02:00

Backup before upgrade and restore if it fails

This commit is contained in:
polytan02 2017-01-17 19:58:01 +00:00
parent 4983d1914e
commit c50ed41723

View file

@ -1,18 +1,30 @@
#!/bin/bash #!/bin/bash
#set -eu
# Charge les fonctions génériques habituellement utilisées dans le script
#source fonctions
# Active trap pour arrêter le script si une erreur est détectée.
#TRAP_ON
# Source app helpers
source /usr/share/yunohost/helpers
# We retrieve app parameters # We retrieve app parameters
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Backup the current version of the app, restore it if the upgrade fails
if sudo yunohost backup list | grep -q ${app}-before-upgrade > /dev/null 2>&1; then # Supprime l'ancienne archive seulement si elle existe
sudo yunohost backup delete ${app}-before-upgrade
fi
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
# We check variables are not empty # We check variables are not empty
CHECK_VAR () { # Vérifie que la variable n'est pas vide. CHECK_VAR () { # Vérifie que la variable n'est pas vide.
# $1 = Variable à vérifier # $1 = Variable à vérifier