refactor: inject config sources into scheduled backups

Introduce a ConfigSource interface so scheduled backups no longer need
to load host configuration directly from runtime YAML. Add a Django-backed
config source for SQL-driven backup runs, keep file-based config as the
CLI default, and make scheduled prune execution actually apply retention
after successful runs.
This commit is contained in:
2026-05-19 04:57:10 +02:00
parent 18082496e4
commit bb44f8a09c
9 changed files with 216 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ from django.utils import timezone
from pobsync.commands.run_scheduled import run_scheduled
from pobsync.paths import PobsyncPaths
from pobsync_backend.config_repository import export_runtime_configs
from pobsync_backend.config_source import DjangoConfigSource
from pobsync_backend.models import BackupRun, HostConfig
@@ -32,7 +33,10 @@ class Command(BaseCommand):
except HostConfig.DoesNotExist as exc:
raise CommandError(f"Missing enabled HostConfig {host_name!r}") from exc
export_runtime_configs(prefix=paths.home, host=host.host)
# Compatibility bridge: retention planning still reads runtime YAML.
# The backup run itself receives config directly from Django.
if options["prune"]:
export_runtime_configs(prefix=paths.home, host=host.host)
run = BackupRun.objects.create(
host=host,
@@ -49,6 +53,7 @@ class Command(BaseCommand):
prune=bool(options["prune"]),
prune_max_delete=int(options["prune_max_delete"]),
prune_protect_bases=bool(options["prune_protect_bases"]),
config_source=DjangoConfigSource(),
)
except Exception as exc:
run.status = BackupRun.Status.FAILED