Invoice Ledger

Back up n8n workflows — and prove the restore works

A CLI export is not a backup, and a backup you have never restored is a rumour. This is what a complete copy contains, the commands, and a drill with a pass condition.

Guide · checked against n8n documentation and published images on 22 October 2026 · works with JavaScript switched off

What a "complete backup" means in n8n

n8n's own documentation is unusually direct about this: a complete backup is two parts, not one.1 The first is the .n8n user folder — ~/.n8n by default, and inside a Docker container it is the volume mounted at /home/node/.n8n. That folder holds the config file, which stores the credential encryption key; with the default SQLite database it also holds the database file itself.

The second part is your external database, if you use PostgreSQL. And in either case, if you have pointed binary data or execution data at a custom filesystem path, or loaded custom nodes from directories in N8N_CUSTOM_EXTENSIONS, those are part of the backup too.

That definition is the whole article. Everything below is the mechanical part.

Three things people call "a backup"

What you haveContainsDoes not contain
CLI export (--backup) Workflows and credentials as separate, readable JSON files Users and roles, execution history and logs, variables, instance settings, and the encryption key1
A copy of .n8n The encryption key, and with SQLite the entire database Nothing for SQLite; for PostgreSQL, the database itself
A database dump Workflows, credentials (encrypted), users, execution data The encryption key — so the credentials in it are unreadable on a fresh host unless you also restore config or set the same N8N_ENCRYPTION_KEY

Which is why the practical answer is: do the CLI export and copy the instance. The export is what you read and diff; the copy is what you restore.

Step 1 — know which database you have

Fresh self-hosted installs use SQLite; the documentation says so plainly, and describes PostgreSQL as the option you configure with environment variables.2 In a Compose setup you can see it in one command:

docker compose exec n8n printenv DB_TYPE

No output means SQLite (the default). postgresdb means the database is a separate service and needs pg_dump, not a folder copy.

Step 2 — the CLI export, exactly as documented

n8n documents two commands, and the --backup flag is shorthand for --all --pretty --separate: one JSON file per workflow, one per credential.1

n8n export:workflow    --backup --output=backups/workflows/
n8n export:credentials --backup --output=backups/credentials/

In Docker, the documented form runs the CLI inside the container as the node user:3

docker compose exec -u node n8n \
  n8n export:workflow --backup --output=/home/node/.n8n/backups/workflows/

Two traps, both documented:

Step 3 — copy the instance, key included

For a Compose install with SQLite, stop n8n first — the documentation is explicit that copying the database while n8n is writing to it can produce an inconsistent backup.1

# stop writes, then archive the volume that holds config + SQLite
docker compose stop n8n
docker run --rm \
  -v n8n_n8n_storage:/data:ro \
  -v "$PWD/backups":/backup \
  alpine tar czf /backup/n8n-data-$(date -u +%F).tar.gz -C /data .
docker compose start n8n

Check the volume name first with docker volume ls; Compose prefixes it with the project directory name.

With PostgreSQL, dump the database and still keep the folder, because the key lives there:

docker compose exec -T postgres \
  pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" \
  | gzip > "backups/n8n-db-$(date -u +%F).sql.gz"

The -T matters: docker compose exec allocates a pseudo-TTY by default, and -T / --no-tty turns it off — which is what you want when the output is being piped into a file.4

The key is the backup. Credentials are stored encrypted. Without the encryption key from config — or the same custom N8N_ENCRYPTION_KEY — a restored database cannot be decrypted, and the workflows that reference those credentials will fail at runtime, not at import time.1 Put the key somewhere that is not the same disk as the backup.

Step 4 — run it nightly, keep dated copies

A shell script plus a systemd timer is enough, and both are in the operating system you already have. The script below is the shape that survives: dated directory, no silent failure, old copies pruned.

#!/usr/bin/env bash
# /usr/local/bin/n8n-backup.sh — run as root from a systemd timer
set -euo pipefail          # pipefail matters: it is what catches a failed pg_dump in a pipe
PROJECT=/opt/n8n            # directory holding compose.yml
DEST=/srv/backups/n8n       # NOT on the same disk as the n8n data
VOLUME="${PROJECT##*/}_n8n_storage"   # check this with: docker volume ls
STAMP=$(date -u +%Y-%m-%d)

cd "$PROJECT"
mkdir -p "$DEST/$STAMP"

# Fail loudly if the volume name is wrong. `docker run -v name:/data` CREATES a missing
# volume instead of erroring, so without this check the script would archive an empty folder
# and exit 0.
docker volume inspect "$VOLUME" >/dev/null

# PostgreSQL install: dump the database first (skip this if you use SQLite - the archive
# below already contains the database file). Use your own POSTGRES_USER / POSTGRES_DB values.
docker compose exec -T postgres pg_dump -U n8n -d n8n \
  | gzip > "$DEST/$STAMP/n8n-db.sql.gz"

# The .n8n folder: the encryption key, and with SQLite the database itself. Stop n8n for the
# copy: the docs are explicit that copying the SQLite file while n8n is writing to it can
# produce an inconsistent backup.
docker compose stop n8n
trap 'docker compose start n8n' EXIT   # bring it back even if the copy below fails
docker run --rm -v "$VOLUME:/data:ro" -v "$DEST/$STAMP:/backup" \
  alpine tar czf /backup/n8n-data.tar.gz -C /data .

# keep 14 days
find "$DEST" -mindepth 1 -maxdepth 1 -type d -mtime +14 -exec rm -rf {} +

The timer. These are two files — a service and a timer; saving both blocks into one file makes systemd refuse to parse it:

# FILE 1: /etc/systemd/system/n8n-backup.service
[Unit]
Description=n8n backup

[Service]
Type=oneshot
ExecStart=/usr/local/bin/n8n-backup.sh
# FILE 2: /etc/systemd/system/n8n-backup.timer
[Unit]
Description=Nightly n8n backup

[Timer]
OnCalendar=*-*-* 03:20:00
Persistent=true

[Install]
WantedBy=timers.target
systemctl daemon-reload
systemctl enable --now n8n-backup.timer
systemctl list-timers n8n-backup.timer

Persistent=true is the line that makes a missed run happen after boot instead of vanishing, which is the difference between a backup and a wish.

Then get the copy off the machine. rsync to a host you control is the smallest working answer — that is the one thing in this guide where a rented server earns its keep (a small VPS as an off-site target). Object storage with versioning is the other answer; both are outside n8n and outside this guide.

Step 5 — restore into a throwaway instance

This is the step that turns a copy into a backup. Do it on a second machine, or on the same machine with the production stack stopped.

  1. Start a second n8n container with the same N8N_ENCRYPTION_KEY and a different volume. Complete the owner setup: the import commands need an existing user.1
  2. Copy the export directory in and import it:
    docker compose exec -u node n8n \
      n8n import:workflow    --separate --input=/home/node/.n8n/backups/workflows/
    docker compose exec -u node n8n \
      n8n import:credentials --separate --input=/home/node/.n8n/backups/credentials/
  3. Imported workflows arrive deactivated by default. Activate them in the UI, or pass --activeState=fromJson, which the docs note only works in queue or multi-main mode.1
  4. Open one imported workflow and execute it. A credential that cannot be decrypted fails here, loudly, which is exactly what you want to find on a test box.

What "the restore passed" looks like

Write the answer down, because a drill with no numbers becomes a feeling:

If any of those four disagree, the backup is not done — and you have just found out at the cheapest possible moment.

Troubleshooting

Honest limits

If the thing you are backing up is an invoice ledger

The pack this site sells includes a workflow that writes one dated copy of the ledger CSV every night (11-ledger-backup.json) — a file-level copy, not a replacement for the instance backup above. If you are automating invoices, that pair is the whole safety story: the ledger copy for the data, the instance copy for the machine.

Invoice Ledger — 11 workflows, USD 49 · how the invoice pipeline works · why execution history is the other disk problem · the pack on the n8n template library

Sources

  1. n8n docs — Back up and restore (what a complete backup contains; what a CLI backup does not contain; export/import commands and flags; encryption key warning; Docker volume path). Read 2026-10-22.
  2. n8n docs — Choose n8n's database. Read 2026-10-22.
  3. n8n docs — Use the command line (docker exec -u node form; export and import flags). Read 2026-10-22.
  4. Docker docs — docker compose exec (“Commands allocate a TTY by default”; -T / --no-tty). Read 2026-10-22.
  5. n8n docs — Export and import (credential names in exports; recommended n8n CLI; planned deprecation of Server CLI export/import). Read 2026-10-22.
  6. n8n docs — Download workflows (n8n Cloud) (owners download workflows from the most recent backup in the Cloud admin dashboard; no other route documented). Read 2026-10-22.
  7. Docker docs — Volumes (“If you start a container with a volume that doesn't yet exist, Docker creates the volume for you”; an empty volume is created). Read 2026-10-22.

Version note: the n8n documentation was read on 2026-10-22, when the published npm latest for n8n was 2.44.5 and the published image index for n8nio/n8n:2.44.5 listed linux/amd64 and linux/arm64. Commands and defaults can change; the pages above are the authority.