recovery-manifest

Recovery catalog format 2

Implemented and tested locally; rollout and a live restore rehearsal are pending. Upgrade the destination's HostSSH binary and engine scripts before producing new packs. The source checks its own binary capability; it cannot establish the destination's installed version.

integrity.json remains the single file-size/SHA-256 catalog. Format 2 adds a random artifact ID, capture time, selected component roots, required adapter identifiers, engine/version fields, consistency scope, and verification level. The existing manifest.json remains descriptive capture metadata and is hashed as payload.

The first adapter is fleet-files-v1. Its components are filesystem roots with engineVersion: "unknown", consistency: "uncoordinated-files", and verification sha256-content-only. These fields do not assert Postgres compatibility, cross-database consistency, or application health. Native database discovery/version checks follow in H3. Credential references are currently an empty array; reusable credentials are never copied from captured file contents into the recovery catalog. Backup payloads can still contain secrets and need their existing encryption and access controls.

H3's Postgres adapter now adds version/digest receipts beside logical dumps. Catalogs containing those receipts also require postgres-logical-v1; the filesystem component's own consistency label remains unchanged.

Publish and verify

The fleet capture engine requests auto (format 2 when it fits, else format 3) when the pack binary advertises recovery-catalog-v3-sharded, otherwise format 2, and refuses an older binary. For a manually prepared, stable directory:

hostssh pack capabilities
hostssh pack write --format 2 --out /snapshot/stage/integrity.json \
  --root /snapshot/stage=var/backups/fleet-clone/example
hostssh pack verify --catalog /restore/var/backups/fleet-clone/example/integrity.json \
  --base /restore

The verification example assumes the stage has been copied into that restore-relative layout. Use an isolated extraction directory owned by the operator, with no concurrent writers.

Publication removes the previous completion marker, hashes and syncs payload files and directories, atomically writes and syncs the catalog, then checks the file inventory/hashes again. Only then does it atomically publish integrity.complete.json. This marker binds the artifact ID to the catalog's exact length and SHA-256. A failed/crashed attempt can leave a catalog without a marker; verification rejects it. Retry publication from stable content.

Restore verifies the marker and catalog before database, volume or configuration apply. It rejects unknown formats/fields/adapters, duplicate JSON keys/paths, overlapping roots, traversal, invalid sizes, missing components, special files, symlinks and mismatched content. Extra files anywhere in the extraction directory are rejected, including outside declared roots. The catalog has a 16 MiB limit. The Go publisher keeps indented JSON while it fits, and writes the same document without indentation only when indentation alone would pass 16 MiB. A compact catalog over 16 MiB is still refused, and that error names both sizes, the file count, and the largest roots. The fleet shell writer in engine/pack-integrity.sh already emits compact JSON and still refuses anything over 16 MiB. A larger inventory uses format 3 (below). The 16 MiB per-object ceiling is not raised. Committing this page does not install either writer on a node.

Fleet restore extracts each attempt into a fresh /var/restore/attempt.* directory and requires exactly one stage. That directory is retained for inspection; remove it only after the attempt is resolved and no restore is using it.

Fleet capture holds /var/backups/fleet-clone/.capture-lock-<box> through packing/upload. Normal exit removes the lock. After a killed capture, confirm no process still uses that workspace and inspect the prior attempt before manually removing its lock directory.

Compatibility and limits

  • To deliberately produce an old pack, use HOSTSSH_PACK_FORMAT=1 with fleet capture. The direct hostssh pack write command also retains format 1 as its compatibility default; pass --format 2 for publication evidence.
  • To restore an old pack, set HOSTSSH_ALLOW_LEGACY_PACK=1, or pass --allow-legacy to hostssh pack verify. A catalog-free image is labeled unverified; schema 1 verifies hashes without publication proof. A catalog still requires the upgraded verifier.
  • Legacy opt-in cannot bypass a missing or invalid format-2 marker. Verification errors never trigger a fallback to TSV, Python, or an older binary.
  • Format 2 fails closed on symlinks and special files. It does not silently omit them. Check this constraint against the selected filesystem roots before rollout.
  • A checksum does not authenticate the artifact's author. Signed packs remain separate work. Keep receiving directories private and use trusted encrypted transport/storage.
  • Publication does not freeze live volumes. Changes after publication can cause restore to reject the captured content; use snapshots/quiescence for stable capture. H4 covers stronger consistency coordination. Local process/fsync fault tests are not hardware power-loss proof.
  • Restic continues to own deduplication and snapshot dependencies. No manifest base chain, new storage service, database migration or dependency is introduced.

Format 3: sharded catalog

Added 2026-11-30 after the .223 nightly capture (96,671 files) failed with INVALID_FORMAT: catalog exceeds 16 MiB. Implemented and tested locally; not yet installed on any node.

  • integrity.json becomes a small head ("schema": 3) with the same artifact, root, sidecar and adapter fields as format 2, plus fileCount and a shards list. Each shard is integrity.shard-NNNNN.jsonl beside the head: one {"path","sha256","bytes"} object per line, in canonical path order (byte order with / lowest, which equals a directory-walk preorder).
  • The head lists each shard's name, SHA-256, byte length and entry count. integrity.complete.json still binds the head's length and SHA-256, so the marker transitively binds every shard.
  • No object exceeds the per-object limit: 16 MiB by default, lowerable (never raisable) with --catalog-max-bytes N or HOSTSSH_PACK_CATALOG_MAX_BYTES (64 KiB to 16 MiB).
  • Publication streams entries to shards and re-checks content with a streaming merge, so writer and verifier memory stays bounded by one shard, not the inventory (120,002 files: Go heap peak about 13 MiB to publish, 15 MiB to verify).
  • --format auto writes format 2 when it fits and format 3 otherwise. --format 3 always shards. --format 2 over the limit is refused and points at auto.
  • Verification checks every shard's digest, size, count, strict JSONL and strict ordering, and the full entry structure, before opening any payload. It then merge-joins the shards against the extraction directory (missing, extra, special files, size, hash). Unknown/missing/extra shard files, reordered or duplicate paths and a head/marker mismatch all fail closed.
  • Compatibility: a binary with recovery-catalog-v3-sharded still verifies format 1 (with legacy opt-in) and format 2 packs. An older binary cannot verify format 3. engine/pack-integrity.sh says so explicitly instead of falling back. Upgrade the destination before restoring a format-3 pack.
  • HOSTSSH_PACK_BIN lets the engine use a newer pack binary installed beside an older agent.

Live volumes: accept-changed capture policy

Added 2026-11-30 after a manual .223 capture failed CONTENT_CHANGED on all three attempts (07:21–07:52 ET). The volumes that changed were written continuously by running services: the Postfix spool (usermails-mta and the maillog bridge), Redis/Valkey persistence, MinIO objects, and worker state. A quiet re-check never comes for those. Implemented and tested locally; not yet installed on any node.

  • Each payload root is either strict (the default) or accept-changed. Strict roots keep every guarantee above: any change between the hash pass and its re-check fails publication with CONTENT_CHANGED, and restore refuses any difference.

  • An accept-changed root is captured in full; nothing is excluded or dropped. If its files change during publication, the publication still succeeds. The catalog keeps the first-pass observation of each file, marks the component "capture": "accept-changed", and adds recovery.drift: exact added, removed and modified counts in total and per root, link changes, and up to 2,000 changed paths in canonical order (truncated counts the paths that are not listed). The list gets shorter only when a format-3 head would otherwise go over the per-object limit. The counts are always exact. Drift sits inside the catalog, so the marker binds it.

  • Restore verification inside an accept-changed root reports differences instead of refusing them: missing files, extra files, modified files, skipped special files, and links. It prints pack verify: accept-changed roots differ at restore: .... restic reads live volumes after publication, so some difference is expected there. Strict roots, the stage, and paths outside every root still fail closed. The stage (root 0) can never be accept-changed.

  • hostssh pack write --root-changing ABS=REL (formats 2, 3 and auto) marks a root as live and accept-changed. The capability line is recovery-capture-accept-changed.

  • Fleet capture decides each Docker volume's policy, then logs it, writes it to system/docker-volume-policy.tsv, and records it under volume_policies in manifest.json:

    1. CAPTURE_STRICT_VOLUMES (name globs) forces strict and overrides every other rule.
    2. CAPTURE_CHANGING_VOLUMES (name globs) forces accept-changed.
    3. Otherwise a volume mounted by a running container whose image basename matches CAPTURE_CHANGING_IMAGES is accept-changed. The default list is redis redis-stack* valkey keydb minio postfix; set it to an empty string to turn this off.
    4. Everything else is strict.

    Non-volume paths listed in CAPTURE_CHANGING_PATHS (default /data/minio) are accept-changed. If the pack binary does not have the capability, capture logs a warning and captures every root strictly (the earlier behavior).

  • Compatibility: a catalog with policy fields needs a verifier that has recovery-capture-accept-changed. Older verifiers reject the unknown fields, and engine/pack-integrity.sh refuses up front with a clear message. Catalogs with only strict roots carry no new fields and are unchanged.

  • Limits: a file in an accept-changed root can be captured mid-write; the drift record names it. Use application-level dumps or quiescence (for example Redis BGSAVE or SAVE before capture) when point-in-time consistency matters. Redis RDB files are replaced atomically by rename, and AOF tolerates a truncated tail.

Capture unit sizing

The nightly unit is Type=oneshot, so only TimeoutStartSec bounds it; RuntimeMaxSec does not apply. The defaults are now:

SettingDefaultOverride
TimeoutStartSec4hCAPTURE_TIMEOUT
MemoryHigh2GCAPTURE_MEMORY_HIGH
MemoryMax3GCAPTURE_MEMORY_MAX
MemorySwapMax1GCAPTURE_SWAP_MAX
GOGC50CAPTURE_GOGC

Why these values: on .223, one hash pass plus its re-check took about 10 minutes, and three attempts took 31 minutes before restic started. The cgroup sat at the old 2G cap, mostly page cache. A first full upload of about 33 GiB takes roughly 15–30 minutes at 20–40 MB/s. Incremental runs finish far inside the bound.

Root numbering and Next.js cache volumes (2026-11-30 follow-up)

A manual .223 capture (10:19–10:44 PM ET) failed CONTENT_CHANGED on all three attempts, and the failure report looked like it blamed an accept-changed Redis volume. The policy itself was working. hostssh pack write was regrouping roots by flag kind: strict first, then live, then accept-changed. So root-N in the report did not match the capture's order (stage first, then each extra path). Every index after the first accept-changed volume pointed at a different, strict volume. Fixed:

  • Roots now keep their command-line order whatever their flag kind, so root-N is the Nth --root* flag. For fleet capture that means root-0 is the stage and root-N is manifest.json extra_paths[N-1].

  • The failure report and the CONTENT_CHANGED error now include rootPaths, which maps each blamed root-N to its catalog path (a mount point, never a file inside it).

  • Next.js cache volumes: HostSSH's deploy mounts a per-app <app>-cache volume at /app/.next/cache. It holds the ISR/fetch/route cache and /_next/image variants, keyed by BUILD_ID, and Next rebuilds all of it on demand. It also changes on almost every request. Fleet capture treats a volume as such a cache only when both of these are true:

    • its name matches CAPTURE_NEXT_CACHE_VOLUMES (default *-cache, a suffix match), and
    • every container that mounts it, running or stopped, mounts it only at /app/.next/cache.

    Such a volume is excluded and comes back empty on restore. It is listed in system/docker-excluded-volumes.txt, in docker-volume-policy.tsv as excluded next-cache, and in manifest.json volume_policies.

    • A volume with no container, a volume mounted at any other path, and names such as *_cache, *-cache-data or *-database are not proven caches. They keep their normal policy.
    • CAPTURE_STRICT_VOLUMES wins: such a volume is kept and stays strict.
    • CAPTURE_NEXT_CACHE=accept-changed captures these caches with drift instead of excluding them. CAPTURE_NEXT_CACHE=off turns the rule off.
    • fleet-capture.sh --next-cache NAME [DEST ...] shows the decision for one volume.