Skip to content

fix(cli): safe SQLite db backup/restore (config path + VACUUM INTO)#837

Merged
xarmian merged 2 commits into
mainfrom
fix/db-backup-vacuum-into
Jul 7, 2026
Merged

fix(cli): safe SQLite db backup/restore (config path + VACUUM INTO)#837
xarmian merged 2 commits into
mainfrom
fix/db-backup-vacuum-into

Conversation

@xarmian

@xarmian xarmian commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

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

xarmian added 2 commits July 7, 2026 19:15
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
@xarmian xarmian merged commit 9be8e96 into main Jul 7, 2026
4 checks passed
@xarmian xarmian deleted the fix/db-backup-vacuum-into branch July 7, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant