In short
Updating n8n in Docker takes two steps: back up first, then pull the new image. Back up the PostgreSQL database with pg_dump, export workflows with n8n export:workflow, and save your N8N_ENCRYPTION_KEY; then run docker compose pull and docker compose up -d to start the new version. Shipping those backups every night to off-server cloud storage with rclone means you can recover even if you lose the server.
In this guide
- What Should an n8n Backup Include?
- Step 1: Find the Install Directory and Services
- Step 2: Back Up the PostgreSQL Database
- Step 3: Export Workflows and Credentials
- Step 4: Update n8n with Docker
- If Something Goes Wrong: Rolling Back
- Send Backups to the Cloud Automatically
- Quick Pre-Update Checklist
- Next Step: n8n Infrastructure That's Easy to Update
If you run n8n in Docker, updating it takes a few minutes: you pull the new image and recreate the container. The real risk is not the update itself but updating without a backup. If a database migration fails halfway or the encryption key gets lost, every workflow and saved API connection goes with it. In this guide you will take a complete backup first, then upgrade n8n safely, and finally set up a routine that sends your backups to the cloud automatically every night.
What Should an n8n Backup Include?
In a Docker-based n8n setup running on PostgreSQL, your data lives in three places. If you don't back up all three, a restore will be incomplete.
- PostgreSQL database: Workflows, credentials (encrypted), execution history, users and tags are stored here. This is your primary backup.
- n8n data directory (
/home/node/.n8n): This directory inside the container is usually mounted to a Docker volume. It contains theconfigfile and the encryption key. - Encryption key (
N8N_ENCRYPTION_KEY): Credentials are encrypted with this key. Even with a database backup, no API connection can be decrypted without the key, and you would have to re-enter all of them.
Also keep a copy of the docker-compose.yml and .env files from your install directory. If you ever have to rebuild the server from scratch, they let you bring up an identical environment.
Golden rule: save your N8N_ENCRYPTION_KEY value in a password manager right now. Everything else can be recreated; this key cannot.
Step 1: Find the Install Directory and Services
First connect to the server over SSH (on Windows, running ssh root@SUNUCU_IP from PowerShell is enough; replace the placeholder with your server's IP). Then check which Compose project is running and where its files are:
docker compose ls
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
The CONFIG FILES column in the output shows the path of the Compose file. This guide uses /opt/n8n as the example directory and n8n and postgres as the service names; swap in your own. Write down the current version, because you will need it if you have to roll back:
cd /opt/n8n
docker compose exec n8n n8n --version
Step 2: Back Up the PostgreSQL Database
pg_dump is the most reliable way to back up the database. It takes a consistent dump while the container is running, so you don't need to stop n8n:
mkdir -p /opt/n8n-backup
docker compose exec -T postgres pg_dump -U n8n -d n8n | gzip > /opt/n8n-backup/db-$(date +%F).sql.gz
Confirm the user and database names against the POSTGRES_USER and POSTGRES_DB values in your .env file. Run ls -lh /opt/n8n-backup to make sure the file isn't empty; if it's only a few hundred bytes, the dump failed.
Step 3: Export Workflows and Credentials
The database backup is for full restores. Exporting workflows as JSON is also very handy for restoring a single workflow, moving it to another n8n instance, or tracking versions in Git. n8n's own CLI commands are built for this:
docker compose exec -T n8n n8n export:workflow --backup --output=/home/node/.n8n/backup/workflows/
docker compose exec -T n8n n8n export:credentials --backup --output=/home/node/.n8n/backup/credentials/
The --backup flag writes each workflow to its own file in a readable format. Credentials exported this way stay encrypted and can only be read by an n8n instance with the same encryption key. You can export them in plain text with the --decrypted flag, but that file contains all your API keys in clear text; avoid it unless you truly need it.
Copy the files from the container to the server:
docker compose cp n8n:/home/node/.n8n/backup /opt/n8n-backup/export-$(date +%F)
cp /opt/n8n/docker-compose.yml /opt/n8n/.env /opt/n8n-backup/
Step 4: Update n8n with Docker
Once your backups are in place, the update itself is short. Read the release notes first: major n8n versions can change certain nodes, environment variables or default behavior. Check the official release notes for any breaking changes affecting the nodes you use.
Pinning the version
If your Compose file uses the latest tag, every pull moves you to whatever the newest version is at that moment. For controlled updates, it's safer to specify an exact version:
services:
n8n:
image: docker.n8n.io/n8nio/n8n:1.x.y # put your target version here
That way you always know which version you're on, and if something breaks you roll back by setting the tag to the old value.
Update commands
- If you changed the tag, save the file.
- Pull the new image:
docker compose pull n8n - Recreate the container with the new image:
docker compose up -d n8n - Watch the startup logs:
docker compose logs -f n8n. Database migrations run at this stage; don't stop the container until you see a line like "Editor is now accessible". - Verify the version:
docker compose exec n8n n8n --version - Clean up unused old images:
docker image prune -f
After the update, run a few of your most critical workflows manually and confirm that webhooks and scheduled triggers are still active.
If Something Goes Wrong: Rolling Back
Because migrations change the database schema, simply setting the image tag back to the old version isn't always enough. Here is how to roll back safely:
- Stop n8n:
docker compose stop n8n - Drop the database and restore the backup:
docker compose exec -T postgres psql -U n8n -d postgres -c "DROP DATABASE n8n;" docker compose exec -T postgres psql -U n8n -d postgres -c "CREATE DATABASE n8n;" gunzip -c /opt/n8n-backup/db-TARIH.sql.gz | docker compose exec -T postgres psql -U n8n -d n8n - Set the image tag in the Compose file back to the old version you noted, then run
docker compose up -d n8n.
To restore just one workflow, you don't need to touch the database: the n8n import:workflow --input=dosya.json command is enough.
Send Backups to the Cloud Automatically
A backup stored on the same server is useless if you lose that server. That's the core of the 3-2-1 backup rule: at least one copy should be physically somewhere else. Sunucu Atlas AtlasDrive cloud storage plans offer SFTP and WebDAV access and work with rclone, so you can use them directly to ship n8n backups automatically.
1. Set up an rclone remote
apt install -y rclone
rclone config
In the wizard, press n to create a new remote, name it atlasdrive, choose sftp as the type, and enter the server address, username and password from your AtlasDrive panel. For detailed settings, see the guide to sending backups to the cloud with rclone.
2. Write the backup script
Create the file /opt/n8n-backup.sh:
#!/bin/bash
set -euo pipefail
cd /opt/n8n
D=$(date +%F)
B=/opt/n8n-backup/$D
mkdir -p "$B"
docker compose exec -T postgres pg_dump -U n8n -d n8n | gzip > "$B/db.sql.gz"
docker compose exec -T n8n rm -rf /home/node/.n8n/backup
docker compose exec -T n8n n8n export:workflow --backup --output=/home/node/.n8n/backup/workflows/
docker compose exec -T n8n n8n export:credentials --backup --output=/home/node/.n8n/backup/credentials/
docker compose cp n8n:/home/node/.n8n/backup "$B/export"
cp docker-compose.yml .env "$B/"
rclone copy /opt/n8n-backup atlasdrive:n8n-yedek
find /opt/n8n-backup -mindepth 1 -maxdepth 1 -type d -mtime +7 -exec rm -rf {} +
The script keeps the last 7 days locally and leaves the cloud copies alone. Make it executable and run it once by hand:
chmod 700 /opt/n8n-backup.sh
/opt/n8n-backup.sh
rclone ls atlasdrive:n8n-yedek | tail
3. Run it nightly with cron
crontab -e
# n8n backup every night at 03:30
30 3 * * * /opt/n8n-backup.sh >> /var/log/n8n-backup.log 2>&1
Because the .env file contains the encryption key and the database password, only root should be able to read the backup folder; on the cloud side, keep two-factor authentication enabled on your account as well.
Quick Pre-Update Checklist
- Is
N8N_ENCRYPTION_KEYsaved somewhere safe, off the server? - Does today's
pg_dumpfile exist, and is its size reasonable? - Have the workflow exports been taken?
- Did you write down the current version number?
- Do the release notes mention changes to nodes you use?
- Is there enough disk space for the new image? (
df -h)
Follow this list on every update and upgrading n8n stops being a nerve-racking operation and becomes routine maintenance.
Next Step: n8n Infrastructure That's Easy to Update
For this setup to run smoothly, n8n needs to run with Docker and PostgreSQL on a server with root access. Sunucu Atlas n8n server plans come in exactly that configuration: n8n preinstalled with Docker, a PostgreSQL database and automatic SSL certificate already set up, on NVMe storage in Istanbul. For a small number of workflows, SA-N8N-1 is enough to get started; teams with growing execution history and many concurrent workflows get more RAM and disk headroom with SA-N8N-2. To keep backups off the server, adding an AtlasDrive 50 GB plan is, in most cases, more than enough to start with for your n8n data. If you're new to n8n, the what is n8n guide explains the basics.
Frequently asked questions
Will updating n8n delete my workflows?
In a Docker setup, workflows are stored in the PostgreSQL database and a persistent volume, so updating the image does not delete them. Still, take a pg_dump database backup before updating in case a migration fails.
What happens if I lose N8N_ENCRYPTION_KEY?
Your workflows come back, but saved credentials can't be decrypted, so you have to re-enter every API key and connection. That's why you should store the key off the server, in a password manager.
Should I run n8n with the latest tag or a specific version?
In production, a specific version tag is safer. You decide when updates happen, and rolling back to the old tag is easy if something breaks.
How do I restore a single workflow from a backup?
Copy the exported JSON file into the container and run n8n import:workflow --input=dosya.json. You can also import the file from the n8n editor using the Import from File option.
How often should I back up n8n?
If your workflows change often, a daily backup is a sensible starting point. Also take an extra manual backup right before every version update.