Jawaban singkat: backup n8n = 3 lapis — (1) Workflow JSON (harian ke GitHub/Drive/S3), (2) PostgreSQL Database (pg_dump harian), (3) n8n Data Folder (tar.gz harian). Restore: VPS baru → Docker Compose → Restore DB + Data → Import Workflow → Verify. Artikel ini setup otomatis, schedule, retention, disaster recovery test, dan migrasi server.
Mengapa Backup n8n Itu Kritis (Bukan Optional)
- Workflow = Otak Bisnis: Logic, Prompt, Kredensial (encrypted), Konfigurasi — hilang = bangun dari nol (hari-hari kerja).
- Executions = Audit Trail & Debugging: History chat, error log, performance metrics — hilang = buta troubleshooting.
- Credentials = Kunci Kerajaan: API Key, Token, Password (encrypted di DB) — hilang = harus reset semua integrasi.
- Risk: VPS Crash / Disk Full / Hack / Provider Shutdown / Human Error (delete workflow) — tanpa backup = bisnis stop.
- Compliance & Legal: Audit trail transaksi, komplain, verifikasi pembayaran — butuh retensi 1-2 tahun.
Apa yang Harus Di-Backup (3 Komponen Wajib)
| Komponen | Lokasi | Isi | Ukuran | Frekuensi |
|---|---|---|---|---|
| 1. Workflow JSON | n8n DB (table: workflow_entity) / Export API | Semua workflow: nodes, connections, settings, tags, credentials reference | ~1-10 MB | Harian (setiap jam untuk produksi tinggi) |
| 2. PostgreSQL Database | /opt/n8n/postgres (Docker volume) | Workflows, Credentials (encrypted), Executions, Users, Settings, Variables | ~50-500 MB | Harian 03:00 (pg_dump) |
| 3. n8n Data Folder | /opt/n8n/data (Docker volume) | Binary files (uploaded files), Custom nodes, SSH keys, License, Config | ~10-100 MB | Harian 03:30 (tar.gz) |
Strategi Backup: 3-2-1 Rule (Best Practice)
- 3 Copies: Original (VPS) + Backup Local (VPS) + Backup Remote (GitHub/Drive/S3)
- 2 Media: Disk VPS + Cloud Storage (GitHub/Drive/S3) + Optional: USB/NAS
- 1 Offsite: Minimal 1 copy di lokasi fisik/cloud berbeda (GitHub Private Repo / Google Drive / AWS S3 / Backblaze B2)
Implementasi Otomatis: Backup Script (Cron Daily)
Script Backup Lengkap (Simpan di `/opt/n8n/scripts/backup.sh`)
# Backup n8n Otomatis – Jalankan via Cron Daily 03:00
# Simpan di: /opt/n8n/scripts/backup.sh
# chmod +x /opt/n8n/scripts/backup.sh
set -e
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR=”/opt/n8n/backups”
RETENTION_DAYS=30
RETENTION_MONTHS=12
# Load environment
source /opt/n8n/.env
echo “[$(date)] Starting n8n backup…”
# 1. Backup Workflow JSON via n8n CLI (butuh n8n running)
echo “Backing up workflows JSON…”
docker compose -f /opt/n8n/docker-compose.yml exec -T n8n n8n export:workflow –all –output=/home/node/.n8n/backups/workflows_${DATE}.json 2>/dev/null || true
# Copy dari container ke host
docker cp $(docker compose -f /opt/n8n/docker-compose.yml ps -q n8n):/home/node/.n8n/backups/workflows_${DATE}.json ${BACKUP_DIR}/workflows_${DATE}.json 2>/dev/null || true
# 2. Backup PostgreSQL Database (pg_dump)
echo “Backing up PostgreSQL…”
docker compose -f /opt/n8n/docker-compose.yml exec -T postgres pg_dump -U n8n -d n8n –no-owner –no-privileges –clean –if-exists | gzip > ${BACKUP_DIR}/postgres_${DATE}.sql.gz
# 3. Backup n8n Data Folder (binary, custom nodes, config)
echo “Backing up n8n data folder…”
tar -czf ${BACKUP_DIR}/n8n_data_${DATE}.tar.gz -C /opt/n8n/data . –exclude=’backups’ –exclude=’*.log’ –exclude=’*.pid’
# 4. Upload ke GitHub Private Repo (via Git)
if [ -d “/opt/n8n/backup-repo/.git” ]; then
echo “Syncing to GitHub…”
cp ${BACKUP_DIR}/workflows_${DATE}.json /opt/n8n/backup-repo/workflows/latest.json
cp ${BACKUP_DIR}/postgres_${DATE}.sql.gz /opt/n8n/backup-repo/postgres/latest.sql.gz
cp ${BACKUP_DIR}/n8n_data_${DATE}.tar.gz /opt/n8n/backup-repo/n8n_data/latest.tar.gz
cd /opt/n8n/backup-repo
git add .
git commit -m “Auto backup ${DATE}” –quiet
git push origin main –quiet
echo “GitHub sync done.”
fi
# 5. Upload ke Google Drive (via rclone – optional)
if command -v rclone &> /dev/null && [ -f “/opt/n8n/rclone.conf” ]; then
echo “Syncing to Google Drive…”
rclone copy ${BACKUP_DIR}/ gdrive:n8n-backups/ –include=”*_${DATE}*” –quiet
echo “Google Drive sync done.”
fi
# 6. Upload ke AWS S3 / Backblaze B2 (via rclone – optional)
if command -v rclone &> /dev/null && [ -f “/opt/n8n/rclone.conf” ]; then
echo “Syncing to S3/B2…”
rclone copy ${BACKUP_DIR}/ s3:n8n-backups/ –include=”*_${DATE}*” –quiet
echo “S3/B2 sync done.”
fi
# 7. Cleanup Local Old Backups (Retention)
echo “Cleaning up old local backups (>${RETENTION_DAYS} days)…”
find ${BACKUP_DIR} -name “workflows_*.json” -mtime +${RETENTION_DAYS} -delete
find ${BACKUP_DIR} -name “postgres_*.sql.gz” -mtime +${RETENTION_DAYS} -delete
find ${BACKUP_DIR} -name “n8n_data_*.tar.gz” -mtime +${RETENTION_DAYS} -delete
# Keep Monthly (1st day of month) for 12 months
find ${BACKUP_DIR} -name “*_01_*.json” -mtime +365 -delete
find ${BACKUP_DIR} -name “*_01_*.sql.gz” -mtime +365 -delete
find ${BACKUP_DIR} -name “*_01_*.tar.gz” -mtime +365 -delete
echo “[$(date)] Backup completed successfully.”
Setup Cron Job
crontab -e
# Backup Daily 03:00
0 3 * * * /opt/n8n/scripts/backup.sh >> /opt/n8n/backups/backup.log 2>&1
# Verifikasi backup weekly (Senin 04:00) – cek file exists & size > 0
0 4 * * 1 bash -c ‘if [ ! -s /opt/n8n/backups/workflows_$(date -d “yesterday” +\%Y\%m\%d)_*.json ]; then echo “BACKUP MISSING!” | mail -s “n8n Backup Alert” admin@domain.com; fi’
Remote Storage Setup (GitHub + Google Drive + S3)
1. GitHub Private Repo (Gratis, Version Control, Unlimited)
- Buat GitHub Private Repo: `n8n-backups`
- Generate Personal Access Token (PAT): Settings → Developer Settings → PAT → `repo` scope
- Clone ke VPS: `cd /opt/n8n && git clone https://PAT@github.com/username/n8n-backups.git backup-repo`
- Setup Git Config: `cd /opt/n8n/backup-repo && git config user.name “n8n Backup Bot” && git config user.email “backup@domain.com”`
- Script backup sudah include `git add/commit/push`
2. Google Drive (Gratis 15GB, Easy)
- Install rclone: `curl https://rclone.org/install.sh | bash`
- Config: `rclone config` → `n` → `gdrive` → `drive` → Follow OAuth (browser di VPS via `rclone config` headless atau copy config dari local)
- Test: `rclone ls gdrive:`
- Script backup sudah include `rclone copy` ke `gdrive:n8n-backups/`
3. AWS S3 / Backblaze B2 (Murah, Scalable, Enterprise)
- Backblaze B2: $5/TB/bulan (lebih murah vs S3 $23/TB)
- rclone config → `b2` / `s3` → Credentials
- Script backup include `rclone copy` ke `s3:n8n-backups/` / `b2:n8n-backups/`
- Lifecycle Policy: Delete after 90 days (cost control)
Restore & Disaster Recovery (Step-by-Step)
Scenario: VPS Baru / VPS Crash Total / Migrasi Server
- Provision VPS Baru (Same spec atau lebih besar) → Ubuntu 22.04/24.04
- Install Docker + Docker Compose + Nginx + Certbot (seperti setup awal)
- Restore PostgreSQL:
cd /opt/n8n && docker compose up -d postgres
# Wait healthy
# 2. Restore dari pg_dump (latest.sql.gz dari GitHub/Drive/S3)
gunzip -c postgres_latest.sql.gz | docker compose exec -T postgres psql -U n8n -d n8n
# 3. Verify: docker compose exec postgres psql -U n8n -d n8n -c “SELECT count(*) FROM workflow_entity;”
- Restore n8n Data Folder:
docker compose down
# Restore data folder
tar -xzf n8n_data_latest.tar.gz -C /opt/n8n/data
# Start all
docker compose up -d
- Start n8n & Verify:
# Wait healthy
curl -f https://domain-anda.com/healthz
# Login n8n → Check: Workflows ada, Credentials ada, Executions history ada
- Verify WhatsApp Webhook: Kirim test chat → Execution sukses
- Update DNS (jika IP berubah): DNS A Record → IP VPS Baru
Scenario: Hanya Workflow Terhapus (Human Error)
- n8n UI → Workflows → **Import** → Pilih `workflows_latest.json` dari backup → Import
- Atau CLI: `docker compose exec n8n n8n import:workflow –input=/home/node/.n8n/backups/workflows_latest.json`
- Credentials: Jika credentials reference hilang → Re-enter di n8n UI (Credentials tab)
Migrasi Server (VPS ke VPS / Cloud ke Self-Hosted / Self-Hosted ke n8n Cloud)
| Migrasi | Metode | Downtime | Catatan |
|---|---|---|---|
| VPS → VPS Baru (Same Version) | Full Restore (DB + Data + Workflows) | 10-30 menit | DNS switch setelah verify |
| VPS → n8n Cloud | Export Workflows JSON → Import di n8n Cloud + Re-enter Credentials | 1-2 jam | Executions history TIDAK migrasi (hanya workflows). Credentials manual. |
| n8n Cloud → VPS Self-Hosted | Export Workflows JSON → Import ke VPS + Re-enter Credentials | 1-2 jam | Sama atas. Executions history tidak migrasi. |
| n8n Version Upgrade (Major) | Backup → Upgrade Docker Image → Verify → Rollback kalau error | 5-10 menit | Backup wajib sebelum upgrade major. Test di staging dulu. |
Monitoring & Verifikasi Backup (Anti “Backup Ternyata Kosong”)
🛡️ VERIFIKASI WAJIB (Otomatis + Manual):
- Daily Auto-Check (Cron 04:00): Script cek file backup kemarin exists & size > 1KB → Jika gagal → Alert Telegram/Email
- Weekly Manual Verify (Senin): Restore test ke Local Docker / VPS Staging → Verify workflows, credentials, executions load benar
- Monthly Full Disaster Recovery Drill: Provision VPS baru (bisa VPS murah $3/bln) → Full Restore → Verify WhatsApp webhook jalan → Destroy VPS. Cost: ~Rp 50rb/bulan untuk peace of mind.
- Checksum Verification: `sha256sum` backup files → Simpan di log → Verify saat restore
Retention Policy (Berapa Lama Simpan Backup)
| Tipe | Retensi Local | Retensi Remote (GitHub/Drive/S3) | Alasan |
|---|---|---|---|
| Daily (Full) | 30 hari | 90 hari | Recovery point harian |
| Weekly (Mingguan – hari Minggu) | 12 minggu | 1 tahun | Recovery point mingguan |
| Monthly (1 tanggal) | 12 bulan | 7 tahun (compliance) | Recovery point bulanan, audit trail |
| Yearly (1 Januari) | Permanen | Permanen | Archive tahunan |
Checklist Backup & Recovery Minggu Ini
- [ ] Buat script `/opt/n8n/scripts/backup.sh` (copy template di atas)
- [ ] `chmod +x /opt/n8n/scripts/backup.sh`
- [ ] Test run manual: `/opt/n8n/scripts/backup.sh` → cek folder `/opt/n8n/backups/` ada 3 file
- [ ] Setup GitHub Private Repo `n8n-backups` + PAT + Clone ke VPS
- [ ] Setup rclone untuk Google Drive / S3 / B2 (opsional tapi recommended)
- [ ] Update script backup dengan config remote yang dipakai
- [ ] Setup Cron: `0 3 * * * /opt/n8n/scripts/backup.sh >> /opt/n8n/backups/backup.log 2>&1`
- [ ] Setup Cron Verifikasi: `0 4 * * *` cek file exists & size > 1KB
- [ ] Test Restore ke Local Docker / VPS Staging (Weekly Drill)
- [ ] Document: Recovery Procedure (step-by-step), Contact List, DNS Info
- [ ] Schedule Monthly DR Drill (Provision VPS $3 → Full Restore → Verify → Destroy)
FAQ: Backup & Restore Workflow n8n Bot WhatsApp AI
Apakah backup workflow JSON saja cukup (tanpa DB)?
TIDAK — Workflow JSON hanya isi workflow (nodes, connections). TIDAK include: Credentials (encrypted di DB), Executions History, Users, Settings, Variables, Binary Data. Restore hanya JSON = harus re-enter SEMUA credentials manual, kehilangan history debugging. Wajib backup PostgreSQL DB (pg_dump).
Bisakah backup ke Google Drive gratis (15GB) cukup?
YA — n8n backup harian ~10-50MB compressed. 30 hari = 300MB-1.5GB. 90 hari remote = 1-5GB. Muat di Google Drive 15GB gratis. Untuk enterprise: S3/B2 lebih scalable & cheap.
Bagaimana handle credentials saat restore (encrypted di DB)?
Credentials tersimpan encrypted di PostgreSQL. Restore DB full (pg_dump) → credentials otomatis restore (encrypted sama key). Jika HANYA restore workflow JSON (tanpa DB) → credentials reference hilang → harus re-enter manual di n8n UI. Solusi: Selalu restore DB full.
Berapa lama restore disaster recovery (VPS baru)?
15-30 menit: Provision VPS (5-10 menit) → Install Docker/Nginx (5 menit) → Restore DB (2-5 menit) → Restore Data (1-3 menit) → Start & Verify (5 menit). Total <30 menit. DNS switch tergantung TTL (biasanya 5-60 menit).
Template backup & disaster recovery lengkap sudah jadi di mana?
Ebook + Template n8n — include: Backup script otomatis (GitHub/Drive/S3/B2), Cron schedule, Restore procedure step-by-step, Disaster recovery drill checklist, Migration guide (VPS↔VPS, VPS↔Cloud), Verification checklist, Retention policy, DR drill schedule template, Cost calculator remote storage.
Baca juga: Backup & Restore Workflow n8n Bot WhatsApp AI: Panduan Lengkap untuk panduan lengkapnya.