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 have | Contains | Does 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:
- Use a different output directory for each command. A known issue makes
import:credentials --separatefail when the input directory also contains workflow files, so keeping them apart now saves you later.1 - A
backups/directory inside the container is not persisted — only.n8nis a volume. Bind-mount a host directory, or write into/home/node/.n8n/backups/as above and copy it out.1
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.
- Start a second n8n container with the same
N8N_ENCRYPTION_KEYand a different volume. Complete the owner setup: the import commands need an existing user.1 - 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/ - 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 - 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:
ls backups/workflows/*.json | wc -land the workflow count in the restored instance agree.ls backups/credentials/*.json | wc -land the credential count agree.- One workflow that uses a credential ran to completion after restore.
- The execution appears in the restored instance's history with a green result.
If any of those four disagree, the backup is not done — and you have just found out at the cheapest possible moment.
Troubleshooting
- The archive is tiny and the restore is empty. The volume name was wrong.
docker run -v name:/datacreates an empty volume instead of failing,7 so thedocker volume inspectline in the script is not decoration. Check the real name withdocker volume lsand compare it with the project directory name. import:credentials --separatefails. The input directory probably contains workflow files as well; the docs record this as a known issue. Keep the two exports in two directories, as the commands above do.- Workflows import but credentials cannot be decrypted. The restore instance
does not have the same encryption key. Copy the
configfile, or set the sameN8N_ENCRYPTION_KEY, then re-import. - Imported workflows are all inactive. That is the default. Activate them in
the UI, or pass
--activeState=fromJson(queue or multi-main mode only).
Honest limits
- Exported workflow JSON carries credential names and IDs. The docs warn that the names can be sensitive depending on how you name them, and that HTTP Request nodes imported from cURL may contain authentication headers. Strip before sharing.5
--decryptedwrites credentials in plain text. The docs say to treat such a file like the credentials themselves and delete it once restored. Do that.1- The Server CLI export/import commands are expected to be deprecated. n8n
now recommends the
n8n-clipackage and.n8nppackages for moving workflows between instances, which are in preview; the deprecation of the Server CLI commands "is not yet scheduled".5 The commands above work today (n8n 2.44.5). - On n8n Cloud there is no shell and no instance folder to copy. The documented
backup route there is Download workflows in the Cloud admin dashboard, which gives you
workflow JSON and nothing else — no
.n8nfolder, no database, no encryption key.6 That is one more reason the paid ledger is documented as self-hosted. - Nothing here was benchmarked. No claim is made about how long a backup of your instance takes or how large it is.
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
- 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.
- n8n docs — Choose n8n's database. Read 2026-10-22.
- n8n docs — Use the command line (
docker exec -u nodeform; export and import flags). Read 2026-10-22. - Docker docs — docker compose exec (“Commands allocate a TTY by default”;
-T/--no-tty). Read 2026-10-22. - n8n docs — Export and import (credential names in exports; recommended n8n CLI; planned deprecation of Server CLI export/import). Read 2026-10-22.
- 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.
- 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.