diff --git a/selfprivacy_api/backup/__init__.py b/selfprivacy_api/backup/__init__.py index f4b3b80..a540c8b 100644 --- a/selfprivacy_api/backup/__init__.py +++ b/selfprivacy_api/backup/__init__.py @@ -248,7 +248,7 @@ class Backups: raise ValueError("cannot backup a non-backuppable service") folders = service.get_folders() service_name = service.get_id() - service.pre_backup() + service.pre_backup(job=job) snapshot = Backups.provider().backupper.start_backup( folders, service_name, @@ -258,7 +258,7 @@ class Backups: Backups._on_new_snapshot_created(service_name, snapshot) if reason == BackupReason.AUTO: Backups._prune_auto_snaps(service) - service.post_backup() + service.post_backup(job=job) except Exception as error: Jobs.update(job, status=JobStatus.ERROR, error=str(error)) raise error @@ -452,7 +452,7 @@ class Backups: with StoppedService(service): if not service.is_always_active(): Backups.assert_dead(service) - service.pre_restore() + service.pre_restore(job=job) if strategy == RestoreStrategy.INPLACE: Backups._inplace_restore(service, snapshot, job) else: # verify_before_download is our default @@ -465,7 +465,7 @@ class Backups: service, snapshot.id, verify=True ) - service.post_restore() + service.post_restore(job=job) Jobs.update( job, status=JobStatus.RUNNING, diff --git a/selfprivacy_api/services/service.py b/selfprivacy_api/services/service.py index b7097d2..376a2ac 100644 --- a/selfprivacy_api/services/service.py +++ b/selfprivacy_api/services/service.py @@ -478,16 +478,16 @@ class Service(ABC): group=group, ) - def pre_backup(self): + def pre_backup(self, job: Job): pass - def post_backup(self): + def post_backup(self, job: Job): pass - def pre_restore(self): + def pre_restore(self, job: Job): pass - def post_restore(self): + def post_restore(self, job: Job): pass diff --git a/selfprivacy_api/services/templated_service.py b/selfprivacy_api/services/templated_service.py index d9ef76a..6c77a9c 100644 --- a/selfprivacy_api/services/templated_service.py +++ b/selfprivacy_api/services/templated_service.py @@ -12,9 +12,8 @@ from os import mkdir, rmdir from pydantic import BaseModel, ConfigDict from pydantic.alias_generators import to_camel -from selfprivacy_api.backup.jobs import get_backup_job from selfprivacy_api.backup.postgres import PostgresDumper -from selfprivacy_api.jobs import JobStatus, Jobs +from selfprivacy_api.jobs import Job, JobStatus, Jobs from selfprivacy_api.models.services import ServiceDnsRecord, ServiceStatus from selfprivacy_api.services.flake_service_manager import FlakeServiceManager from selfprivacy_api.services.generic_size_counter import get_storage_usage @@ -475,9 +474,8 @@ class TemplatedService(Service): group=group, ) - def pre_backup(self): + def pre_backup(self, job: Job): if self.get_postgresql_databases(): - job = get_backup_job(self) # Create the folder for the database dumps db_dumps_folder = self._get_db_dumps_folder() if not exists(db_dumps_folder): @@ -494,23 +492,22 @@ class TemplatedService(Service): backup_file = join(db_dumps_folder, f"{db_name}.sql.gz") db_dumper.backup_database(backup_file) - def post_backup(self): + def post_backup(self, job: Job): if self.get_postgresql_databases(): # Remove the folder for the database dumps db_dumps_folder = self._get_db_dumps_folder() if exists(db_dumps_folder): rmdir(db_dumps_folder) - def pre_restore(self): + def pre_restore(self, job: Job): if self.get_postgresql_databases(): # Create the folder for the database dumps db_dumps_folder = self._get_db_dumps_folder() if not exists(db_dumps_folder): mkdir(db_dumps_folder) - def post_restore(self): + def post_restore(self, job: Job): if self.get_postgresql_databases(): - job = get_backup_job(self) # Recover the databases db_dumps_folder = self._get_db_dumps_folder() for db_name in self.get_postgresql_databases():