Repository navigation
backup(schedule): automatic backups, retention, and a proven restore path - #9
Merged
Merged
Conversation
…path Complete the Milestone 1 backup scope (ADR 0003 follow-through): - serve runs a background scheduler that keeps the newest snapshot no older than the configured interval (default 24h, minimum 1h); the due-decision is a pure tested function over snapshot mtime, failures log and retry, and there is deliberately no way to disable it - retention prunes to the newest N snapshots (default 14, minimum 1) only after a new snapshot validates, and never deletes the last one - serve holds an exclusive OS file lock on instance/serve.lock: two servers cannot share a data directory, and restore refuses while a server runs — a lock check, not a guess - consolebook restore <snapshot>: validates the snapshot, sets the current database aside (validated pre-restore snapshot when healthy, raw bytes marked .damaged when too corrupt to snapshot — corruption must not block its own repair), removes stale WAL sidecars, copies into place, fsyncs, and proves the result exactly as startup would - backup and restore record append-only audit events, as the domain model requires - doctor warns when the newest snapshot is older than the default interval and reuses the backup module's listing - 7 new integration tests: retention edges, scheduling decisions, destroyed-database round trip (damaged set-aside asserted), invalid snapshot refusal, lock refusal, lock exclusivity - ADR 0006 records scheduling, retention, lock, and restore decisions Closes #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Primary Issue
Closes #8
Problem And Outcome
Backups only happened when an operator remembered, nothing pruned old snapshots, and restore was undocumented file surgery. After merge, a running installation converges to a recent validated snapshot automatically, retention is bounded, and recovery from a destroyed database is one command whose mistake path is itself recoverable.
Changes
serveruns a background scheduler keeping the newest snapshot no older than the configured interval (default 24h,--backup-interval-hours, min 1); the due-decision is a pure tested function over snapshot mtime; failures log and retry; deliberately no disable flag (PRINCIPLES.md 8)--backup-keep, min 1) only after a new snapshot validates; never deletes the last remaining snapshotserveholds an exclusive OS file lock (instance/serve.lock): two servers can't share a data directory, andrestorerefuses while a server runs — a lock check, not a guessconsolebook restore <snapshot>: validate → lock → set current database aside (validated pre-restore snapshot when healthy; raw bytes marked.damagedwhen too corrupt to snapshot, so corruption can't block its own repair) → remove stale WAL sidecars → copy + fsync → prove the result exactly as startup would → auditbackup_completed/restore_completedappend-only audit events, per the domain model's audit vocabularydoctorwarns when the newest snapshot exceeds the default interval and reuses the backup module's listingScope
Verification
.damagedset-aside asserted, invalid-snapshot refusal, lock refusal, lock exclusivity)Review And Merge Notes
restore.rs(found during testing: the pre-restoreVACUUM INTOcannot snapshot a corrupt database, and the fix must not weaken the healthy-path guarantees), and ADR 0006's costs sectionrestoreis a supported command;serverefuses to double-start on one data directory