The VPS dies. The disk fills up. An update wipes your workflows. A docker compose down -v runs one flag too far. In every one of these scenarios, the difference between "10 minutes of recovery" and "two weeks of rebuilding every workflow from memory" is a single question: did you actually back up n8n — all four layers of it?
A complete n8n backup needs four things: (1) the database (SQLite file or Postgres dump), (2) the .n8n folder (config, binary data, community nodes), (3) the N8N_ENCRYPTION_KEY — without it your credentials backup is encrypted junk — and (4) the n8n version you're running, so you can restore onto the same one.
Most guides tell you to copy one folder and call it done. Sections 3–6 give you the complete system — including a free nightly auto-backup workflow in section 6 — and section 9 walks you through a restore with all seven real-world traps — while section 7 ships the backup off-server and section 10 turns recovery into a written plan instead of a 2 AM panic.
On this page
- The 4 Layers of a Complete Backup
- Backup Strategy in 60 Seconds
- Method 1: CLI Export
- Method 2: SQLite Backup (Stop First!)
- Method 3: PostgreSQL pg_dump (Hot)
- Method 4: Free Auto-Backup Template
- Shipping Backups Off-Server
- Additional Methods: API & Git
- Restore: The 7 Real Traps
- Disaster Recovery Plan (RTO & RPO)
- Backup Tools Worth Knowing
- 7 Common Errors + Fixes
- Backup Checklist
- FAQ
- Sources & References
1. The 4 Layers of a Complete Backup
Every "how to back up n8n" guide covers layer 1. Almost none cover layers 2–4 — which is why so many restores fail. Here's what actually matters:
| Layer | What it holds | What breaks if you skip it |
|---|---|---|
| 1. Database | Workflows, executions, credentials, users, settings | Everything is gone — workflows, history, credentials |
| 2. .n8n folder | config file, binary data (filesystem mode), community nodes, custom extensions |
Files your workflows stored vanish; community nodes disappear; binary-mode files lost |
| 3. Encryption key | N8N_ENCRYPTION_KEY — generated on first launch, stored in ~/.n8n/config |
Credentials become unreadable garbage. The most common restore disaster |
| 4. Version pin | Which n8n image/version you're running | Restoring onto a newer version can fail or silently corrupt workflow schemas |
The encryption key deserves special attention. n8n encrypts every credential with it. The key itself lives in the config file inside ~/.n8n — so backing up the folder does capture it. But if you ever restore to a fresh server with a new key, your exported credentials are permanently unreadable. That's why every method below repeats the same rule: know your key, store it in a password manager, never let it change silently.
N8N_ENCRYPTION_KEY explicitly in your .env (as our Docker installation guide recommends), you already have it. If you never set it, n8n generated one and stored it in ~/.n8n/config — read the key from that file and store it in your password manager today (the template in section 6 deliberately keeps the key out of its archives).2. Backup Strategy in 60 Seconds
- Frequency: daily at minimum + immediately before every n8n update (updates are the #1 cause of "restore needed" moments).
- Retention: keep 7 daily backups; 1 monthly for 3 months.
- Location: backups on the same server as n8n are not backups. Copy them off-server — Google Drive, S3, another VPS, even GitHub.
- The 3-2-1 rule: three copies, on two different media, one off-site. For a solo automation stack, that realistically means: server copy + cloud copy + your laptop's monthly pull.
- Know your version: find it in the UI (Settings → About) or with
docker compose exec n8n n8n --version, and write it down next to the backups — a safe restore needs the same version (section 9, trap 2). - Test restores: "a backup you never restored is just a hopeful file." Section 10 lays out the full recovery plan.
| Backup method | Restores | Typical recovery time |
|---|---|---|
| CLI export (section 3) | Workflows + credentials | ~10 minutes |
| Database dump (sections 4–5) | + history, users, settings | ~20–30 minutes |
| Full restore (DB + .n8n folder) | + files, community nodes | ~30–45 minutes |
3. Method 1: CLI Export (Workflows + Credentials)
The n8n CLI exports every workflow and credential as JSON files. This is your portable, version-tolerant layer — it survives moving to a new server, a new database, even a slightly different n8n version:
# Export ALL workflows as JSON files
docker compose exec n8n n8n export:workflow --all --output=/home/node/.n8n/export
# Export ALL credentials (still encrypted with your key)
docker compose exec n8n n8n export:credentials --all --output=/home/node/.n8n/export
# Copy the export folder out of the container
docker compose cp n8n:/home/node/.n8n/export ./n8n-export
What it does NOT capture: execution history, users, settings, and (in filesystem binary mode) your stored files. For those, you need the database and folder backups below. Think of the CLI export as your fast-recovery layer and the full backup as your disaster-recovery layer.
4. Method 2: SQLite Backup (Stop First!)
SQLite is a single file: ~/.n8n/database.sqlite. Copying it while n8n is running risks a corrupted backup — SQLite can be mid-write at any moment. The safe options:
4.1 Stop, copy, start (30 seconds of downtime)
# 1. Stop n8n briefly
docker compose stop n8n
# 2. Copy the database file out of the volume
docker compose cp n8n:/home/node/.n8n/database.sqlite ./backup/database-$(date +%Y-%m-%d).sqlite
# 3. Start n8n again
docker compose start n8n
4.2 Zero-downtime: sqlite3 .backup
If the sqlite3 CLI is available in your container, use its online backup command — safe while n8n runs:
docker compose exec n8n sqlite3 /home/node/.n8n/database.sqlite ".backup /home/node/.n8n/database-backup.sqlite"
docker compose cp n8n:/home/node/.n8n/database-backup.sqlite ./backup/
5. Method 3: PostgreSQL pg_dump (Hot Backup, No Downtime)
PostgreSQL has a real advantage here: pg_dump produces a consistent snapshot while n8n keeps running. If you followed our Queue Mode guide, you're already on Postgres — this is your method:
# Hot backup — n8n keeps running, zero downtime
docker compose exec -T postgres pg_dump -U n8n n8n > ./backup/n8n-db-$(date +%Y-%m-%d).sql
# Keep the last 7 days
find ./backup -name 'n8n-db-*.sql' -mtime +7 -delete
Restore (into a fresh, empty database):
docker compose exec -T postgres psql -U n8n n8n < ./backup/n8n-db-2026-08-16.sql
rclone — that's a complete backup system in five lines, before we even touch the fancy template below.6. Method 4: The Free Auto-Backup Template
You run automation for a living — so automate your backups. This workflow runs nightly at 3 AM: exports workflows and credentials with the n8n CLI, packs them into a nightly archive (the encryption key itself stays out — it lives in your password manager, not in the archive), keeps a 7-day history, and confirms on Telegram. Deploy it once and backups stop being a thing you remember to do.
{
"name": "n8n Auto-Backup (Nightly)",
"nodes": [
{
"parameters": {
"rule": {
"interval": [
{
"field": "cronExpression",
"expression": "0 3 * * *"
}
]
}
},
"id": "schedule",
"name": "Daily 3:00 AM",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [250, 300]
},
{
"parameters": {
"command": "=mkdir -p /home/node/.n8n/backup/export && rm -rf /home/node/.n8n/backup/export/* && n8n export:workflow --all --output=/home/node/.n8n/backup/export && n8n export:credentials --all --output=/home/node/.n8n/backup/export && cd /home/node/.n8n/backup && tar -czf n8n-backup-{{ $now.format('yyyy-MM-dd') }}.tar.gz export && cp n8n-backup-{{ $now.format('yyyy-MM-dd') }}.tar.gz n8n-backup-latest.tar.gz && find /home/node/.n8n/backup -name 'n8n-backup-*.tar.gz' -mtime +7 -delete"
},
"id": "backup-cmd",
"name": "Export & Pack",
"type": "n8n-nodes-base.executeCommand",
"typeVersion": 1,
"position": [450, 300]
},
{
"parameters": {
"chatId": "YOUR_TELEGRAM_CHAT_ID",
"text": "=✅ n8n BACKUP COMPLETE\n\nDate: {{ $now.format('yyyy-MM-dd HH:mm') }}\nWorkflows + credentials packed.\n7-day history retained in the container.\n\n⚠️ Remember: also copy n8n-backup-latest.tar.gz off-server (Drive/S3)."
},
"id": "telegram",
"name": "Telegram Confirmation",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.2,
"position": [650, 300],
"credentials": {
"telegramApi": {
"id": "YOUR_TELEGRAM_CREDENTIAL_ID"
}
}
}
],
"connections": {
"Daily 3:00 AM": {
"main": [
[
{
"node": "Export & Pack",
"type": "main",
"index": 0
}
]
]
},
"Export & Pack": {
"main": [
[
{
"node": "Telegram Confirmation",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1",
"saveManualExecutions": true
}
}
- Where it runs: the Execute Command node executes inside the n8n container — that's why the commands are bare (
n8n export:workflow, nodocker execneeded). - The key stays OUT of the archive — deliberately. The nightly tar holds workflows and encrypted credentials, but never the key that decrypts them. Store
N8N_ENCRYPTION_KEYexactly once, in a password manager or secrets vault, separate from the backups. Lose the key and every archive becomes unreadable — keep it only where you keep your passwords. - Off-site copy: this template keeps backups inside the container — the honest truth is that a server fire takes them too. Add a Google Drive or S3 upload (Read Binary Files node on
n8n-backup-latest.tar.gz→ Drive Upload) to ship the archive off-server. More ready-to-import blueprints live in our Templates Library. - If this workflow fails silently — and one day it will — the Error Handling guide makes backup failures alert you. A backup system nobody monitors is a superstition.
- Ship it off-server: add a Read Binary Files node on
n8n-backup-latest.tar.gzfollowed by a Google Drive or S3 upload node — the full walkthrough is in section 7.2.
7. Shipping Backups Off-Server
Here's the uncomfortable truth: the auto-backup template in section 6 keeps archives inside the same server. If the server dies, the backups die with it. A backup is only a backup once it lives somewhere else.
7.1 The host route: rclone + cron (5 minutes)
Point the backup output at a folder on the host, then let rclone push it to Google Drive, S3, or any S3-compatible storage every night:
# In docker-compose.yml — mount a host folder as the backup output
volumes:
- ./n8n-backups:/home/node/.n8n/backup
# On the host: install rclone once, configure a remote
sudo apt install rclone
rclone config # name the remote 'offsite'
# crontab -e — push every night at 4 AM, keep a tidy log
0 4 * * * rclone sync /home/you/n8n-backups offsite:n8n-backups >> /var/log/n8n-backup.log 2>&1
7.2 The n8n-native route: Drive upload inside the template
No cron, no host access. Add two nodes to the section 6 template: a Read Binary Files node on /home/node/.n8n/backup/n8n-backup-latest.tar.gz, then a Google Drive → Upload node writing the same filename every night. The cloud file gets overwritten in place — one clean, always-current off-server copy.
7.3 Encrypt the cloud copy (rclone crypt)
Your archives hold workflows and encrypted credentials — sensitive enough that a cloud-account compromise would hurt. crypt makes any leaked archive useless to the attacker. The key itself stays in your password manager, never in the archive (section 6):
# Create an encrypted remote wrapping the plain one
rclone config create offsite-crypt crypt remote=offsite:n8n-backups
# Then sync through it — files land encrypted
0 4 * * * rclone sync /home/you/n8n-backups offsite-crypt: >> /var/log/n8n-backup.log 2>&1
One honest warning: the encryption password becomes another thing you must never lose. Store it next to N8N_ENCRYPTION_KEY in your password manager — lose both and the backups become mathematically unreachable.
8. Additional Backup Methods: API & Git
The CLI methods in sections 3–6 need shell access. Two alternatives cover the rest of the real world:
8.1 Back up via the public API (no shell needed)
n8n's REST API can export every workflow definition — the right choice on n8n Cloud, or on any server where you don't have (or don't want) shell access:
# 1. Create an API key: Settings → n8n API → Create API Key
# 2. Pull the workflow list, then save each workflow's JSON
IDS=$(curl -s -H "X-N8N-API-KEY: YOUR_API_KEY" https://n8n.yourdomain.com/api/v1/workflows | jq -r '.data[].id')
for id in $IDS; do
curl -s -H "X-N8N-API-KEY: YOUR_API_KEY" https://n8n.yourdomain.com/api/v1/workflows/$id -o "workflow-$id.json"
done
Credentials have their own endpoint (/api/v1/credentials) and follow the same encryption-key rules as everything else in this guide. And treat the API key like a root password — it can read and modify every workflow you own.
8.2 Version your backups with Git (GitHub / Gitea)
Committing the nightly export to a private Git repository adds something no archive can: a full change history. Deleted a workflow by accident at 9 AM? git log shows every version that ever existed:
cd /home/you/n8n-backups/export
git init
git add -A
git commit -m "backup $(date +%Y-%m-%d)"
git push origin main
9. Restore: The 7 Real Traps
Restoring is where backup guides go silent — and where people lose hours. Follow these seven rules and your restore is boring (which is exactly what you want):
Same encryption key — or your credentials are dead on arrival
On the new instance, set N8N_ENCRYPTION_KEY to the old instance's key before it starts for the first time. If n8n already generated a different key, fix the key and re-import the credentials.
Restore onto the same (pinned) version, then upgrade
Restore onto the exact image version you backed up. A backup from n8n 1.90 restored onto 1.120 may fail or silently break workflow schemas. After a successful restore, upgrade intentionally — see our Queue Mode guide for zero-downtime updates.
Stop before touching the database
Never restore a SQLite file or pg_dump into a running instance. Stop n8n (or use a fresh database), restore, then start.
Re-activate workflows and re-connect OAuth
Imported workflows arrive deactivated — turn each one on. OAuth credentials (Google, LinkedIn) usually need one fresh authorization click after restore; token state doesn't survive intact.
Names collide — imports overwrite
Importing a workflow or credential with the same name as an existing one overwrites it. Restore into a fresh instance, or rename your live copies before importing.
New server, new domain? Update WEBHOOK_URL before anything else
Restoring onto a different machine almost always means a different domain or IP. Set WEBHOOK_URL (and N8N_HOST if you use it) to the new address before the instance starts — otherwise every webhook workflow still points at the old server, and providers like Stripe or Telegram keep knocking on a dead door.
Match the binary data mode — or restored files won't load
If your old instance ran N8N_DEFAULT_BINARY_DATA_MODE=filesystem, its files live in the binaryData folder, not the database. A new instance with the default mode looks for them in the wrong place. Restore the folder and set the same mode before starting — our Out of Memory guide covers the variable in depth.
10. Disaster Recovery Plan: RTO, RPO & Failure Scenarios
Backup is the boring half. Recovery is where time and money get lost. A recovery plan is just two numbers and a short table — write them down once, and every future incident becomes a checklist instead of a panic.
10.1 The two numbers: RTO & RPO
- RTO — Recovery Time Objective: how fast you must be back online. An RTO of 30 minutes means your restore must be automated (prebuilt compose file + scripted import) — not improvised at 2 AM.
- RPO — Recovery Point Objective: how much data you can afford to lose. An RPO of 24 hours means daily backups are enough; an RPO of 1 hour means hourly database dumps.
Realistic numbers for a solo automation stack: RTO 60 minutes, RPO 24 hours. That combination is achievable with exactly what this guide already gives you — a nightly backup plus a documented restore path. Anything tighter and you're building infrastructure, not running a blog of automations.
10.2 Failure scenarios & the right response
| Scenario | What you lose | Restore path | Realistic RTO |
|---|---|---|---|
| Server dies (hardware / provider) | Everything | Rebuild stack from compose + restore DB & .n8n folder (sections 6 & 9) | 30–60 min |
| Database corruption | Workflows, history, users | pg_dump restore or SQLite file replace (sections 4–5) | 15–30 min |
| Human error (deleted or broken workflow) | One workflow | CLI/API import or Git history (sections 3 & 8) | 5–10 min |
| Compromised instance | Your trust | Rebuild on a new server; rotate API keys & OAuth tokens; restore workflows only, then review every credential | Hours — do it right |
Note on the last row: never restore over a compromised instance. If someone had access, assume every credential inside is burned — restore the workflow structure, rotate the secrets, and only then bring the automation back to life.
10.3 The staging ritual
Once a month, restore last night's backup onto a throwaway staging instance and confirm three things: workflows open, credentials connect, and one test execution runs. The night described in section 9 went smoothly because we'd rehearsed it — the day you skip the drill is the day you'll need it.
11. Backup Tools Worth Knowing
Four tools that earn their place — all verified, none magical. A tool moves bytes; it doesn't replace the four-layer strategy from section 1:
| Tool | What it does | Best for |
|---|---|---|
| n8n CLI (built into n8n) | Export/import workflows & credentials | The portable layer — sections 3 & 6. There is no separate "n8n-cli" tool to install; it ships with n8n itself. |
| restic | Encrypted, incremental file backups to S3/any backend | Backing up the host folder that holds your archives |
| rclone (+ crypt) | Syncs folders to Drive/S3/OneDrive, optionally encrypted | Off-server shipping — section 7 |
| n8n Backup Manager (open source) | Web UI with scheduling, retention, S3/Drive/OneDrive sync, AES-256 encryption, one-click restore | People who prefer a dashboard over cron |
# restic in one breath: init once, then back up the host folder
restic -r s3:https://s3.amazonaws.com/your-bucket init
restic -r s3:https://s3.amazonaws.com/your-bucket backup /home/you/n8n-backups
n8n Backup Manager on GitHub is a standalone open-source companion app with a clean web UI — useful if you'd rather click "Restore" than type psql at 2 AM. And the official workflow & credential restoration template on n8n.io restores from a backup folder on demand.
12. The 7 Most Common Errors & Fixes
| # | Error / Symptom | Cause | Fix |
|---|---|---|---|
| 1 | Credentials import but every workflow fails with a decryption error | Encryption key differs between old and new instance | Set the old N8N_ENCRYPTION_KEY before the new instance starts, then re-import (section 9, trap 1) |
| 2 | Webhooks return 404 after restoring workflows | Imported workflows arrive deactivated | Re-activate each workflow (section 9, trap 4) |
| 3 | Restored SQLite file won't open, or n8n crashes with "database disk image is malformed" | The file was copied while n8n was writing | Stop n8n before copying, or use sqlite3 .backup (section 4) |
| 4 | pg_dump: command not found on the host |
The dump tool lives in the Postgres container, not the host | Run it through Docker: docker compose exec -T postgres pg_dump ... (section 5) |
| 5 | Files stored by workflows are missing after restore | Binary data lived in the .n8n/binaryData folder, which wasn't backed up |
Back up the full .n8n folder, not just the database (section 1, layer 2) — and set the same N8N_DEFAULT_BINARY_DATA_MODE on restore (section 9, trap 7) |
| 6 | Community nodes missing on the restored instance | Installed nodes live in the .n8n folder on the original server |
Restore the folder, or reinstall the community nodes on the new instance |
| 7 | The backup disk fills up until the VPS dies | No retention policy — archives accumulate forever | find ... -mtime +7 -delete in the cron job or the template (section 6) |
13. Backup Checklist
- ✅
N8N_ENCRYPTION_KEYknown, explicit, and stored in a password manager - ✅ n8n image version pinned (not
latest) - ✅ Daily automated backup (cron + the template from section 6)
- ✅ Database layer covered (SQLite stop-first or Postgres pg_dump)
- ✅
.n8nfolder covered (config, binaryData, community nodes) - ✅ Retention policy: 7 days minimum
- ✅ Off-server copy (Google Drive / S3 / rclone to another VPS)
- ✅ Backup failures alert you (Error Trigger workflow)
- ✅ Monthly test restore to a staging instance
14. Frequently Asked Questions
Four things: the database (SQLite file or Postgres dump), the .n8n folder (config, binary data, community nodes), the encryption key, and the n8n version you're running. Missing any one of them makes the restore incomplete — section 1 breaks each layer down.
No. Credentials are exported encrypted with your N8N_ENCRYPTION_KEY, but the key itself is not included. n8n generates the key on first launch and stores it in /home/node/.n8n/config. Without the same key on restore, credentials cannot be decrypted.
It's risky. Copying a live SQLite file can produce a corrupted backup. Stop n8n before copying, or use the sqlite3 .backup command. PostgreSQL doesn't have this problem — pg_dump supports hot backups (section 5).
Use pg_dump: docker compose exec -T postgres pg_dump -U n8n n8n > backup.sql. Postgres supports hot backups, so n8n keeps running. Restore with psql -U n8n n8n < backup.sql into a fresh database.
Daily at minimum, plus immediately before every n8n update. Keep 7 days of retention, store backups off-server, and follow the 3-2-1 rule: three copies, two media, one off-site.
RTO (Recovery Time Objective) is how quickly you must be back online after a failure — e.g., 30 minutes, which means your restore must be automated. RPO (Recovery Point Objective) is how much data you can afford to lose — e.g., 24 hours, which dictates your backup frequency. Section 10 explains how to pick both.
Because the encryption key on the new instance differs from the key that encrypted the credentials. Set N8N_ENCRYPTION_KEY to the old instance's key before the new instance starts, then import the credentials (section 9, trap 1).
Yes. Imported workflows come in deactivated. Turn each one on after import, and re-authorize OAuth credentials (Google, LinkedIn) with a fresh click — OAuth tokens do not survive a restore intact.
Restore them to a staging instance at least once before you need them. A backup you have never restored is just a hopeful file. Run the restore drill monthly, then delete the staging instance.
Two ways: in the UI, open Settings → About — or from the shell, docker compose exec n8n n8n --version. Write the version down next to your backups; a safe restore needs the same version (section 9, trap 2).
n8n Cloud manages the database and infrastructure for you, so you skip the database layers. Still export workflows and credentials weekly with the CLI (section 3) — they're your portable copy and your freedom to self-host later. OAuth re-authorization after import applies on Cloud too.
Sources & References
- n8n Documentation — CLI commands (export/import)
- n8n Documentation — Deployment environment variables (encryption key)
- n8n Documentation — Binary data environment variables
- PostgreSQL Documentation — pg_dump
- SQLite Documentation — Online Backup API (.backup command)
