Limited Time Offer

20% OFF

On All Shared RDP Plans

Use the code below at checkout and save instantly on any Shared plan.

NEWRDP20
Claim Your Discount

*Valid on Shared Plans only. Limited time offer.

Loader

How to Back Up and Restore n8n: Workflows, Credentials and Database

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.

  • Database + encryption key
  • Workflow and credential export
  • Automate it and test the restore
How to Back Up and Restore n8n: Workflows, Credentials and Database
  • 22 October 2026
  • by Admin

How to Back Up and Restore n8n: Workflows, Credentials and Database

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.

What an n8n backup must contain

  • The database. Workflows, credentials (encrypted), tags and execution data live here. For Postgres, use pg_dump.
  • The encryption key. Credentials in the database are encrypted with N8N_ENCRYPTION_KEY. Without the same key, a restored database cannot decrypt them.
  • The n8n data folder. The .n8n directory (the n8n_data volume) holds the config and any local files.
  • Your configuration. Keep your docker-compose.yml and .env in a private repository or encrypted storage.

Method 1: dump the Postgres database

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

Method 2: export workflows and credentials with the n8n CLI

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.

Restoring

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

Automate it with cron

#!/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.

Test your restore

  • Spin up a second, empty n8n instance (a cheap VPS or a local Docker setup is fine).
  • Restore last night's backup and set the same encryption key.
  • Open a few workflows and run a test execution. Confirm credentials work.
  • Write down how long it took. That is your real recovery time.

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 Plans

Frequently asked questions

  • How often should I back up n8n?
    Daily is a good baseline. If your workflows change constantly or handle critical data, back up more often.
  • What happens if I lose the encryption key?
    The database can still be restored, but stored credentials cannot be decrypted and must be re-created by hand.
  • Can I back up while n8n is running?
    Yes. A pg_dump is consistent while the database is live.