feature(backups): report status text for restore jobs

This commit is contained in:
Houkime 2023-08-23 14:18:33 +00:00
parent 02b03cf401
commit c68239044f

View file

@ -308,7 +308,9 @@ class Backups:
) -> None: ) -> None:
failsafe_snapshot = Backups.back_up(service) failsafe_snapshot = Backups.back_up(service)
Jobs.update(job, status=JobStatus.RUNNING) Jobs.update(
job, status=JobStatus.RUNNING, status_text=f"Restoring from {snapshot.id}"
)
try: try:
Backups._restore_service_from_snapshot( Backups._restore_service_from_snapshot(
service, service,
@ -316,9 +318,19 @@ class Backups:
verify=False, verify=False,
) )
except Exception as error: except Exception as error:
Jobs.update(
job,
status=JobStatus.ERROR,
status_text=f" restore failed with {str(error)}, reverting to {failsafe_snapshot.id}",
)
Backups._restore_service_from_snapshot( Backups._restore_service_from_snapshot(
service, failsafe_snapshot.id, verify=False service, failsafe_snapshot.id, verify=False
) )
Jobs.update(
job,
status=JobStatus.ERROR,
status_text=f" restore failed with {str(error)}, reverted to {failsafe_snapshot.id}",
)
raise error raise error
@staticmethod @staticmethod
@ -335,17 +347,30 @@ class Backups:
try: try:
Backups._assert_restorable(snapshot) Backups._assert_restorable(snapshot)
Jobs.update(
job, status=JobStatus.CREATED, status_text="stopping the service"
)
with StoppedService(service): with StoppedService(service):
Backups.assert_dead(service) Backups.assert_dead(service)
if strategy == RestoreStrategy.INPLACE: if strategy == RestoreStrategy.INPLACE:
Backups._inplace_restore(service, snapshot, job) Backups._inplace_restore(service, snapshot, job)
else: # verify_before_download is our default else: # verify_before_download is our default
Jobs.update(job, status=JobStatus.RUNNING) Jobs.update(
job,
status=JobStatus.RUNNING,
status_text=f"Restoring from {snapshot.id}",
)
Backups._restore_service_from_snapshot( Backups._restore_service_from_snapshot(
service, snapshot.id, verify=True service, snapshot.id, verify=True
) )
service.post_restore() service.post_restore()
Jobs.update(
job,
status=JobStatus.RUNNING,
progress=90,
status_text="restarting the service",
)
except Exception as error: except Exception as error:
Jobs.update(job, status=JobStatus.ERROR, status_text=str(error)) Jobs.update(job, status=JobStatus.ERROR, status_text=str(error))