S3-compatible off-volume backup uploads (completes audit H4) #15

Merged
ronnyandre merged 2 commits from feat/backup-s3 into main 2026-06-03 10:53:23 +02:00
Owner

Completes H4 — the same-volume baseline shipped in #12, this adds the off-volume copy you asked for (S3-compatible).

What it does

  • After the local VACUUM INTO snapshot, pnpm db:backup uploads it to an S3-compatible bucket when BACKUP_S3_* is set (Cloudflare R2 / AWS S3 / Backblaze B2 / MinIO via custom endpoint).
  • @aws-sdk/client-s3 is lazy-imported inside the upload fn, so the boot/migrate path (which imports backupDatabase) never loads it and its only pulled in when off-volume backups are enabled.
  • Upload runs only in the scheduled job, not the pre-migration backup (which must stay fast/local so it cant slow or break boot).
  • Job exits non-zero on upload failure so monitoring can alert.
  • S3 retention = bucket lifecycle rules (not reimplemented; avoids needing list/delete perms). Local retention still via BACKUP_KEEP.
  • README documents the BACKUP_S3_* vars, lifecycle retention, and restore.

Verified: local snapshot + "S3 not configured" path works; SDK import + client/command construction verified; pnpm typecheck/lint/test (40/40) pass. (A real upload needs a bucket — not exercised in CI.)

Operator TODO after merge: set BACKUP_S3_* + a daily node scripts/backup.mjs Dokploy task + a bucket lifecycle rule.

Completes **H4** — the same-volume baseline shipped in #12, this adds the off-volume copy you asked for (S3-compatible). **What it does** - After the local `VACUUM INTO` snapshot, `pnpm db:backup` uploads it to an S3-compatible bucket when `BACKUP_S3_*` is set (Cloudflare R2 / AWS S3 / Backblaze B2 / MinIO via custom `endpoint`). - `@aws-sdk/client-s3` is **lazy-imported** inside the upload fn, so the boot/migrate path (which imports `backupDatabase`) never loads it and its only pulled in when off-volume backups are enabled. - Upload runs **only in the scheduled job**, not the pre-migration backup (which must stay fast/local so it cant slow or break boot). - Job **exits non-zero on upload failure** so monitoring can alert. - **S3 retention** = bucket lifecycle rules (not reimplemented; avoids needing list/delete perms). Local retention still via `BACKUP_KEEP`. - README documents the `BACKUP_S3_*` vars, lifecycle retention, and restore. **Verified:** local snapshot + "S3 not configured" path works; SDK import + client/command construction verified; `pnpm typecheck`/`lint`/`test` (40/40) pass. (A real upload needs a bucket — not exercised in CI.) **Operator TODO after merge:** set `BACKUP_S3_*` + a daily `node scripts/backup.mjs` Dokploy task + a bucket lifecycle rule.
scripts/backup.mjs: after the local VACUUM INTO snapshot, the CLI uploads it to
an S3-compatible bucket when BACKUP_S3_* env vars are set (Cloudflare R2 / AWS
S3 / Backblaze B2 / MinIO via custom endpoint). The @aws-sdk/client-s3 import is
lazy so the boot/migrate path (which imports backupDatabase) never loads it and
it's only needed when off-volume backups are enabled.

- Upload runs only in the scheduled db:backup job, not the pre-migration backup
  (which must stay fast/local so it can't slow or break boot).
- The job exits non-zero on upload failure so monitoring can alert.
- S3 retention is left to bucket lifecycle rules; local retention via BACKUP_KEEP.
- README documents the BACKUP_S3_* vars, lifecycle retention, and restore.

Completes H4 (same-volume baseline shipped earlier in #12).
Recent @aws-sdk/client-s3 versions default to CRC32 + aws-chunked trailer
checksums on PutObject, which breaks uploads to several S3-compatible stores
(Cloudflare R2, Backblaze B2, MinIO). Set requestChecksumCalculation /
responseChecksumValidation to WHEN_REQUIRED; harmless on real AWS S3.
ronnyandre deleted branch feat/backup-s3 2026-06-03 10:53:25 +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!15
No description provided.