(feature) improve snapshot discovery visibility in Django

Add a discovery preflight that reports the configured backup root, host
root, and snapshot directory counts before importing anything.

Show discovery status on host detail pages so missing mounts or mismatched
host directories are visible from the UI.

Warn clearly when discovery scans zero snapshots, including whether the
host backup directory is missing or simply empty.
This commit is contained in:
2026-05-19 13:21:31 +02:00
parent 573177e118
commit 1d90454109
7 changed files with 133 additions and 7 deletions

View File

@@ -65,6 +65,54 @@ def discover_snapshots(
}
def inspect_snapshot_discovery(
*,
host: HostConfig,
global_config: GlobalConfig | None = None,
kinds: list[str] | None = None,
) -> dict[str, Any]:
try:
global_config = global_config or GlobalConfig.objects.get(name="default")
except GlobalConfig.DoesNotExist:
return {
"ok": False,
"reason": "missing_global_config",
"message": "Create the default global config before discovering snapshots.",
"backup_root": "",
"host_root": "",
"host_root_exists": False,
"kind_counts": {},
"total_candidates": 0,
}
kinds = kinds or ["scheduled", "manual", "incomplete"]
host_root = resolve_host_root(global_config.backup_root, host.host)
kind_counts = {kind: len(list(iter_snapshot_dirs(host_root, kind))) for kind in kinds}
total_candidates = sum(kind_counts.values())
host_root_exists = host_root.exists()
if not host_root_exists:
reason = "missing_host_root"
message = f"Host backup directory does not exist yet: {host_root}"
elif total_candidates == 0:
reason = "no_snapshots"
message = f"No snapshot directories found below {host_root}."
else:
reason = "ready"
message = f"Found {total_candidates} snapshot directories below {host_root}."
return {
"ok": True,
"reason": reason,
"message": message,
"backup_root": str(global_config.backup_root),
"host_root": str(host_root),
"host_root_exists": host_root_exists,
"kind_counts": kind_counts,
"total_candidates": total_candidates,
}
def upsert_snapshot_record(*, host: HostConfig, kind: str, snapshot_dir: Path) -> tuple[SnapshotRecord, bool]:
meta = read_snapshot_meta(snapshot_dir)
base_defaults = _base_defaults_from_meta(meta)