A backup you have never restored is only a hope. Here is what an n8n backup must contain, how to automate it and how to test the restore.
n8n holds your workflows, your credentials and your execution history. Lose the server without a good backup and you lose all of it. This guide covers what to back up, how to automate it, and how to confirm that you can really restore it.
pg_dump.N8N_ENCRYPTION_KEY. Without the same key, a restored database cannot decrypt them..n8n directory (the n8n_data volume) holds the config and any local files.docker-compose.yml and .env in a private repository or encrypted storage.This assumes the Docker Compose setup from our self-hosting guide.
cd ~/n8n
docker compose exec -T postgres pg_dump -U n8n n8n | gzip > ~/backups/n8n-db-$(date +%F).sql.gz
The CLI gives you portable JSON files that are easy to inspect and import into another instance.
docker compose exec n8n n8n export:workflow --all --output=/home/node/.n8n/backups/workflows.json
docker compose exec n8n n8n export:credentials --all --output=/home/node/.n8n/backups/credentials.json
Credentials are exported in encrypted form by default. There is an option to export them decrypted, but that writes your secrets in plain text, so avoid it unless you have a strong reason and protect the file carefully.
To restore a database dump into a fresh Postgres container:
gunzip -c ~/backups/n8n-db-2026-10-22.sql.gz | docker compose exec -T postgres psql -U n8n n8n
To import exported files into a clean n8n instance that uses the same encryption key:
docker compose exec n8n n8n import:credentials --input=/home/node/.n8n/backups/credentials.json
docker compose exec n8n n8n import:workflow --input=/home/node/.n8n/backups/workflows.json
#!/bin/bash
set -e
cd ~/n8n
mkdir -p ~/backups
docker compose exec -T postgres pg_dump -U n8n n8n | gzip > ~/backups/n8n-db-$(date +%F).sql.gz
find ~/backups -name 'n8n-db-*.sql.gz' -mtime +14 -delete
# crontab -e (daily at 02:30)
30 2 * * * /home/youruser/n8n-backup.sh
Then copy the backups off the server, for example to object storage or another machine. A backup that sits on the same disk as the database does not survive a disk failure.
Do this once a quarter at minimum. Most backup failures are discovered during the first restore attempt, and that should not be during an outage.
Prefer not to maintain backup scripts? Every managed n8n hosting plan includes daily backups and a team that tests them.
See Managed n8n Hosting Planspg_dump is consistent while the database is live.