Zero-Cost Encrypted Backups for Self-Hosted AI Stacks: Automated pg_dump + age + Cloudflare R2 & Restore Drill
An untested backup stored on the same VPS disk is not a backup—it is a wish. Combine nightly `pg_dump | gzip` + `age` public-key encryption + `rclone copy` to Cloudflare R2’s free 10 GB tier (zero egress fees), store your `N8N_ENCRYPTION_KEY` separately in a password manager, and run a 3-minute restore drill into a throwaway container once a quarter.
1. The Two Disaster Mistakes That Wipe Out Months of Automations
Mistake #1 is backing up `/root/backups/n8n.sql.gz` onto the exact same VPS SSD. If the host RAID array fails or a billing glitch terminates the VM, both your live server and your backups vanish in the same second.
Mistake #2 is backing up PostgreSQL faithfully every night while forgetting `.env` (`N8N_ENCRYPTION_KEY`). When you restore `n8n.sql.gz` onto a fresh VPS with a freshly generated encryption key, n8n boots cleanly—and then throws decryption errors on every single Google, Slack, OpenAI, and Stripe credential you ever saved.
2. Copy-Paste Nightly Encrypted Backup Script (Cloudflare R2 Free 10 GB)
With `age` (single static Go binary, zero GPG keyring headaches) and `rclone`, your entire encrypted disaster-recovery pipeline fits in ten lines of bash and costs **$0.00/month** on Cloudflare R2’s 10 GB free tier:
#!/usr/bin/env bash
set -euo pipefail
STAMP=$(date +%F-%H%M)
TMP="/tmp/n8n-${STAMP}.sql.gz.age"
AGE_PUBKEY="age1yourpublickeyhere..." # Keep private key OFFLINE in 1Password/Bitwarden
docker exec nodebudget-postgres pg_dump -U n8n n8n \
| gzip -9 \
| age -r "${AGE_PUBKEY}" > "${TMP}"
rclone copyto "${TMP}" "r2:nodebudget-backups/n8n-${STAMP}.sql.gz.age"
rm -f "${TMP}"
# Keep 30 days of encrypted daily snapshots automatically
rclone delete --min-age 30d r2:nodebudget-backups/