From 6b577bdd23e7cba2b05049bc66c365ffe905e80f Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 27 May 2024 22:39:43 +0200 Subject: [PATCH] helpers 2.1: remove packaging v1 ynh_backup_before_upgrade and ynh_restore_upgradebackup, handled by core in packaging v2 --- helpers/helpers.v2.1.d/backup | 91 ----------------------------------- 1 file changed, 91 deletions(-) diff --git a/helpers/helpers.v2.1.d/backup b/helpers/helpers.v2.1.d/backup index 820a2562d..bcf322914 100644 --- a/helpers/helpers.v2.1.d/backup +++ b/helpers/helpers.v2.1.d/backup @@ -408,94 +408,3 @@ ynh_backup_archive_exists() { yunohost backup list --output-as json --quiet \ | jq -e --arg archive "$1" '.archives | index($archive)' >/dev/null } - -# Make a backup in case of failed upgrade -# -# [packagingv1] -# -# usage: ynh_backup_before_upgrade -# -# Usage in a package script: -# ``` -# ynh_backup_before_upgrade -# ynh_clean_setup () { -# ynh_restore_upgradebackup -# } -# ynh_abort_if_errors -# ``` -# -# Requires YunoHost version 2.7.2 or higher. -ynh_backup_before_upgrade() { - if [ ! -e "/etc/yunohost/apps/$app/scripts/backup" ]; then - ynh_print_warn --message="This app doesn't have any backup script." - return - fi - backup_number=1 - local old_backup_number=2 - local app_bck=${app//_/-} # Replace all '_' by '-' - NO_BACKUP_UPGRADE=${NO_BACKUP_UPGRADE:-0} - - if [ "$NO_BACKUP_UPGRADE" -eq 0 ]; then - # Check if a backup already exists with the prefix 1 - if ynh_backup_archive_exists "$app_bck-pre-upgrade1"; then - # Prefix becomes 2 to preserve the previous backup - backup_number=2 - old_backup_number=1 - fi - - # Create backup - BACKUP_CORE_ONLY=1 yunohost backup create --apps $app --name $app_bck-pre-upgrade$backup_number --debug - if [ "$?" -eq 0 ]; then - # If the backup succeeded, remove the previous backup - if ynh_backup_archive_exists "$app_bck-pre-upgrade$old_backup_number"; then - # Remove the previous backup only if it exists - yunohost backup delete $app_bck-pre-upgrade$old_backup_number >/dev/null - fi - else - ynh_die --message="Backup failed, the upgrade process was aborted." - fi - else - ynh_print_warn --message="\$NO_BACKUP_UPGRADE is set, backup will be avoided. Be careful, this upgrade is going to be operated without a security backup" - fi -} - -# Restore a previous backup if the upgrade process failed -# -# [packagingv1] -# -# usage: ynh_restore_upgradebackup -# -# Usage in a package script: -# ``` -# ynh_backup_before_upgrade -# ynh_clean_setup () { -# ynh_restore_upgradebackup -# } -# ynh_abort_if_errors -# ``` -# -# Requires YunoHost version 2.7.2 or higher. -ynh_restore_upgradebackup() { - ynh_print_err --message="Upgrade failed." - local app_bck=${app//_/-} # Replace all '_' by '-' - - NO_BACKUP_UPGRADE=${NO_BACKUP_UPGRADE:-0} - - if [ "$NO_BACKUP_UPGRADE" -eq 0 ]; then - # Check if an existing backup can be found before removing and restoring the application. - if ynh_backup_archive_exists "$app_bck-pre-upgrade$backup_number"; then - # Remove the application then restore it - yunohost app remove $app - # Restore the backup - yunohost backup restore $app_bck-pre-upgrade$backup_number --apps $app --force --debug - if [[ -d /etc/yunohost/apps/$app ]] - then - ynh_die --message="The app was restored to the way it was before the failed upgrade." - else - ynh_die --message="Uhoh ... Yunohost failed to restore the app to the way it was before the failed upgrade :|" - fi - fi - else - ynh_print_warn --message="\$NO_BACKUP_UPGRADE is set, that means there's no backup to restore. You have to fix this upgrade by yourself !" - fi -}