feat(backup): scheduled database backup verification with restore testing - #148
Merged
JamesEjembi merged 1 commit intoAug 30, 2026
Conversation
…ting Implements the three-stage pipeline for Issue Lumina-etwork#101: nightly pg_dump backups compressed and encrypted at rest with AES-256 (with optional S3 off-site copy), integrity verification of each artifact against a checksum manifest, and a weekly restore test that replays the backup into an isolated scratch database and compares table and row counts against the live database before dropping it. Adds Prometheus metrics and alerting rules, a Grafana dashboard, admin API endpoints for status/history/manual triggers, a CLI entrypoint, full unit test coverage, and architecture and runbook documentation. No schema migrations are required.
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.
Motivation
Closes #101 — Scheduled Database Backup Verification with Restore Testing.
The backend depends on PostgreSQL for all persistent state, but a backup is
only useful if it can actually be restored. This change guarantees that by
running a three-stage pipeline on a schedule, so a "backup succeeded" claim is
backed by evidence that the data is restorable.
Description
Pipeline
takeBackup) — consistentpg_dumpsnapshot, gzip-compressed(zlib), encrypted at rest with AES-256 (OpenSSL PBKDF2), optionally copied
off-site to S3, with a SHA-256 manifest written alongside the artifact.
verifyBackup) — decrypt/decompress, re-compute thechecksum against the manifest, and validate the PostgreSQL dump header and
CREATE TABLEstatements.restoreTestBackup) — restore the backup into anisolated scratch database (
lumina_restore_test_*), compare the number ofpublictables and the row counts of key tables (BACKUP_VERIFY_TABLES)against the live database, then drop the scratch database (with lingering
connections terminated first) in a
finallyblock.Scheduling
BACKUP_CRON(default0 2 * * *) — daily backup + integrity verification.BACKUP_RESTORE_TEST_CRON(default0 4 * * 0) — weekly restore test of thelatest verified artifact.
BACKUP_ENABLED,BACKUP_RESTORE_TEST_ENABLED.Operations
GET /api/admin/backups/status,GET /api/admin/backups/history,POST /api/admin/backups/run,POST /api/admin/backups/restore-test.npm run backup:verifyandnpm run backup:restore-test(
backend/scripts/run-backup-verification.js), exit code 0/1 for cron/CI.verification-history.jsonl) withpruning, plus in-report metrics.
Monitoring
/metricsregistry: attempts, failures,durations, artifact size, verification status, last-success timestamps, and
per-table restore row deltas.
monitoring/prometheus/database-backup-verification-rules.yaml):DatabaseBackupFailed,DatabaseBackupStale,DatabaseBackupVerificationFailed,DatabaseBackupRestoreTestFailed,DatabaseBackupRestoreTestStale,DatabaseBackupRestoreRowDeltaMismatch.monitoring/grafana/dashboards/database-backup-verification.json).Documentation
backend/docs/architecture/database-backup-verification.mdbackend/docs/runbooks/database-backup-verification.mdBACKEND.mdand mirrored inbackend/.env.example.Configuration
Testing
backend/test/backup/covering configurationvalidation, the backup pipeline (with/without encryption, S3 upload, failure
paths), integrity verification (pass, checksum tamper, missing manifest),
restore testing (pass, row-count mismatch, table-count mismatch, scratch DB
lifecycle), full-cycle reports, history, and retention cleanup.
Deployment
Blue-green: deploy to green with backup jobs disabled, confirm metrics appear,
enable restore testing on green, then enable the full schedule and promote.
No schema migrations are involved, so rollback is a plain image revert.
Breaking Changes
None. All changes are additive and off the request critical path.