Skip to content

backup copies: a replacement server copies its empty database over the share's newest backup #115

Closed

Description

@TusanHomichi

Problem or outcome

Found by the #97 clean-room restore drill against the published v0.1.0 release. The same code is on main at e8f4e42.

docs/install.md says that when the server's disk is gone, you "install on a new machine with the same --backup-dir, stop the service, and restore the newest file from the copy directory". Followed literally, that restores an empty database.

  1. The new installation starts with the copy directory configured. Its scheduler finds no local snapshot, snapshots the new empty database, and catch_up copies it into the share as consolebook-<now>.db. That file is now the newest one there.
  2. "Restore the newest file" restores that empty copy. Sign-in with the old accounts fails, and the records are missing.

Recorded run, with the same release on both hosts and the copy directory on another filesystem:

host A copies:  consolebook-20261015T003221Z.db  consolebook-20261015T003222Z.db   (records)
host B starts:  automatic backup complete ... consolebook-20261015T003223Z.db size_bytes=552960
                backup copied off the server and verified copy=.../consolebook-20261015T003223Z.db
restore newest: restored .../consolebook-20261015T003223Z.db (installation 5ffe5235-…)   <- host B's own empty install
collect:        POST /api/auth/login: 401 invalid_credentials

The same path does further harm:

  • After a restore, catch_up copies the newest local snapshot, which is now the consolebook-prerestore-<stamp>.db of the database just replaced (here, the empty one). The share's newest file is again not this installation's data.
  • A new server left running before anyone restores adds one empty copy per backup interval. With the default 14 copies kept, it prunes every real copy within 14 days.
  • Two installations pointed at one share prune each other's copies.

Scope

  • A copy directory holds one installation's backups.
    • copy_snapshot refuses a snapshot whose installation id differs from the id in the share's newest existing copy. Both ids are read from the files, read-only and immutable, so nothing is written to the share. This works for copy directories written by 0.1.0, which carry no marker.
    • The refusal says what to do: restore the newest copy if this server replaces that installation, otherwise give this installation its own directory.
  • Copies carry only this installation's backups.
  • docs/install.md: the replacement-server procedure says the new installation refuses to copy until you restore, and says which copy to restore.

Acceptance criteria

  • Integration tests:
    • a new installation whose share holds another installation's copies refuses to copy, writes nothing there, and reports why;
    • after restoring one of those copies, copying resumes;
    • a prerestore snapshot is never copied, and does not make the status behind.
  • The recovery: clean-room restore drill from a release install #97 drill, run with the fixed build as host B against a share written by v0.1.0 host A and following the guide literally, restores the records with identical record and chain hashes.

Execution record

Related

#97, ADR 0024, #105, #106

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions