WAL-safe DB backups + pre-migration snapshot (audit H4 baseline) #12

Merged
ronnyandre merged 1 commit from feat/db-backups into main 2026-06-03 10:20:40 +02:00
Owner

From docs/audit-2026-06.md H4. Branches off main (independent). This is the same-volume baseline you approved; off-volume copies are a documented follow-up pending a destination.

What it does

  • scripts/backup.mjs — WAL-safe VACUUM INTO snapshot into <dataDir>/backups/ (single consistent file, no -wal/-shm), timestamped, with retention (keep newest BACKUP_KEEP, default 14). Run via pnpm db:backup or import backupDatabase().
  • scripts/migrate.mjs — takes an automatic *-premigrate snapshot before applying migrations (Drizzles runtime migrator has no rollback). Warns-but-continues on backup failure so a transient issue cant crash-loop boot.
  • package.json db:backup script; .gitignore ignores backups/.
  • README Backups section: scheduling (host cron / Dokploy task), retention, and restore steps.

Verified locally: pnpm db:backup against dev.db produces a snapshot with PRAGMA integrity_check = ok and correct row counts; migrate.mjs runs the pre-migration backup then migrates. pnpm typecheck/lint/test (40/40) pass.

Still open (needs you): off-volume target — give me an object-storage/rsync destination and Ill wire snapshots to it. Also: set up the daily scheduled task in Dokploy (node scripts/backup.mjs).

From `docs/audit-2026-06.md` **H4**. Branches off `main` (independent). This is the **same-volume baseline** you approved; off-volume copies are a documented follow-up pending a destination. **What it does** - `scripts/backup.mjs` — WAL-safe `VACUUM INTO` snapshot into `<dataDir>/backups/` (single consistent file, no `-wal`/`-shm`), timestamped, with retention (keep newest `BACKUP_KEEP`, default 14). Run via `pnpm db:backup` or import `backupDatabase()`. - `scripts/migrate.mjs` — takes an automatic `*-premigrate` snapshot **before** applying migrations (Drizzles runtime migrator has no rollback). Warns-but-continues on backup failure so a transient issue cant crash-loop boot. - `package.json` `db:backup` script; `.gitignore` ignores `backups/`. - README **Backups** section: scheduling (host cron / Dokploy task), retention, and restore steps. **Verified locally:** `pnpm db:backup` against dev.db produces a snapshot with `PRAGMA integrity_check = ok` and correct row counts; `migrate.mjs` runs the pre-migration backup then migrates. `pnpm typecheck`/`lint`/`test` (40/40) pass. **Still open (needs you):** off-volume target — give me an object-storage/rsync destination and Ill wire snapshots to it. Also: set up the daily scheduled task in Dokploy (`node scripts/backup.mjs`).
- scripts/backup.mjs: VACUUM INTO snapshot to <dataDir>/backups/ (WAL-safe,
  single-file), timestamped, with retention (keep newest BACKUP_KEEP, default
  14). Runnable via 'pnpm db:backup' or importable.
- scripts/migrate.mjs: take an automatic *-premigrate snapshot before applying
  migrations so a bad migration is recoverable (Drizzle's runtime migrator has
  no rollback). Warns-but-continues on backup failure so a transient issue
  can't crash-loop boot.
- package.json: add db:backup script. .gitignore: ignore backups/.
- README: 'Backups' section (scheduling via host cron/Dokploy, restore steps).

Same-volume protection only (guards bad migrations / deletes / corruption);
off-volume copies to external storage are a documented follow-up.
ronnyandre deleted branch feat/db-backups 2026-06-03 10:20:41 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ronnyandre/fliary!12
No description provided.