Skip to content

Check the restored database against the backup's manifest before it replaces the current one #568

Backlog

Description

@samuelmbabhazi

Problem

An instance restore checks the archive thoroughly before it changes anything (#439, #565). backup.js verify reads the whole archive: its manifest, its tag, its name, and every chunk to the end. That proves the right archive went in. Nothing checks what came out.

backup.sh restore runs pg_restore into shipkeep_restore, ends that database's sessions, then renames it into place. A pg_restore that exits 0 can still leave a database that does not match the archive:

  • one that is empty, or that holds only part of the data;
  • one whose schema is older or newer than the archive says.

The script cannot tell. It would swap that database in and report "Restored", and the previous database would survive only under shipkeep_before_restore_*.

The idea came from a reader's comment on the backup article: after a test restore, they check max(created_at) on a busy table and a row count, because they once had a restore that "worked" and produced an empty database.

Proposal

After pg_restore and before the rename, check the restored database against the manifest, which is authenticated:

  • Schema: the newest applied migration in _prisma_migrations is the manifest's migration.
  • Content: at least one user exists, since the installer creates the first account. When audit_events has rows, its newest created_at is no later than the manifest's createdAt, give or take clock skew. Every state change writes an audit event (CLAUDE.md, rule 6), so its newest row shows how recent the restored data is.
  • On failure:
    • drop shipkeep_restore, keep the current database, leave the key untouched;
    • say which check failed, with counts and timestamps only, never row contents;
    • stop with the control plane stopped, as the other refusals at this step already do.

Acceptance criteria

  • A restore whose pg_restore leaves an empty database is refused before the rename. The current database and the key file are unchanged.
  • A database restored without the manifest's newest migration is refused.
  • A database whose newest audit event is later than the manifest's createdAt (beyond the allowed skew) is refused.
  • A normal restore still succeeds, including the backup of an installation that holds only its first account.
  • The refusal messages name the check and contain no data from the database.
  • docs/INSTALL.md ("Back up and restore") and ADR 0026 describe the check.

Activity

  1. added
    enhancement
    priority:P3
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:P3track:control-plane

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions