n8n backup and restore that actually works

There are only two things you must back up in n8n — the database and the encryption key — and almost everyone forgets the second. Here is how to capture both, automate it, and prove the restore works before you are relying on it at 2 a.m.

Disclosure: contains an affiliate link to Inferno VPS.

What a backup must contain

That is it. You do not need to back up the n8n container or the software; those are reinstalled from the Compose file. The value is entirely in the database and the key.

The encryption key — save it first

It is in your .env and inside the data volume at ~/n8n/n8n-data/config:

docker compose exec n8n cat /home/node/.n8n/config | grep encryptionKey

Copy that value into your password manager now. Everything else in this guide is worthless without it.

Manual database backup

cd ~/n8n
docker compose exec -T db pg_dump -U n8n n8n | gzip > n8n-$(date +%F).sql.gz
ls -lh n8n-*.sql.gz

pg_dump produces a consistent logical dump even while n8n is running — no downtime needed. Gzip keeps it small; a typical personal instance dumps to a few megabytes.

Automated nightly backups

Create a script:

mkdir -p ~/backups
nano ~/n8n-backup.sh
#!/usr/bin/env bash
set -euo pipefail
cd /home/youruser/n8n
STAMP=$(date +%F)
OUT=/home/youruser/backups/n8n-$STAMP.sql.gz
docker compose exec -T db pg_dump -U n8n n8n | gzip > "$OUT"
# keep 14 days
find /home/youruser/backups -name 'n8n-*.sql.gz' -mtime +14 -delete
echo "backup ok: $OUT"
chmod +x ~/n8n-backup.sh
crontab -e
# run at 03:30 every night:
30 3 * * * /home/youruser/n8n-backup.sh >> /home/youruser/backups/backup.log 2>&1

For real safety, copy the dumps off the server too — rclone to object storage or a scp pull from another machine. A backup that lives only on the server it protects is not a backup.

Restoring on a fresh server

  1. Recreate the stack from your Compose file, putting the same N8N_ENCRYPTION_KEY in .env.
  2. Start only the database, then load the dump:
docker compose up -d db
sleep 10
gunzip -c n8n-2026-05-20.sql.gz | docker compose exec -T db psql -U n8n -d n8n
docker compose up -d n8n

Open the UI, check a workflow, and open a stored credential — if it decrypts, the key matched and the restore is good.

Test the restore before you trust it

The only backup that counts is one you have restored. Once a quarter, load your latest dump into a throwaway local Postgres or a scratch VPS and confirm it imports without errors. Teams discover broken backups during a real outage precisely because they never rehearsed.

Keep backups off-box

Run your automations on one Inferno VPS and push nightly dumps to another region for geographic redundancy. Eight EU + Asia locations, snapshots available, from $3.49/mo.

View Inferno plans →

What to do next


Author: Daniel Ferro — Self-hosting writer, Lisbon. Last tested: 2026-05-18 on n8n 1.62, Postgres 16, Ubuntu 22.04.