Skip to content

backups: copy validated snapshots off the server, show backup health, and make setup insist on it - #91

Merged
TusanHomichi merged 10 commits into
mainfrom
claude/offsite-backups
Oct 14, 2026
Merged

TusanHomichi merged 10 commits into
mainfrom
claude/offsite-backups

Conversation

@TusanHomichi

@TusanHomichi TusanHomichi commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Primary Issue

Closes #90

Problem And Outcome

Automatic backups (ADR 0006) lived only in backups/ on the database's own disk. A dead disk, ransomware, or a deleted data directory would take the records and every backup together. Nothing asked anyone to fix that, and nothing showed when backups ran.

After this PR:

  • Copies: each validated backup is copied to a second disk or a mounted share and verified byte for byte.
  • Health: administrators see backup health on their home page.
  • Pressure to fix it: the installer, the home page, the checklist, and guided setup all warn until off-server copies are current. Nothing hard-blocks use of the application.

Changes

  • ADR 0024 amends ADR 0006. It covers the copy contract, health read from the files, and how the product presses for a copy. ADR 0023, the installation lifecycle from setup: one-command install and upgrade, release archives, and a first-day checklist #89, now also records --data-dir, --backup-dir, and the paths.conf drop-in.
  • backup_copy.rs:
    • copy_snapshot copies to .partial, fsyncs, verifies the copy's SHA-256 against the snapshot, renames, and fsyncs the directory.
      • If the copy can't be made durable, it is removed.
      • The copy directory is then pruned to retention.
    • A copy directory on the local snapshots' filesystem is never used or counted. That is what an unmounted share's empty mount point looks like. The rule also covers the data directory itself.
    • catch_up copies the newest snapshot when it is missing, or finishes retention when it is present.
    • status / status_for (manage_users, enforced by the service): a copy is current exactly when the newest local snapshot's name is in a copy directory on another filesystem.
  • Scheduler: copies after each validated backup and retries every 15 minutes. Failures raise a deduplicated backup_copy_failed notice.
  • CLI and HTTP:
    • serve and backup accept --backup-copy-dir (CONSOLEBOOK_BACKUP_COPY_DIR), and serve warns at start when it is unset.
    • New endpoint: GET /api/backups/status.
  • Web: a BackupHealth panel on the admin home, Getting started step 8, and a guided-setup Backups step.
  • Installer:
    • --data-dir and --backup-dir are validated before anything is stopped or replaced.
    • Copy directory: the installer never creates it. It refuses one that is missing or on the data directory's filesystem, and warns instead for an already-configured one.
    • Moving data: it refuses to point an installation that has records at a new data directory. The documented manual move replaces it.
    • Drop-in: paths.conf grants the chosen paths. The copy path is optional (-), so a missing share never stops the service.
  • Release workflow: on both architectures, under real systemd:
    • a data-directory change and an unmounted copy directory are each refused, and the service keeps running;
    • with a tmpfs standing in for the share, the first copy is cmp-identical and journaled as verified;
    • after the share is unmounted and removed, the service restarts healthy.
  • Docs: the install guide covers choosing and mounting the copy location, backup and recovery, and moving the data directory.
  • Tests: the browser tests' sign-out race fix from test(e2e): wait for sign-out to finish before navigating #102 is ported here as 97d1488. It no-ops once test(e2e): wait for sign-out to finish before navigating #102 merges.

Correction rung: 2 (mechanical). The copy and health contract has integration tests with negative controls. Stubbing the filesystem guard, the retention retry, or the "current" rule fails a test.

Scope

Verification

  • Local full gates passed on 97d1488, with the permission-bypass capabilities dropped and system Chromium:
    • all 7 steps passed;
    • the browser suite reported 59 expected and 0 unexpected;
    • the tree did not change during the run;
    • receipt.json sha256 8f20468f62760474efbaace20567edcac0e39579df6286572a90dda202996840.
  • tests/backup_copy.rs, 6/6. /dev/shm is used as the second filesystem. Covered:
    • a byte-identical copy, pruned to retention;
    • a missing or non-directory target leaves the local snapshot intact;
    • an unmounted "mount point" is never written to or counted;
    • catch-up copies only what is missing, and finishes retention;
    • status transitions and the capability gate.
  • Hosted on 97d1488:
    • fmt-clippy-test passed;
    • release passed on both architectures with the refusal, copy, and missing-share-restart proofs above.
  • Automated review: seven findings across rounds, all fixed with tests or CI coverage. It was clean on 97d1488.
  • Added or updated tests when behavior changed
  • ADR 0024, and the ADR 0023 amendment
  • All fixtures and examples are invented

Review And Merge Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts


Generated by Claude Code

Automatic backups lived only in backups/ on the database's own disk.
ADR 0023 amends ADR 0006: with --backup-copy-dir /
CONSOLEBOOK_BACKUP_COPY_DIR, each validated snapshot is copied to a
second disk or mounted share under a temporary name, fsynced, verified
byte for byte by SHA-256, renamed into place, and pruned to the same
retention. A failed copy never touches the local snapshot; it raises a
backup_copy_failed notice to administrators and retries every 15
minutes, catching up whenever the copy directory lacks the newest
snapshot. `backup --backup-copy-dir` copies a manual backup too.

GET /api/backups/status (manage_users, enforced in backup_copy) reports
backup health from the files themselves: the copy is current exactly
when the newest local snapshot's name is in the copy directory. The
administrator's home shows it with a warning until copies are current,
the Getting started checklist gains that step, and guided setup shows it
with the installer command that fixes it.

install.sh takes --data-dir and --backup-dir, validates them before
touching anything (absolute, copy outside data), keeps them in the env
file, and writes a systemd drop-in so the sandbox may write exactly
those paths; without a copy directory it ends with a warning. The
release workflow proves the copy under the real sandbox.

Refs #90

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
The copy proof waited five minutes and failed on aarch64 because the
runner user cannot list /srv/consolebook-copies or the data directory's
backups/: both are 0750 and owned by the service account, as intended.
Inspect them with sudo.

Refs #90

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
Brings #89's latest state (probe follows the bind, release workflow on
every pull request, ADR 0023 for the installation lifecycle, and main
through #92) into this branch.

- release.yml: the upgrade step keeps both the backup warning check and
  the move to 127.0.0.2:7771.
- The backup ADR becomes ADR 0024, since the installer ADR took 0023;
  every reference is renumbered, and ADR 0024 cites ADR 0023 for the
  unit's writable paths.
- ADR 0023 now records --data-dir, --backup-dir, and the paths.conf
  drop-in this branch adds.

Refs #90

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
@TusanHomichi
TusanHomichi marked this pull request as ready for review October 14, 2026 19:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T20:08:07.304168Z 97d1488 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e2c602c134

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install/install.sh Resolved
Comment thread crates/consolebook-server/src/main.rs Resolved
Review of #91 found three ways a copy could be reported current while
it would not survive the server's disk:

- The installer created a missing --backup-dir. On an unmounted share
  that put the copies on the local disk. The same happens at runtime
  when a share drops: its mount point is an empty local directory.
  Copies, retries, and the health read now refuse a copy directory on
  the local snapshots' filesystem and report it unreachable ("not
  mounted"). The installer never creates the directory and refuses a
  --backup-dir that is missing or on the data directory's filesystem;
  for an already-configured one it warns instead, so an upgrade is not
  blocked by a share that is down.
- serve accepted the data directory itself as the copy directory; the
  filesystem rule covers that and any nesting.
- A copy whose post-rename fsync failed kept its name and so counted as
  current and was never retried; it is now removed.

Tests use /dev/shm as the second filesystem and add the unmounted
case; stubbing the guard fails it. The release workflow mounts a tmpfs
for the copy proof and checks that a plain local directory is refused
while the service keeps running. ADR 0024 and the install guide state
the rule.

Refs #90

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1dc5ca07d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install/install.sh Resolved
…ata directory

Rerunning the installer with a different --data-dir on an installation
that has a database rewrote the only data-directory setting; the service
then created an empty database there, the installer offered first-run
setup, and every record seemed to have vanished. The installer now
refuses that change before touching anything and says how to move the
directory deliberately. A directory without a database can still be
changed. The install guide documents the move, ADR 0023 records the
rule, and the release workflow checks that the refusal changes nothing.

Refs #90

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36da1fb59a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

If pruning the copy directory failed after a copy was made and made
durable, the retry found the newest copy in place and returned, so the
prune was never retried and the share could grow past retention until
a later snapshot happened to prune it. Catch-up now finishes retention
when the newest copy is already there, after the same
other-filesystem check. The catch-up test seeds an over-retention copy
directory; removing the prune fails it.

Refs #90

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba44ba2b0c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install/install.sh Resolved
The generated drop-in granted the copy directory as a required
ReadWritePaths entry. systemd fails namespace setup for a missing
required path, so a share absent at boot or restart stopped the whole
service instead of leaving backups local and reporting the copy
location unreachable (ADR 0024: the application is never blocked by a
missing copy). The entry is now optional ("-"), like the base unit's.

The release workflow unmounts and removes the share after the copy
proof, restarts the service, and requires it to come up healthy.

Refs #90

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
The shell keeps a signed-in browser out of /login and /reset. Twelve
browser steps clicked Sign out and navigated straight on; when the
logout request was still in flight (a loaded CI runner), /reset bounced
to the home page and the next fill waited out the test timeout. It
failed pr-gate on #91 in drafts.spec.ts:113.

One owning helper, signOut(page) in fixtures.ts, clicks Sign out and
waits for /login, which the shell reaches only after the server ends
the session. Every plain sign-out goes through it; the one deliberate
exception tests that a failed save refuses sign-out. A scratch spec
that delays the logout response by 1.5 s reproduced the bounce with the
old pattern and passed with the helper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

Copy link
Copy Markdown
Member Author

pr-gate on e9f3758 failed in e2e/drafts.spec.ts:113 (test timeout at getByLabel('Username') on /reset). It is not this PR's code. Since ba44ba2, whose full local gates passed with 59 browser tests, this branch had changed only the installer and the release workflow.

The cause is a race in the browser tests. Twelve steps click Sign out and navigate on without waiting. When the logout is still in flight, the shell's guard bounces a signed-in browser from /reset to home, so the Username field never appears. A scratch spec that delays the logout response reproduces it deterministically.

The fix is #102, a signOut(page) helper that waits for /login. The same commit is ported here as 97d1488, and it no-ops once #102 merges.


Generated by Claude Code

@TusanHomichi
TusanHomichi merged commit 7c4d011 into main Oct 14, 2026
4 checks passed
@TusanHomichi
TusanHomichi deleted the claude/offsite-backups branch October 14, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backups: copy validated snapshots off the server, show backup health, and make setup insist on it

2 participants