fix(cli): safe SQLite db backup/restore (config path + VACUUM INTO)#837
Merged
Conversation
pad db backup/restore hardcoded ~/.pad/pad.db, so `docker exec pad db
backup` (container sets PAD_DATA_DIR=/data) and Windows layouts broke,
and the SQLite path did a torn io.Copy of pad.db + separate -wal/-shm
copy that could lose or tear in-flight WAL writes.
- Resolve the SQLite path via the server's config loader (PAD_DB_PATH >
PAD_DATA_DIR/pad.db > ~/.pad/pad.db) instead of os.Getenv("HOME").
Covers backup, restore, and migrate-to-pg's --from default.
- Replace the file copy with an online-safe `VACUUM INTO` through the
embedded modernc.org/sqlite driver: one self-contained file, no
-wal/-shm juggling, safe while the server is live.
- Restore refuses when a live server is detected (a running WAL
checkpoint could clobber the restored file); --force overrides.
- docs/backup.md: `pad db backup -o <file>` is the canonical SQLite
path (+ the `docker exec <container> pad db backup -o /data/backup.db`
form); dropped the "PostgreSQL-only" mislabel.
PostgreSQL pg_dump/psql paths are unchanged.
Fixes BUG-1996.
Claude-Session: https://claude.ai/code/session_01BoPkYhKqMiWPYmxQigeWsA
Address Codex review P2s: - Restore: treat a failure to remove a stale -wal/-shm at the target as fatal (was silently ignored). With single-file VACUUM INTO backups a leftover sidecar would replay old WAL state over the restored DB. - docs/backup.md: the SQLite strategy block still recommended a raw `cp pad.db` daily; point it at `pad db backup --cron` instead. Claude-Session: https://claude.ai/code/session_01BoPkYhKqMiWPYmxQigeWsA
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.
pad db backup/restore hardcoded ~/.pad/pad.db (broken in Docker/Windows) and did a torn WAL file-copy. Now resolves the path via the server config loader (PAD_DB_PATH > PAD_DATA_DIR > ~/.pad) and uses VACUUM INTO for an online-safe single-file backup; restore refuses a live server; docs corrected.
Fixes BUG-1996.
Gates: go build/test (store+cmd) green; golangci-lint clean; functional WAL backup+restore round-trip verified; Codex review CLEAN.
https://claude.ai/code/session_01BoPkYhKqMiWPYmxQigeWsA