feat: record backup snapshots during run completion

Upsert SnapshotRecord rows directly from run_pobsync_backup results so
new successful and failed backup runs are reflected in the database
without requiring a separate discovery pass. Keep discovery for existing
snapshots and repair workflows, and cover success, failure, and dry-run
behavior with tests.
This commit is contained in:
2026-05-19 11:09:20 +02:00
parent 336fb1a5be
commit 0a49c5719c
3 changed files with 140 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ from pobsync.commands.run_scheduled import run_scheduled
from pobsync.paths import PobsyncPaths
from pobsync_backend.config_source import DjangoConfigSource
from pobsync_backend.models import BackupRun, HostConfig
from pobsync_backend.snapshot_discovery import infer_snapshot_kind, upsert_snapshot_record
class Command(BaseCommand):
@@ -73,6 +74,13 @@ class Command(BaseCommand):
"result",
],
)
if run.snapshot_path:
snapshot_path = Path(run.snapshot_path)
try:
kind = infer_snapshot_kind(snapshot_path)
upsert_snapshot_record(host=host, kind=kind, snapshot_dir=snapshot_path)
except ValueError:
pass
if result.get("ok"):
self.stdout.write(self.style.SUCCESS(f"Backup completed for {host.host}."))