If you self-host n8n, your workflows represent hours of design, testing, and debugging — and they can vanish in seconds with a bad update, a corrupted database, or a dead VPS. Learning how to backup n8n workflows automatically is one of the highest-value habits for any self-hoster. In this guide, you'll learn the manual export method, the official CLI commands, and a simple cron-based script that backs up your workflows and credentials every night without you lifting a finger.
Why You Need to Backup n8n Workflows
n8n stores everything — workflows, credentials, executions — in a database (SQLite by default, PostgreSQL for production setups). A single failed Docker upgrade, a full disk, or an accidental container deletion can wipe it all. Unlike SaaS tools, self-hosted n8n has no built-in cloud backup, so backing up n8n workflows is entirely your responsibility. Automated backups also give you version history: when a “quick fix” breaks a production workflow at 2 AM, you can roll back to last night's export in minutes instead of rebuilding from memory.
Method 1: Manual Export from the n8n UI
The simplest way to backup n8n workflows is through the interface. Open a workflow, click the three-dot menu in the top right, and choose Export to download a JSON file. You can also bulk-export: go to the Workflows overview, select multiple workflows, and export them together. This is fine for occasional snapshots, but it's manual, easy to forget, and doesn't include credentials — so use it only as a stopgap.
Method 2: Backup n8n Workflows with the CLI
n8n ships with a powerful CLI that exports everything to JSON files. Inside your n8n container or installation directory, run:
# Export all workflows to a directory
n8n export:workflow --all --output=/backups/n8n/workflows/
# Export all credentials (encrypted)
n8n export:credentials --all --output=/backups/n8n/credentials/
Each workflow becomes its own JSON file, named by ID — perfect for version control with Git. If you run n8n in Docker, execute the CLI inside the container:
docker exec -u node -it n8n n8n export:workflow --all --output=/home/node/backups/
Note that exported credentials are still encrypted with your n8n encryption key. Without that key, credential exports are useless — we'll cover how to protect it below.
Method 3: Fully Automated Backups with Cron
The reliable way to backup n8n workflows is a nightly script run by cron. Create a backup script like this on your server:
#!/bin/bash
BACKUP_DIR="/root/n8n-backups/$(date +%Y-%m-%d)"
mkdir -p "$BACKUP_DIR"
# Export workflows and credentials
docker exec n8n n8n export:workflow --all --output=/home/node/backups/
docker exec n8n n8n export:credentials --all --output=/home/node/backups/
# Copy out of the container and compress
docker cp n8n:/home/node/backups "$BACKUP_DIR/"
tar -czf "/root/n8n-backups/n8n-$(date +%Y-%m-%d).tar.gz" -C "$BACKUP_DIR" .
# Keep only the last 14 days
find /root/n8n-backups -name "n8n-*.tar.gz" -mtime +14 -delete
Then schedule it with crontab -e:
0 2 * * * /root/backup-n8n.sh >> /var/log/n8n-backup.log 2>&1
This runs every night at 2 AM, compresses the exports, and rotates old archives. A $5–10/month VPS is plenty for n8n plus backups — budget-friendly providers like RackNerd are a popular pick for self-hosting n8n without overspending.
Don't Forget the Encryption Key and Credentials
A workflow-only backup is half a backup. n8n encrypts credentials using an encryption key defined in the N8N_ENCRYPTION_KEY environment variable (or auto-generated and stored in ~/.n8n/config). If you lose this key, your restored credentials can't be decrypted, and every API key, OAuth token, and database password has to be re-entered by hand. Add these to your backup routine:
- Set an explicit
N8N_ENCRYPTION_KEYin your Docker Compose or systemd file — don't rely on the auto-generated one. - Store the key in a password manager, separate from the backups themselves.
- Include the exported
credentialsJSON files in your nightly archive. - Periodically test a restore on a staging instance to confirm the key works.
Restoring Workflows from a Backup
To restore, import the exported JSON files with the CLI:
n8n import:workflow --input=/backups/n8n/workflows/
n8n import:credentials --input=/backups/n8n/credentials/
Restart n8n after importing so it picks up the changes. Workflows import as inactive by default — review them, fix any environment-specific values (webhook URLs, file paths), then activate. If your whole server died, the fastest path is: spin up a fresh VPS, restore the Docker Compose setup, set the same N8N_ENCRYPTION_KEY, import workflows and credentials, and you're back online.
Store Backups Off-Site (Don't Skip This)
Backups that live on the same server as n8n aren't backups — they're copies. A disk failure or a terminated VPS takes them with it. Use rclone to push your nightly archives to cheap object storage like Backblaze B2 or S3:
rclone copy /root/n8n-backups/n8n-$(date +%Y-%m-%d).tar.gz remote:n8n-backups/
Append this line to your backup script after the tar step. With rclone's encryption remote, you can even encrypt archives before upload for an extra layer of safety. Test the download-and-restore path at least once a quarter — an untested backup is just a hope.
Key Takeaways
- Self-hosted n8n has no built-in backup — automating your n8n workflow backups is your job.
- Use
n8n export:workflow --allandn8n export:credentials --allfor complete, version-controllable JSON exports. - Schedule a nightly cron script that exports, compresses, and rotates backups (keep 14–30 days).
- Always back up your
N8N_ENCRYPTION_KEYseparately — without it, credential exports can't be restored. - Push archives off-site with rclone to S3/B2 so a server failure can't take your backups with it.
- Test your restore process regularly on a staging instance before you actually need it.
Related Guides
- Best VPS Providers for Self-Hosting — pick an affordable, reliable server to run n8n on.
- How to Install PowerMTA on Ubuntu 24 — pair your n8n automation with your own email delivery server.
