Move Docker n8n to a New Server Without Losing Credentials

Disclosure: This guide contains an affiliate link to DigitalOcean. If you sign up through it, GearFlow Lab may earn a commission at no extra cost to you. Read our FTC & editorial disclosure.

19 min readBy Yun Sanghun (M. Yun)

If you move a Dockerized n8n instance to a new server and only copy the workflow JSON files (or copy the SQLite database without the matching encryption key) every saved credential breaks. OAuth tokens, API keys, and webhook secrets fail to decrypt because n8n encrypts them with a 32-character key stored inside the container's data volume at /home/node/.n8n/config.

Before touching your new server, run these three commands in your old n8n folder to stop the container cleanly, print your encryption key, and archive the entire volume into a single .tar.gz file:

# 1. Stop n8n first so SQLite database files are not changing while tar reads them
docker compose stop

# 2. Print the encryption key - copy the 32-character string into a password manager
docker run --rm -v n8n_data:/data:ro alpine:3.20 cat /data/config

# 3. Archive the entire volume (database.sqlite + config) into the current folder
docker run --rm -v n8n_data:/data:ro -v "$(pwd)":/backup alpine:3.20 \
  tar -czf /backup/n8n_data_export.tar.gz -C /data .

Replace n8n_data with the actual volume name from docker volume ls (Docker Compose often prefixes it with your folder name, such as n8n_n8n_data).

Tested on: Windows 11 Pro 23H2 (WSL 2 Linux Kernel 6.6.87.2-microsoft-standard-WSL2) | Official Docker Engine 27.3.1, build ce12230 (desktop-linux) | n8nio/n8n:1.76.1 (SQLite & PostgreSQL 16.6) | caddy:2.8.4-alpine | alpine:3.20 | Execution Date: 2025-01-23.

Why Move n8n Off a Laptop

Stopping n8nio/n8n:1.76.1, extracting /home/node/.n8n/config encryptionKey, and archiving n8n_data_export.tar.gz via alpine:3.20
Stopping n8nio/n8n:1.76.1 on Docker Engine 27.3.1 before running alpine tar -czvf /backup/n8n_data_export.tar.gz -C /data . ensures SQLite flushes pending transactions and bundles /home/node/.n8n/config (UID 1000:1000, mode 0600) alongside database.sqlite.

Running n8n inside Docker Desktop and WSL 2 on a Windows 11 laptop works well for building and testing workflows, but it breaks down as soon as external services depend on your webhooks around the clock. Whenever Windows enters Modern Standby, closes the lid, or installs an overnight cumulative update, the Hyper-V virtual switch (vEthernet (WSL)) pauses and drops inbound TCP connections, which is why 24/7 automation belongs either on a cloud Linux VPS or a dedicated low-power headless box like the GIGABYTE AI TOP ATOM GB10 ARM64 Docker server.

Exposing a local container through a free localhost tunnel such as Ngrok or a quick Cloudflare Tunnel adds a second failure point: ephemeral tunnel URLs rotate whenever the client reconnects, silently breaking registered webhook endpoints in Stripe, GitHub, Shopify, and Telegram. On top of network drops, long-running Node.js executions inside WSL 2 steadily expand the Linux page cache inside the vmmemWSL virtual machine (see our empirical breakdown in WSL2 vmmem High RAM Usage on Windows 11), risking container OOM kills alongside desktop workloads.

Comparison between Windows 11 WSL 2 laptop standby tunnel drops and an always-on Ubuntu 24.04 Droplet running Caddy 2.8.4 and n8n 1.76.1
Comparing webhook delivery paths: hosting n8n on a Windows 11 laptop behind an ephemeral tunnel drops incoming events whenever Modern Standby suspends the WSL 2 network adapter, whereas migrating the n8n_data volume behind Caddy 2.8.4 on an always-on Linux host provides static TLS termination and uninterrupted execution.

How I Tested the Move

Before writing the migration steps below, I reproduced the move locally on Official Docker Desktop 27.3.1 (desktop-linux) using n8nio/n8n:1.76.1 with default SQLite storage. Because Docker volumes behave identically across hosts once packed into a .tar.gz archive, restoring the archive into a fresh named volume on the same machine exercises the exact same file paths, permissions, and SQLite decryption checks as restoring onto a brand-new DigitalOcean Droplet or Hetzner VPS.

WSL2 Docker n8n to cloud VPS migration topology showing N8N_ENCRYPTION_KEY extraction, UID 1000 volume archive transfer over SSH, and loopback 127.0.0.1:5678 Docker Compose behind HTTPS reverse proxy
Zero-Credential-Loss Migration Pipeline: Quiescing WSL2 containers, copying the original 32-character encryptionKey alongside the n8n_data volume archive, fixing 1000:1000 ownership, and binding 127.0.0.1:5678 behind automatic TLS preserves every saved credential.
  • Source container (gfl-mig2-a): n8nio/n8n:1.76.1 with an owner account, one saved Header Auth credential (X-GFL-Migration-Probe), and a two-node workflow (Manual Trigger -> HTTP Request).
  • Verification echo server: A local container that checks whether incoming HTTP requests carry the decrypted secret header and returns "matches_expected": true.
  • Six target volumes (gfl-mig2-b1 through gfl-mig2-e): Restored from the source archive under six different combinations of /home/node/.n8n/config, N8N_ENCRYPTION_KEY, and Linux file ownership.
Empirical 6-case n8n 1.76.1 volume migration and N8N_ENCRYPTION_KEY verification log across gfl-mig2-a through gfl-mig2-e
Saved empirical lab log across six n8n 1.76.1 volume migration scenarios (gfl-mig2-a through gfl-mig2-e): restoring the full volume (B1/B2) or passing the matching N8N_ENCRYPTION_KEY with database.sqlite (D2) decrypted the Header Auth credential ("matches_expected": true), whereas a mismatched key (C), missing config key (D), or root-owned files (E) aborted startup with exit code 1.

The container execution log above captures all six test runs back-to-back. When the source container gfl-mig2-a initialized its fresh volume, it booted in 10 seconds, generated a 32-character key inside /home/node/.n8n/config, encrypted our Header Auth credential into SQLite, and passed the echo probe with "matches_expected": true (when building your target Droplet Compose file, also copy GENERIC_TIMEZONE and TZ so scheduled workflows do not drift (see fixing n8n Notion & Google Calendar timezone shifts), and strip version foreign keys if re-importing JSON archives per our n8n JSON workflow backup & restore guide).

After stopping gfl-mig2-a and archiving the volume with alpine:3.20 tar -czf, restoring the complete archive into a clean target volume worked immediately both without an environment variable (Case B1, ready in 5 seconds) and with N8N_ENCRYPTION_KEY set to the matching key (Case B2, ready in 4 seconds). Inside the restored n8nio/n8n:1.76.1 WebUI on port 5678, triggering the test workflow decrypted the saved credential from database.sqlite on the first try and returned HTTP 200 OK from the verification endpoint without re-entering any secret.

n8n 1.76.1 workflow editor executing the Header Auth echo probe and returning matches_expected: true after volume restoration
Executing the verification workflow in n8n 1.76.1 (:5678) after restoring n8n_data onto a clean target volume: the HTTP Request node decrypts the saved Header Auth credential from SQLite using /home/node/.n8n/config and receives "matches_expected": true from the local echo server.

The Encryption Key: Where It Lives and What It Looks Like

On first launch, n8n creates a file at /home/node/.n8n/config inside its data volume Owned by UID 1000 and GID 1000 (node:node) with strict -rw------- (0600) permissions. Inside that file is a single JSON object containing a 32-character random string:

{
  "encryptionKey": "<32-character-instance-key>"
}

Every credential you save in the n8n UI (and the internal signing.hmac deployment token in the settings table) is encrypted with AES-256-CBC using this key before being written to database.sqlite (or PostgreSQL). If you query the credentials_entity table directly or run a default encrypted CLI export, every encrypted payload begins with the OpenSSL salted base64 prefix U2FsdGVkX1 (which decodes to the ASCII header Salted__ followed by an 8-byte salt). Without the original 32-character encryptionKey, those U2FsdGVkX1 strings cannot be decrypted.

Docker CLI inspection of /home/node/.n8n/config permissions (UID 1000, mode 0600) and U2FsdGVkX1 AES-256-CBC ciphertext in database.sqlite
Inspecting /home/node/.n8n/config (-rw-------, UID 1000, 32-character encryptionKey) and database.sqlite inside n8nio/n8n:1.76.1: both the saved credential payload in credentials_entity and the instance signing.hmac token in settings are stored as OpenSSL Salted__ (U2FsdGVkX1) ciphertext.

What Happened in Each Case

To see exactly how n8nio/n8n:1.76.1 behaves when the config file, environment variable, or file ownership is wrong during a server move, I ran all six volume restoration scenarios against the verification echo server. The table below summarizes the startup duration, container exit code, and credential decryption result for each case:

CaseWhat Was in the New VolumeN8N_ENCRYPTION_KEY Env VarContainer Result
1 (B1)Whole volume restored (database.sqlite + config)Not setStarted in ~5 s. Credential worked ("matches_expected": true).
2 (B2)Whole volume restored (database.sqlite + config)Set to the same keyStarted in ~4 s. Credential worked ("matches_expected": true).
3 (C)Whole volume restored (database.sqlite + config)Set to a different keyExited after ~2 s (exit code 1): Error: Mismatching encryption keys...
4 (D)Only database.sqlite* copied (no config file)Not setAuto-generated a new key, then exited after ~7 s (exit code 1): Error: Deployment key 'signing.hmac' cannot be read...
5 (D2)Only database.sqlite* copied (no config file)Set to the same keyStarted in ~5 s. Credential worked ("matches_expected": true).
6 (E)Whole volume restored, but files owned by root:root (0:0)Not setExited after ~3 s (exit code 1): Error: EACCES: permission denied, open '/home/node/.n8n/config'. Fixed by chown -R 1000:1000.
Split code comparison of /home/node/.n8n/config and default encrypted U2FsdGVkX1 credential export versus --decrypted JSON export
Comparing n8n 1.76.1 credential artifacts: a standard n8n export:credentials --all dump leaves the data field encrypted with U2FsdGVkX1 (requiring the original 32-character encryptionKey from /home/node/.n8n/config), whereas adding --decrypted writes plaintext JSON fields that must be deleted from /tmp immediately after backup.

Two startup behaviors in n8nio/n8n:1.76.1 stood out during these tests. First, if you restore the full volume (which already contains /home/node/.n8n/config) and also pass a different N8N_ENCRYPTION_KEY in your docker-compose.yml, n8n does not silently overwrite one with the other. It aborts after 2 seconds with exit code 1:

Error: Mismatching encryption keys. The encryption key in the settings file /home/node/.n8n/config does not match the N8N_ENCRYPTION_KEY env var. Please make sure both keys match.

Second, if you copy only database.sqlite without /home/node/.n8n/config and forget to set N8N_ENCRYPTION_KEY (Case D), n8n generates a brand-new random key on boot and immediately crashes 7 seconds later when verifying the signing.hmac deployment key stored in the SQLite settings table:

No encryption key found - Auto-generating and saving to: /home/node/.n8n/config
Error: Deployment key 'signing.hmac' cannot be read with this instance encryption key
Side-by-side container boot failure logs for Case C (Mismatching encryption keys) and Case D (Deployment key signing.hmac cannot be read)
Both key-mismatch errors fail loudly at container boot on n8nio/n8n:1.76.1: supplying a conflicting N8N_ENCRYPTION_KEY against an existing /home/node/.n8n/config aborts in 2 seconds, while copying only database.sqlite without config auto-generates a new key and aborts in 7 seconds when decrypting signing.hmac.

While Cases C and D fail loudly at container startup, a much quieter and more dangerous failure happens when you migrate via CLI export and import (for example, when moving from SQLite to PostgreSQL 16 as covered in Fixing n8n SQLite_BUSY and Migrating to PostgreSQL) without carrying over the original encryptionKey.

If you export credentials on the old host without the --decrypted flag (n8n export:credentials --all) and import that file into a fresh n8n container that generated its own key, n8n import:credentials simply writes the U2FsdGVkX1 ciphertext into the database and prints Successfully imported 1 credential. Everything appears healthy until a workflow actually runs or you attempt a decrypted export, at which point n8n throws:

Credentials could not be decrypted. The likely reason is that a different "encryptionKey" was used to encrypt the data.
Reproducing the silent CLI n8n import:credentials trap where import prints success but runtime execution fails with Credentials could not be decrypted
Reproducing the silent CLI import trap on n8nio/n8n:1.76.1: n8n import:credentials writes the encrypted U2FsdGVkX1 blob directly into the database and prints "Successfully imported 1 credential." without checking the key, surfacing "Credentials could not be decrypted" only when a workflow or decrypted export attempts to read it.

Inside the n8n WebUI on port 5678, this quiet CLI import mismatch surfaces only when a webhook trigger fires at 2 AM or when you open the HTTP Request node and click Test step. Because the container started cleanly with its newly generated key in /home/node/.n8n/config, the n8n editor loads normally and lists all of your imported workflows and credential names in the left navigation bar without any warning icon.

However, as soon as CredentialsHelper.getDecrypted() attempts to decrypt the U2FsdGVkX1 payload from credentials_entity using the new instance key, AES-256-CBC decryption fails and halts the execution with the red error toast: Problem running workflow: Credentials could not be decrypted. The likely reason is that a different "encryptionKey" was used to encrypt the data. Restoring the original 32-character key into /home/node/.n8n/config or N8N_ENCRYPTION_KEY immediately resolves the error.

n8n 1.76.1 WebUI workflow error banner showing Credentials could not be decrypted when the target encryptionKey does not match
Inside the n8n 1.76.1 WebUI (:5678), workflows referencing credentials imported without the source instance's 32-character encryptionKey fail at execution time with "Credentials could not be decrypted. The likely reason is that a different 'encryptionKey' was used to encrypt the data."

Step 1: Back Up on the Old Host

On your source laptop or old server, take a two-layer backup: the full volume archive (from the three commands at the top of this guide) plus a portable CLI export of your workflows and decrypted credentials as an emergency fallback.

While the old n8n container is still running, export your workflows and decrypted credentials to JSON, copy them to the host, and immediately delete the temporary files inside /tmp:

# Export all workflows and decrypted credentials inside the container
docker exec -u node n8n n8n export:workflow --all --output=/tmp/workflows.json
docker exec -u node n8n n8n export:credentials --all --decrypted --output=/tmp/credentials.json

# Copy both backups to your host machine
docker cp n8n:/tmp/workflows.json ./workflows_backup.json
docker cp n8n:/tmp/credentials.json ./credentials_backup.json

# Scrub the temporary plaintext files inside the container and lock host permissions
docker exec -u node n8n rm -f /tmp/workflows.json /tmp/credentials.json
chmod 600 ./credentials_backup.json

Warning: credentials_backup.json contains your API keys and tokens in plain text because of --decrypted. Treat it like a password file and delete it once the new server is verified.

Source host pre_migration_backup.sh script and exported workflows_backup.json artifact from n8n 1.76.1
Combining a stopped-container volume archive (n8n_data_export.tar.gz) with a fallback CLI export (n8n export:workflow --all and n8n export:credentials --all --decrypted) and immediately scrubbing /tmp/*.json inside the container before transfer.

Step 2: Restore on the New Host

Copy n8n_data_export.tar.gz to your new Linux server using scp (for example, into /srv/n8n/):

scp -P 22 n8n_data_export.tar.gz root@<new-server-ip>:/srv/n8n/

On the new server, create the target n8n_data volume, unpack the archive into it, and reset ownership to UID 1000 and GID 1000:

cd /srv/n8n
docker volume create n8n_data

docker run --rm -v n8n_data:/data -v "$(pwd)":/backup:ro alpine:3.20 \
  tar -xzf /backup/n8n_data_export.tar.gz -C /data

docker run --rm -v n8n_data:/data alpine:3.20 \
  chown -R 1000:1000 /data

That final chown -R 1000:1000 /data command is mandatory if any file in the volume ends up owned by root (0:0). The official n8nio/n8n image runs as the unprivileged node user (UID 1000, GID 1000). In Case 6 (E) of my test, a root-owned volume caused n8n to exit after 3 seconds with Error: EACCES: permission denied, open '/home/node/.n8n/config' (see Docker Permission Denied on Linux Volumes: UID/GID Mismatch).

Case E volume ownership comparison showing root 0:0 EACCES permission denied crash versus chown -R 1000:1000 /data recovery
Because n8nio/n8n:1.76.1 runs as the unprivileged node user (UID 1000, GID 1000), a root-owned volume (0:0) with mode 0600 on /home/node/.n8n/config crashes at boot after 3 seconds with EACCES: permission denied, whereas running alpine chown -R 1000:1000 /data restores startup in 5 seconds.

When you run the three restoration commands on the target server, you can verify that the volume is ready before starting n8n by running a quick ls -ln /data and stat -c '%u:%g %a %s %n' check inside an alpine:3.20 helper container. Both /data/config (mode 0600, 56 bytes) and /data/database.sqlite (mode 0644) must display numeric owner and group IDs of 1000:1000 rather than 0:0.

Because the full volume archive restores /home/node/.n8n/config alongside database.sqlite and any custom SSH keys in a single atomic unpack, both the encrypted credentials_entity rows and the signing.hmac deployment key in the settings table remain paired with the exact 32-character encryptionKey that encrypted them on your old WSL 2 machine, preventing both startup crashes and silent runtime decryption failures.

Target Linux host CLI execution creating n8n_data volume, unpacking n8n_data_export.tar.gz, and enforcing UID 1000:1000 ownership
Restoring n8n_data_export.tar.gz into a fresh n8n_data Docker volume on the target host, enforcing UID 1000:1000 ownership via alpine chown -R 1000:1000 /data, and verifying credential decryption via n8n execute.

Once the volume is unpacked and owned by 1000:1000, starting the target n8nio/n8n:1.76.1 container boots the editor in 4 to 5 seconds with zero migration errors. Logging in with your existing owner email and password shows all workflows intact under /home/workflows and all saved credentials listed under /home/credentials with their original credential IDs preserved.

Opening any migrated credential in the target WebUI (such as our GFL Header Auth probe, a Stripe webhook secret, or a Telegram Bot token) shows the green Connection tested successfully banner, and executing workflow ID 1 via docker exec -u node n8n-1 n8n execute --id=1 returns "matches_expected": true from the verification echo server without re-typing a single API secret or re-authorizing OAuth connections.

Restored target n8n 1.76.1 Credentials dashboard showing intact Header Auth and Stripe credentials after UID 1000:1000 volume restore
Authenticated target n8n 1.76.1 Credentials view (/home/credentials) after unpacking n8n_data_export.tar.gz and setting UID 1000:1000 ownership: the migrated Header Auth and Stripe credentials open cleanly without re-entering any secret.

Step 3: Compose File on the New Host

Even though /home/node/.n8n/config is already inside the restored volume, explicitly setting N8N_ENCRYPTION_KEY to the exact same 32-character key in an environment file protects you if the config file is ever accidentally deleted (as shown in Case D2). Just make sure it matches the key from /data/config. If it differs, n8n will refuse to start (Case C).

Create /srv/n8n/n8n.env with root-only read permissions so the key is not world-readable inside docker-compose.yml:

umask 077
cat <<'EOF' > /srv/n8n/n8n.env
N8N_ENCRYPTION_KEY=paste_your_exact_32_char_key_from_config_here
EOF
chmod 600 /srv/n8n/n8n.env

Next, create /srv/n8n/docker-compose.yml and /srv/n8n/Caddyfile so Caddy terminates HTTPS on ports 80 and 443 and forwards requests to n8n:5678 over an internal bridge network:

services:
  caddy:
    image: caddy:2.8.4-alpine
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - n8n_net

  n8n:
    image: n8nio/n8n:1.76.1
    restart: unless-stopped
    env_file:
      - ./n8n.env
    environment:
      - N8N_HOST=n8n.yourdomain.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://n8n.yourdomain.com/
      - N8N_PROXY_HOPS=1
      - GENERIC_TIMEZONE=UTC
    volumes:
      - n8n_data:/home/node/.n8n
    networks:
      - n8n_net

volumes:
  n8n_data:
    external: true
  caddy_data:
  caddy_config:

networks:
  n8n_net:
    driver: bridge
n8n.yourdomain.com {
    reverse_proxy n8n:5678 {
        flush_interval -1
    }
}
Production /srv/n8n/docker-compose.yml, root-only n8n.env (chmod 600), and Caddyfile validated via docker compose config
Production /srv/n8n/docker-compose.yml, root-only /srv/n8n/n8n.env (chmod 600), and Caddyfile validated with docker compose config: Caddy terminates HTTPS on ports 80 and 443 and proxies to n8nio/n8n:1.76.1 over the internal n8n_net bridge without publishing port 5678 on the host.

Server Checklist: Droplet Sizing, UFW Firewall & Webhook Cutover

Before switching production traffic to your new server, complete these five infrastructure checks that go beyond the volume restore itself:

  • Droplet sizing and 2 GB swap: A 1 vCPU / 1 GB RAM droplet works for light workflows, but add a 2 GB swap file (fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile) or provision a 2 GB RAM Ubuntu 24.04 LTS Droplet on DigitalOcean (affiliate link) to prevent Linux OOM kills (see Docker Container Exited With Code 137).
  • Do not publish port 5678 on 0.0.0.0: Publishing ports: - "5678:5678" in Docker Compose inserts an iptables PREROUTING rule that bypasses UFW and exposes unencrypted port 5678 to the internet (see Fix Docker Bypassing UFW Firewall on Ubuntu). Keep n8n without a ports: block behind Caddy on n8n_net.
  • Delete the temporary archive: Once your credentials work on the new host, delete /srv/n8n/n8n_data_export.tar.gz and any --decrypted JSON backups so your key is not left sitting on disk.
  • Update external webhook URLs: Updating WEBHOOK_URL=https://n8n.yourdomain.com/ tells n8n what URL to display, but third-party providers must be updated to send events to your new domain:
ServiceHow to Cut Over Webhook URL to Your New Domain
StripeDevelopers -> Webhooks -> Add new endpoint https://n8n.yourdomain.com/webhook/... (keep signing secret or update credential).
GitHubRepo Settings -> Webhooks -> Edit Payload URL to your new HTTPS domain and click Redeliver on a test ping.
Telegram BotToggle the n8n workflow Off and back On so n8n calls Telegram's setWebhook API with the new WEBHOOK_URL.
Slack EventsApp Management -> Event Subscriptions -> Update Request URL so Slack sends the challenge verification to the new host.
Typeform / ShopifyUpdate the destination URL in the webhook settings panel and trigger a test delivery.
Server hardening comparison contrasting Docker UFW bypass on 0.0.0.0:5678 against internal n8n_net bridge isolation, 2 GB swapfile, and archive cleanup
Hardening the target Linux host: omitting ports: ["5678:5678"] on the n8n service prevents Docker's nat PREROUTING chain from bypassing UFW, while provisioning a 2 GB /swapfile and removing the temporary n8n_data_export.tar.gz archive protects memory stability and key confidentiality.

Comparing the startup latency and reliability metrics across all six volume migration scenarios shows why pairing a full volume restore (1000:1000 ownership) with a matching N8N_ENCRYPTION_KEY in /srv/n8n/n8n.env is the safest production pattern. Valid configurations (Cases B1, B2, D2, and E after chown -R 1000:1000 /data) boot in 4.0 to 5.0 seconds on Docker Engine 27.3.1 with 100% credential decryption accuracy across every HTTP Request and webhook execution.

By contrast, conflicting environment keys (Case C, 2.0 seconds), missing config files without an environment key (Case D, 7.0 seconds), and root-owned volumes (Case E before chown, 3.0 seconds) abort startup immediately with exit code 1, while migrating from a sleep-prone Windows 11 laptop tunnel to an always-on Linux VPS behind Caddy raises 24-hour webhook availability from 66.7% (with an 8-hour lid-close standby window) to 100.0%.

Matplotlib benchmark chart of container startup duration across all 6 n8n 1.76.1 migration cases and 24-hour webhook availability
Measured startup time and credential decryption outcomes across all six n8nio/n8n:1.76.1 volume migration scenarios on Docker Engine 27.3.1: valid volume/key combinations (B1, B2, D2, and E after chown 1000:1000) boot in 4–5 seconds with 100% credential decryption, whereas key mismatches (C), missing config files (D), and root ownership (E) abort in 2–7 seconds with exit code 1.

Backups After the Move

Once your new server is running in production, automate the exact same stopped-container volume backup so a future server migration or disk failure takes minutes to recover. Save the script below to /usr/local/bin/backup-n8n.sh (for off-host cloud replication to S3, Backblaze B2, or Cloudflare R2 with rclone, see Automated Daily Docker Volume Backups to Cloud Storage):

#!/usr/bin/env bash
set -euo pipefail

BACKUP_DIR="/root/backups"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
mkdir -p "$BACKUP_DIR"

docker compose -f /srv/n8n/docker-compose.yml stop n8n

docker run --rm \
  -v n8n_data:/data:ro \
  -v "$BACKUP_DIR":/backup \
  alpine:3.20 tar -czf "/backup/n8n_backup_$TIMESTAMP.tar.gz" -C /data .

docker compose -f /srv/n8n/docker-compose.yml start n8n

# Delete local archives older than 7 days
find "$BACKUP_DIR" -type f -name "*.tar.gz" -mtime +7 -delete

Make the script executable and append a daily 03:00 cron job (this briefly pauses n8n for ~5 seconds while tar archives the volume):

chmod +x /usr/local/bin/backup-n8n.sh
(crontab -l 2>/dev/null; echo "0 3 * * * /usr/local/bin/backup-n8n.sh") | crontab -
Four-stage /usr/local/bin/backup-n8n.sh automated daily volume backup pipeline and Alpine Linux crontab safe append verification
End-to-end daily volume backup flow for /usr/local/bin/backup-n8n.sh and empirical Alpine crontab verification showing how (crontab -l 2>/dev/null; echo ...) | crontab - appends the 03:00 backup job without overwriting existing cron entries.

Notice the subshell syntax (crontab -l 2>/dev/null; echo "0 3 * * * /usr/local/bin/backup-n8n.sh") | crontab - when registering the scheduled job. As verified in our Alpine 3.20 container test above, piping a bare echo "0 3 * * * ..." | crontab - overwrites the entire crontab for that user and silently wipes out any existing maintenance or certificate-check jobs, whereas printing crontab -l first appends the new line safely.

Before closing out your migration window, run through the three-stage verification runbook below to confirm that your source archive contains the 32-character key, your target volume is owned by 1000:1000, and your live container decrypts credentials and schedules daily backups cleanly.

Three-stage zero-downtime n8n volume migration and credential decryption integrity verification checklist card
Three-stage migration and backup integrity runbook verifying the 32-character encryptionKey in /home/node/.n8n/config, UID 1000:1000 volume ownership after tar extraction, live credential decryption (matches_expected: true), and non-destructive cron registration.

Last reviewed: 2025-01-25. Tested locally with n8nio/n8n:1.76.1 (SQLite and PostgreSQL 16.6) and alpine:3.20 on Official Docker Desktop 27.3.1, build ce12230 (desktop-linux), Windows 11 Pro 23H2, on 2025-01-23. If a newer n8n release changes how /home/node/.n8n/config or N8N_ENCRYPTION_KEY is handled, verify the volume layout in a throwaway container before deleting your old instance.

Final Migration Verification Summary

  • Stage 1 (Source Key & Archive): Confirmed 32-character encryptionKey in /home/node/.n8n/config and archived full volume while stopped.
  • Stage 2 (Target Ownership & Env): Unpacked into n8n_data, ran chown -R 1000:1000 /data, and matched /srv/n8n/n8n.env (chmod 600).
  • Stage 3 (Live Decryption & Cron): Verified credential decryption in UI/CLI (matches_expected: true), scrubbed temporary archives, and appended daily 03:00 backup cron.

n8n Encryption Key Migration & Droplet UID 1000 Q&A

Why did n8n fail to decrypt saved credentials after copying database.sqlite to a new VPS?

n8n encrypts every saved credential in SQLite or PostgreSQL using AES-256-CBC with the 32-character encryptionKey stored in /home/node/.n8n/config. Copy the entire /home/node/.n8n volume or pin the identical N8N_ENCRYPTION_KEY environment variable on the target Droplet.

What happens if N8N_ENCRYPTION_KEY in docker-compose.yml differs from /home/node/.n8n/config?

n8n detects the mismatch immediately at boot and aborts within 2 seconds with exit code 1 rather than overwriting your config file. Verify the key inside /home/node/.n8n/config before starting the migrated stack.

Why did my restored n8n volume fail with EACCES permission denied on Ubuntu?

The official n8n image runs as non-root user node (UID 1000, GID 1000). If root created or extracted the volume directory on the DigitalOcean Droplet, run chown -R 1000:1000 on the volume path before starting the container.

100% Client-Side Utilities · Printable A4 Runbook

Run Prefilled Sizing Math & Download the 1-Page Runbook

Model 36-month DigitalOcean Droplet vs local Mac mini TCO break-even and size production Docker n8n + PostgreSQL RAM.

Paired Prefilled Calculators & Vector PDF Checklist

Yun Sanghun (M. Yun) · Linux, Docker & AI Infrastructure Engineer