fix: userdata handling

This commit is contained in:
Inex Code 2024-12-15 14:23:14 +03:00
parent f2e1370447
commit e2e14103bf
No known key found for this signature in database
3 changed files with 14 additions and 11 deletions

View file

@ -258,6 +258,7 @@ class Backups:
Backups._on_new_snapshot_created(service_name, snapshot)
if reason == BackupReason.AUTO:
Backups._prune_auto_snaps(service)
service.post_backup()
except Exception as error:
Jobs.update(job, status=JobStatus.ERROR, error=str(error))
raise error

View file

@ -150,7 +150,8 @@ class ServiceManager(Service):
# Stash locations as they are set by user right now
locations = {}
for service in services:
locations[service.get_id()] = service.get_drive()
if service.is_movable():
locations[service.get_id()] = service.get_drive()
# Copy files
for p in [USERDATA_FILE, SECRETS_FILE, DKIM_DIR]:
@ -158,9 +159,10 @@ class ServiceManager(Service):
# Pop locations
for service in services:
device = BlockDevices().get_block_device(locations[service.get_id()])
if device is not None:
service.set_location(device)
if service.is_movable():
device = BlockDevices().get_block_device(locations[service.get_id()])
if device is not None:
service.set_location(device)
@classmethod
def stop(cls):
@ -205,13 +207,9 @@ class ServiceManager(Service):
@classmethod
def stash_a_path(cls, p: str):
if path.isdir(p):
logging.warning(f"It is a folder")
rmtree(cls.stash_for(p), ignore_errors=True)
logging.warning(f"Copying {p} to {cls.stash_for(p)}")
copytree(p, cls.stash_for(p))
else:
logging.warning(f"It is a file")
logging.warning(f"Copying {p} to {cls.stash_for(p)}")
copyfile(p, cls.stash_for(p))
# Assert the file is copied
assert path.isfile(cls.stash_for(p))
@ -229,9 +227,7 @@ class ServiceManager(Service):
@classmethod
def pre_backup(cls):
logging.warning("Pre-backup")
tempdir = cls.dump_dir()
logging.warning(f"Tempdir: {tempdir}")
rmtree(join(tempdir), ignore_errors=True)
makedirs(tempdir)
@ -239,9 +235,12 @@ class ServiceManager(Service):
assert len(listdir(tempdir)) == 0
for p in [USERDATA_FILE, SECRETS_FILE, DKIM_DIR]:
logging.warning(f"Stashing {p}")
cls.stash_a_path(p)
@classmethod
def post_backup(cls):
rmtree(cls.dump_dir(), ignore_errors=True)
@classmethod
def dump_dir(cls) -> str:
"""

View file

@ -480,6 +480,9 @@ class Service(ABC):
def pre_backup(self):
pass
def post_backup(self):
pass
def post_restore(self):
pass