feat: link backup runs to snapshot records
Add a nullable SnapshotRecord foreign key to BackupRun and populate it when run_pobsync_backup records a completed or failed snapshot. Keep the existing snapshot_path for audit compatibility while making run-to-snapshot navigation explicit in the database and admin.
This commit is contained in:
@@ -64,23 +64,26 @@ class Command(BaseCommand):
|
||||
rsync = result.get("rsync") if isinstance(result.get("rsync"), dict) else {}
|
||||
run.rsync_exit_code = rsync.get("exit_code")
|
||||
run.result = result
|
||||
snapshot_record = None
|
||||
if run.snapshot_path:
|
||||
snapshot_path = Path(run.snapshot_path)
|
||||
try:
|
||||
kind = infer_snapshot_kind(snapshot_path)
|
||||
snapshot_record, _created = upsert_snapshot_record(host=host, kind=kind, snapshot_dir=snapshot_path)
|
||||
except ValueError:
|
||||
snapshot_record = None
|
||||
run.snapshot = snapshot_record
|
||||
run.save(
|
||||
update_fields=[
|
||||
"status",
|
||||
"ended_at",
|
||||
"snapshot_path",
|
||||
"snapshot",
|
||||
"base_path",
|
||||
"rsync_exit_code",
|
||||
"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}."))
|
||||
|
||||
Reference in New Issue
Block a user