Skip to content

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

Closed

Description

@TusanHomichi

Problem

Automatic backups (ADR 0006) take a validated VACUUM INTO snapshot on schedule and keep 14, but always in backups/ on the same disk as the database. A failed disk, ransomware, or an accidental deletion of the data directory loses the records and every backup together. Nothing in the product asks an administrator to put a copy anywhere else. Nothing shows when backups last ran, and the installer gives no choice of where data or backups live. For training records with retention obligations, an off-server copy should be the expected state, not an operator's afterthought.

Outcome

  • An optional backup copy directory (--backup-copy-dir / CONSOLEBOOK_BACKUP_COPY_DIR; a second disk or a mounted network share). After each validated local snapshot, serve and backup copy it there:

    • write to a temporary name, fsync, and validate the copy by opening it;
    • then rename into place, fsync the directory, and prune to the same retention.

    A failed copy never removes or weakens the local snapshot. It is reported like a failed backup, as an administrator notice.

  • Backup health, derived from the files themselves (GET /api/backups/status, manage_users): the interval and retention, the local snapshot count and newest time, and whether a copy directory is configured, reachable, and current (its newest copy is no older than the newest local snapshot).

  • The admin home shows backup health. A warning stays visible while no off-server copy is configured or the copy has fallen behind. The Getting started checklist gains a step that is done only when copies are current. The guided setup gets a Backups step that shows status and the exact installer command to fix it, since the service cannot and should not rewrite its own configuration.

  • The installer takes --data-dir and --backup-dir. It writes them into the env file and a systemd drop-in, so the sandbox can write only those paths. Without --backup-dir, it ends with a prominent warning.

  • An ADR amends ADR 0006 with the copy contract, and docs/install.md gains a backup section.

Scope

  • Out of scope:
    • Encryption of backups at rest (ADR 0006 already defers it).
    • Push-to-cloud transports: mount the target instead.
    • Restore from the copy directory beyond the existing restore <snapshot> path, which already accepts any path.
    • Hard-blocking use of the application without a copy.

Acceptance

  • Integration tests:
    • a configured copy directory receives a validated copy and is pruned to retention;
    • an unwritable copy directory fails the copy, keeps the local snapshot, and notifies administrators (negative control);
    • status reports current, behind, and unconfigured correctly.
  • ADR accepted.
  • A browser test shows the home warning without a copy directory.
  • The installer passes shellcheck; --data-dir and --backup-dir are exercised locally (--no-service), and on systemd in the release workflow.
  • Full required gates and hosted pr-gate pass.

Refs #87. Authorization: the maintainer's request in the working session ("some sort of backup mechanism should be strongly encouraged if not required"), with standing permission to carry it through merge and cleanup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions