feature(backups): stop services before restores

This commit is contained in:
Houkime 2023-07-12 16:53:49 +00:00 committed by Inex Code
parent 40ad1b5ce4
commit b001e198bf
2 changed files with 15 additions and 10 deletions

View file

@ -258,16 +258,17 @@ class Backups:
try: try:
Backups._assert_restorable(snapshot) Backups._assert_restorable(snapshot)
with StoppedService(service):
Backups.assert_dead(service)
if strategy == RestoreStrategy.INPLACE:
Backups._inplace_restore(service, snapshot, job)
else: # verify_before_download is our default
Jobs.update(job, status=JobStatus.RUNNING)
Backups._restore_service_from_snapshot(
service, snapshot.id, verify=True
)
if strategy == RestoreStrategy.INPLACE: service.post_restore()
Backups._inplace_restore(service, snapshot, job)
else: # verify_before_download is our default
Jobs.update(job, status=JobStatus.RUNNING)
Backups._restore_service_from_snapshot(
service, snapshot.id, verify=True
)
service.post_restore()
except Exception as e: except Exception as e:
Jobs.update(job, status=JobStatus.ERROR) Jobs.update(job, status=JobStatus.ERROR)

View file

@ -379,7 +379,11 @@ def restore_strategy(request) -> RestoreStrategy:
return RestoreStrategy.INPLACE return RestoreStrategy.INPLACE
def test_restore_snapshot_task(backups, dummy_service, restore_strategy): def test_restore_snapshot_task(
backups, dummy_service, restore_strategy, simulated_service_stopping_delay
):
dummy_service.set_delay(simulated_service_stopping_delay)
Backups.back_up(dummy_service) Backups.back_up(dummy_service)
snaps = Backups.get_snapshots(dummy_service) snaps = Backups.get_snapshots(dummy_service)
assert len(snaps) == 1 assert len(snaps) == 1