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 <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2019-01-25 17:01:12 -08:00
parent 7d6284a829
commit f32239d32b
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -82,6 +82,7 @@ def _validate_service(service):
class BackupError: class BackupError:
"""Represent an backup/restore operation error.""" """Represent an backup/restore operation error."""
def __init__(self, error_type, app, hook=None): def __init__(self, error_type, app, hook=None):
"""Initialize the error object.""" """Initialize the error object."""
self.error_type = error_type self.error_type = error_type
@ -90,9 +91,9 @@ class BackupError:
def __eq__(self, other_error): def __eq__(self, other_error):
"""Compare to error objects.""" """Compare to error objects."""
return (self.error_type == other_error.error_type and return (self.error_type == other_error.error_type
self.app == other_error.app and and self.app == other_error.app
self.hook == other_error.hook) and self.hook == other_error.hook)
class Packet: class Packet:
@ -199,12 +200,12 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True,
else: else:
apps = _get_apps_in_order(app_names) apps = _get_apps_in_order(app_names)
_install_apps_before_restore(apps)
if _is_snapshot_available() and create_subvolume: if _is_snapshot_available() and create_subvolume:
subvolume = _create_subvolume(empty=False) subvolume = _create_subvolume(empty=False)
restore_root = subvolume['mount_path'] restore_root = subvolume['mount_path']
subvolume = True
else: else:
_install_apps_before_restore(apps)
_lockdown_apps(apps, lockdown=True) _lockdown_apps(apps, lockdown=True)
original_state = _shutdown_services(apps) original_state = _shutdown_services(apps)
restore_root = '/' restore_root = '/'
@ -222,12 +223,18 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True,
def _install_apps_before_restore(apps): def _install_apps_before_restore(apps):
"""Automatically install any applications from the backup archive """Install/upgrade apps needed before restoring a backup.
if they are not installed yet."""
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 = [] modules_to_setup = []
for backup_app in apps: 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) modules_to_setup.append(backup_app.name)
setup.run_setup_on_modules(modules_to_setup) setup.run_setup_on_modules(modules_to_setup)