Stream PostgreSQL backups directly to Cloudflare R2 with zero local disk staging, schedule automated backups, protect database migrations with pre-deploy snapshots, and support verified point-in-time restoration.
Zero-Disk Streaming Architecture (io.Pipe → R2)
Traditional backup scripts stage multi-gigabyte dumps on local NVMe disks before uploading—risking ENOSPC crashes on production database hosts. flarelensd executes pg_dump inside the target PostgreSQL container, pipes stdout through streaming gzip compression in Go memory (io.Pipe), and uploads multipart chunks straight to your R2 BACKUP_BUCKET via short-lived presigned URLs.
- Constant ~16 MB Memory Footprint: Multi-gigabyte databases stream directly to R2 with zero temporary files written to host storage.
- Multi-Environment DB Resolution: Automatically resolves the right database container and target database name (
DATABASE_URL,POSTGRES_DB, or*_DB_NAME) acrossuatandprodenvironments on shared or dedicated hosts. - Verified Metadata Catalog: Every completed snapshot records byte size, duration, SHA-256 checksum, environment, and revision lineage in D1.
Pre-Migration Guardrails & Automated Rollback
Pair pre_deploy_snapshot: true with run_migrations: true on stateful application manifests so every schema change is backed by a fresh R2 restore point:
name: ledger-api
env: prod
strategy: blue_green
image: ghcr.io/acme/ledger-api:v2.1.0
pre_deploy_snapshot: true
run_migrations: true
migration_command: ["goose", "-dir", "/app/migrations", "up"]Declarative Scheduled Cron Policies & R2 Retention (backup:)
Declare automated UTC backup schedules and R2 retention windows directly inside stateful manifests alongside jobs::
service: postgres
env: prod
mode: singleton
image: postgres:18
container_name: app-prod-postgres
backup:
schedule: "0 2 * * *" # Daily at 02:00 UTC
retain_days: 30 # Automatically prune R2 snapshots older than 30 days
prefix: postgres/prod
databases:
- core_prod
- workflow_prod- 1-Minute Edge Cron Evaluation: The Control Plane evaluates
backup.scheduleevery minute in UTC with D1 slot deduplication (backup_cron_slots), queueing zero-disk streamingpg_dumpruns for every configured database. - Automatic Retention Pruning: Snapshots under
backup.prefixolder thanretain_daysare pruned automatically from Cloudflare R2 after scheduled runs, while manual snapshots and point-in-time restores remain available one click away in the Backups console view.