BLACK FRIDAY 2026 LIVE: RackNerd 4GB VPS $47.98/yr (Lifetime) · ElevenLabs 55% Off · Hostinger 73% Off · Amazon Local AI Hardware View Verified Deals →
Lab Essay #10 · Disaster Recovery7 min readReal Lab Measurements

Zero-Cost Encrypted Backups for Self-Hosted AI Stacks: Automated pg_dump + age + Cloudflare R2 & Restore Drill

TL;DR

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.

NodeBudget 1-Click Deploy generator displaying a freshly generated 32-character N8N_ENCRYPTION_KEY and POSTGRES_PASSWORD
Figure 1 · Generating High-Entropy N8N_ENCRYPTION_KEY Before First Boot: Every OAuth refresh token and API key inside your PostgreSQL dump is encrypted with N8N_ENCRYPTION_KEY. Save that exact key outside your server the moment you generate your stack.

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/

Related Engineering Deep-Dives