From f32239d32b39b319e9616193b952b3dc18cf4aa1 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 25 Jan 2019 17:01:12 -0800 Subject: [PATCH] backups: Upgrade apps before restoring them - All install/upgrade in all cases and not just for non-snapshot cases. Signed-off-by: Sunil Mohan Adapa --- plinth/modules/backups/api.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/plinth/modules/backups/api.py b/plinth/modules/backups/api.py index 59eb6e69d..92851a661 100644 --- a/plinth/modules/backups/api.py +++ b/plinth/modules/backups/api.py @@ -82,6 +82,7 @@ def _validate_service(service): class BackupError: """Represent an backup/restore operation error.""" + def __init__(self, error_type, app, hook=None): """Initialize the error object.""" self.error_type = error_type @@ -90,9 +91,9 @@ class BackupError: def __eq__(self, other_error): """Compare to error objects.""" - return (self.error_type == other_error.error_type and - self.app == other_error.app and - self.hook == other_error.hook) + return (self.error_type == other_error.error_type + and self.app == other_error.app + and self.hook == other_error.hook) class Packet: @@ -199,12 +200,12 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True, else: apps = _get_apps_in_order(app_names) + _install_apps_before_restore(apps) + if _is_snapshot_available() and create_subvolume: subvolume = _create_subvolume(empty=False) restore_root = subvolume['mount_path'] - subvolume = True else: - _install_apps_before_restore(apps) _lockdown_apps(apps, lockdown=True) original_state = _shutdown_services(apps) restore_root = '/' @@ -222,12 +223,18 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True, def _install_apps_before_restore(apps): - """Automatically install any applications from the backup archive - if they are not installed yet.""" + """Install/upgrade apps needed before restoring a backup. + + Upgrading apps to latest version before backups reduces the chance of newer + data getting backed up into older version of the app. + + """ modules_to_setup = [] for backup_app in apps: - if backup_app.app.setup_helper.get_state() == 'needs-setup': + if backup_app.app.setup_helper.get_state() in ('needs-setup', + 'needs-update'): modules_to_setup.append(backup_app.name) + setup.run_setup_on_modules(modules_to_setup)