2.5 KiB
2.5 KiB
Database Operations Runbook
This runbook defines backup, restore, and verification procedures for the
PostgreSQL database used by scholarr.
Objectives
- Keep data loss bounded via scheduled backups.
- Provide repeatable restore procedures.
- Verify backups by running regular restore drills.
Recommended starting targets:
RPO: 24 hours (maximum acceptable data loss).RTO: 60 minutes (maximum acceptable restore time).
Backup Strategy
Use logical backups from the running db compose service.
- Custom-format backup (recommended for restore flexibility):
scripts/db/backup_full.sh
- Plain SQL backup:
scripts/db/backup_full.sh --plain
Optional environment variables:
BACKUP_DIR: destination directory (default:<repo>/backups)BACKUP_PREFIX: backup filename prefix (default:scholarr)USE_DEV_COMPOSE=1: includedocker-compose.dev.yml
Restore Strategy
Restore from a .dump (custom format) or .sql file into the running db
compose service.
- Restore without schema wipe:
scripts/db/restore_dump.sh --file backups/scholarr_20260220T120000Z.dump
- Restore with full
publicschema reset:
scripts/db/restore_dump.sh --file backups/scholarr_20260220T120000Z.dump --wipe-public
Safety Checklist Before Restore
- Pause writes (stop app/scheduler or set maintenance mode).
- Create a fresh pre-restore backup.
- Validate target dump checksum/size.
- Confirm operator, scope, and rollback plan.
Post-Restore Verification
- Run migrations head check.
- Run health endpoint checks.
- Verify table row counts for core tables:
usersscholar_profilespublicationsscholar_publicationscrawl_runs
- Run integrity report and require zero failures:
python3 scripts/db/check_integrity.py
- Run API smoke checks for scholars/publications/runs pages.
Data Cleanup and Repair
Use the audited repair job for scholar-publication relinking cleanup:
python3 scripts/db/repair_publication_links.py --user-id <id> --requested-by "<operator>" --apply
Dry-run first, then re-run with --apply once scope and summary counts match expectation.
If cleanup changes schema assumptions, follow docs/ops/migration_checklist.md before any migration rollout.
Restore Drill Cadence
- Run at least one full restore drill per month.
- Record:
- backup artifact used,
- restore start/end timestamps,
- issues encountered,
- achieved
RTO.