backups: Don't leave services stopped if backup fails

- We stop services before backup and restart them when backup is completed.
However, if backup fails, we are not restarting the services. With this change,
ensure that stopped services are restarted even if backup process fails.

- Similarly for restore operation.

Tests:

- Backup and restore of an app work.

- Functional tests for matrix-synapse work.

- Run the following two tests without the patch to ensure that the reported bug
is reproducible.

- Make a backup operation fail by raising an exception in the privileged code
that takes backup. Enable matrix-synapse app. Run backup including the
matrix-synapse app. Backup fails and shows an error. The service is
stopped before backup and restarted after backup failure.

- Make a restore operation fail by raising an exception in the privileged code
that does restore. Enable matrix-synapse app. Run backup including the
matrix-synapse app and try to restore it. Restore fails and shows an error. The
service is stopped before restore and restarted after restore failure.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2023-10-30 16:54:52 -07:00 committed by James Valleroy
parent 58b2c3a796
commit 300f90f2a2
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -126,16 +126,17 @@ def backup_apps(backup_handler, path, app_ids=None, encryption_passphrase=None,
backup_root = '/'
snapshotted = False
packet = Packet('backup', 'apps', backup_root, components, path,
archive_comment)
_run_operation(backup_handler, packet,
encryption_passphrase=encryption_passphrase)
if snapshotted:
_delete_snapshot(snapshot)
else:
_restore_services(original_state)
_lockdown_apps(components, lockdown=False)
try:
packet = Packet('backup', 'apps', backup_root, components, path,
archive_comment)
_run_operation(backup_handler, packet,
encryption_passphrase=encryption_passphrase)
finally:
if snapshotted:
_delete_snapshot(snapshot)
else:
_restore_services(original_state)
_lockdown_apps(components, lockdown=False)
def restore_apps(restore_handler, app_ids=None, create_subvolume=True,
@ -157,15 +158,17 @@ def restore_apps(restore_handler, app_ids=None, create_subvolume=True,
restore_root = '/'
subvolume = False
packet = Packet('restore', 'apps', restore_root, components, backup_file)
_run_operation(restore_handler, packet,
encryption_passphrase=encryption_passphrase)
if subvolume:
_switch_to_subvolume(subvolume)
else:
_restore_services(original_state)
_lockdown_apps(components, lockdown=False)
try:
packet = Packet('restore', 'apps', restore_root, components,
backup_file)
_run_operation(restore_handler, packet,
encryption_passphrase=encryption_passphrase)
finally:
if subvolume:
_switch_to_subvolume(subvolume)
else:
_restore_services(original_state)
_lockdown_apps(components, lockdown=False)
def _install_apps_before_restore(components):