Operational procedure for backing up and restoring the StudyDeck database. The database is the single source of truth (decks, notes, cards, scheduling state, documents, embeddings, audit log). The application schema is owned by Flyway.
- The
studydeck-postgrescontainer is running (docker compose up -d postgres). dockeraccess on the host.
./scripts/backup.sh # writes ./backups/studydeck-<UTC-stamp>.dump
./scripts/backup.sh /mnt/backups # custom output directoryProduces a compressed custom-format dump (pg_dump -Fc). Verify integrity:
pg_restore --list ./backups/studydeck-<stamp>.dump | headRun via cron on the host (example: daily at 02:30, keep 14 days):
30 2 * * * cd /opt/studydeck && ./scripts/backup.sh /var/backups/studydeck && \
find /var/backups/studydeck -name 'studydeck-*.dump' -mtime +14 -deleteShip dumps off-host (object storage) for disaster recovery — a backup on the same host as the database is not a backup.
DESTRUCTIVE. Recreates the
publicschema before restoring. Stop the backend first so there are no active connections and Flyway does not race.
docker compose stop backend
./scripts/restore.sh ./backups/studydeck-<stamp>.dump # prompts for confirmation
docker compose up -d backendOn startup Flyway runs validate against the restored schema; a mismatch fails
fast. If the dump predates a migration, restore then let Flyway migrate forward.
The logical dumps above cover most needs. For RPO ≈ 0, enable WAL archiving on a
managed Postgres or a wal-g/pgBackRest sidecar — out of scope for the local
compose stack.
- Take a backup from production-like data.
- Restore into a throwaway database/container.
- Boot the backend against it and run the smoke checks.
- Confirm row counts for
deck,note,card,source_document.
An untested backup is a hypothesis, not a recovery plan.