A backup you've never restored isn't a backup, it's a guess with a timestamp on it. That's the uncomfortable truth behind a popular r/n8n thread this autumn about losing workflows to a bad upgrade, with half the replies pointing at a paid backup-manager tool as the fix. You don't need one. n8n ships export and import commands for exactly this, and this n8n backup and restore routine uses nothing but those, a tarball, and one encryption key you keep somewhere safer than the server itself.
This is part 4 of the site's self-hosting series. Part 1 covered moving off npm before Docker became mandatory, part 2 covered the v3 storage rename, and part 3 built the Docker Compose setup this post assumes you're backing up. Everything below was run against a real n8n instance in this sandbox, including the restore, not assumed from the docs.
Blip: A backup you've never restored and a backup that doesn't exist look identical right up until the moment you need one.
Before you start
You'll need shell access to the machine or container running n8n, and to know where your data directory and your N8N_ENCRYPTION_KEY actually live. Nothing here needs a second server; the restore test runs against a throwaway instance you spin up just for this and delete afterward.
Step 1: Export your workflows
n8n's CLI dumps every workflow to its own JSON file in one command, already shown in this site's VM-engine audit for a different reason:
n8n export:workflow --all --separate --output=./backup/workflows/
I ran this against a real workflow created through the n8n API (not a hand-written stub) and confirmed it writes one file per workflow, named by the workflow's own ID, containing the full node graph.
Step 2: Export your credentials, carefully
Same shape, different command, and one flag that matters a lot:
n8n export:credentials --all --separate --output=./backup/credentials-encrypted/
Without --decrypted, each credential's data field comes out as ciphertext, still locked to whatever N8N_ENCRYPTION_KEY your instance is running. That's fine for a same-key restore, but I tested what happens when it isn't: I imported this exact encrypted export into a fresh instance running a different key. The import itself reported success with no error at all, "Successfully imported 1 credential", nothing looked wrong. Only when I tried to actually use that credential (a decrypted re-export, in my test) did n8n say what had really happened: "Credentials could not be decrypted. The likely reason is that a different 'encryptionKey' was used to encrypt the data." The import doesn't fail loudly. It fails silently, and you find out later, which is exactly the scenario Step 4 exists to prevent.
If you're deliberately moving to a new key, or you just want a format you can actually inspect, add --decrypted:
n8n export:credentials --all --decrypted --separate --output=./backup/credentials-decrypted/
I confirmed this writes the real password in plain text in the JSON, which is exactly what the flag is for and exactly why the next step matters.
Step 3: Never let the decrypted version anywhere near git
The encrypted export from Step 2 is safe to commit, it's useless without your key. The decrypted one is a plaintext list of every password and API key your workflows use, and it needs to never touch a git history, including a private repo, including one you'll "clean up later." This site's post on leaked n8n API tokens covered exactly how a committed-then-deleted secret stays reachable in history forever, GitGuardian's 4,576 leaked tokens didn't get there by anyone trying to leak them. If you need the decrypted export at all (migrating to a new encryption key, auditing what a credential actually contains), write it to a path your .gitignore already excludes, use it, and delete it. The encrypted export in Step 2 is your actual backup artifact.
Step 4: Save the encryption key somewhere the server backup doesn't reach
Every credential n8n has ever stored decrypts with exactly one key, N8N_ENCRYPTION_KEY, whether you set it explicitly or n8n auto-generated one into its config file the first time it ran (check with the same pattern used in part 1 of this series: grep -o '"encryptionKey":"[^"]*"' ~/.n8n/config). Step 2's silent-failure result is the whole argument for this step: an encrypted backup with a lost key isn't a backup, it's a very well-organized list of credentials nobody can ever read again. An earlier post in this series covered a sandbox-escape bug whose entire payoff was reaching this exact key, worth remembering that the key is both the thing you must never lose and the thing an attacker most wants.
Write it down somewhere that isn't the server you're backing up and isn't the same backup archive as your credentials file. A password manager entry or a secrets vault both work. The one wrong answer is "it's fine, it's in the config file on the same disk as everything else," since that disk is exactly what you're protecting against losing.
Step 5: Back up the whole data directory too
Workflow and credential exports cover what's in the database, but not everything n8n keeps lives there. Back up the data directory itself:
tar -czf n8n-backup-$(date +%Y%m%d).tar.gz -C ~ .n8n
If you're on Postgres rather than SQLite, add a pg_dump of that database to the same backup; the .n8n folder alone won't have your workflow and execution data in that setup. I ran the tar command above against a real, populated .n8n directory (not a mock one) and confirmed the archive extracts cleanly.
Step 6: Prove the n8n backup and restore actually works
This is the step the r/n8n thread's commenters were all skipping. I built a second, throwaway n8n instance from scratch, imported both exports into it, and checked the result end to end:
n8n import:workflow --separate --input=./backup/workflows/
n8n import:credentials --separate --input=./backup/credentials-encrypted/
The workflow came back with the same node graph. The credential, imported on an instance running the same key as the original, decrypted cleanly, I confirmed this by re-exporting it decrypted afterward and diffing the password against the original: identical, byte for byte. That's the version of "the backup works" worth trusting, not the version where the commands ran without printing an error.
One gotcha worth knowing before you restore onto an instance that already has data on it: n8n's export keeps each workflow's and credential's original database ID, and importing a file whose ID already exists overwrites that row rather than creating a second one. I confirmed this by importing the same workflow file twice into the same instance, once is a clean import, the second time 'succeeds' with an identical message but there's still exactly one copy afterward, not two. For a disaster-recovery restore that's usually what you want. For a test like this one, do it on a throwaway instance, not your production one, so there's nothing it can collide with.
What this doesn't cover
n8n's own docs flag that these Server CLI commands (export:workflow, import:workflow, and their credential equivalents) are planned for eventual deprecation in favor of a newer n8n CLI tool built around .n8np package files, still in Preview as of this writing. The commands above are today's documented, stable path and the ones this post actually tested; if that newer tool graduates out of preview, it's worth a follow-up, but nothing here is at risk of disappearing without notice in the meantime.
This also isn't a scheduling system. Run the export and tar commands by hand, or wire them into a cron job or a scheduled workflow (n8n can back up n8n, which is either elegant or a little too recursive, your call), but either way the schedule is on you; nothing in n8n triggers this automatically.
Where to start
Run Steps 1, 2, and 5 today, on whatever you're currently running, and store the key from Step 4 somewhere that survives the server dying. Then, before you trust any of it, do Step 6 once: spin up a throwaway instance, restore into it, and confirm a real credential actually decrypts. If you'd rather hand the whole backup question to someone else, a free n8n Cloud trial puts backups, key management, and restores on n8n's own team instead of yours.
Disclosure: the n8n Cloud link above is an affiliate link, if you sign up through it, we may earn a commission at no extra cost to you. See our affiliate disclosure for details.
Top comments (0)