Your VPS already has daily server backups; this guide covers your own application backups, which you can restore separately or take to another server. n8n does not make automatic backups by itself: you need to schedule them yourself. Here is what to keep and the commands to do it. They all run on your VPS over SSH as root.
What to keep
- The database: workflows, credentials, users and execution history.
- The encryption key
N8N_ENCRYPTION_KEY, in/opt/n8n/.env. Without it, the credentials in the backup cannot be read. - The files you use in your workflows, in
/opt/n8n/local-files(inside n8n,/files).
Database backup
mkdir -p /opt/n8n/backups
cd /opt/n8n && docker compose exec -T postgres sh -c 'pg_dump -U "$POSTGRES_USER" "$POSTGRES_DB"' | gzip > backups/n8n-$(date +%F).sql.gz
You get one file per day in /opt/n8n/backups/. The astrol-n8n-update command also makes a backup like this before every update.
Export workflows and credentials
Besides the database, you can export workflows and credentials to JSON files, which are handy to move them to another installation:
cd /opt/n8n
docker compose exec n8n n8n export:workflow --backup --output=/files/backup/workflows/
docker compose exec n8n n8n export:credentials --backup --output=/files/backup/credentials/
The files end up in /opt/n8n/local-files/backup/. Credentials are exported encrypted with your key.
Schedule a daily backup
Open the task scheduler with crontab -e and add these two lines. The first backs up the database every day at 04:00; the second deletes backups older than 7 days so the disk does not fill up:
0 4 * * * cd /opt/n8n && docker compose exec -T postgres sh -c 'pg_dump -U "$POSTGRES_USER" "$POSTGRES_DB"' | gzip > /opt/n8n/backups/n8n-$(date +\%F).sql.gz
30 4 * * * find /opt/n8n/backups -name 'n8n-*.sql.gz' -mtime +7 -delete
Keep backups off the VPS
A backup that only lives on the server itself does not protect you if you reinstall it or lose it. Download them to your computer, for example with:
scp root@YOUR_IP:/opt/n8n/backups/*.sql.gz .
Or with an SFTP client (FileZilla, WinSCP) logging in as root.
Restore workflows and credentials
To import what you exported into an n8n instance:
cd /opt/n8n
docker compose exec n8n n8n import:workflow --separate --input=/files/backup/workflows/
docker compose exec n8n n8n import:credentials --separate --input=/files/backup/credentials/
Important: encrypted credentials can only be imported into an n8n with the same N8N_ENCRYPTION_KEY. If you are moving them to a new installation, export with --decrypted instead of --backup: they are saved in plain text, so delete them as soon as you have imported them.
To restore the full database, open a ticket and we will guide you step by step: it is an operation best done calmly.
Related
- Reinstall or change the application on your VPS
- How to update n8n on your VPS
- Getting started with your n8n VPS
Order: n8n VPS in Frankfurt · in Miami
Was this article helpful?
Need more help?
Open a ticket and the support team goes through it with you.