~/t/g/self-hosting $

n8n restored credentials broken? Keep the matching key

gist Preserve the matching encryption key and a consistent database backup, then check credential use in a separate recovery environment.

contents
  1. Step 1: Keep the encryption key with the service state
  2. Step 2: Copy a consistent set of files
  3. Step 3: Choose full backups or exports
  4. Step 4: Check recovery before you need it
  5. Common questions

If n8n credentials stop working after a restore, check that the database has its matching encryption key. A different key cannot decrypt the saved values (n8n encryption key documentation).

I run n8n in Docker on my Unraid box. Before planning a backup, find your persistent storage mount, database type and key source. Have access to the deployment configuration and a protected backup destination.

The screenshots come from a throwaway test install, not my live one.

Step 1: Keep the encryption key with the service state

On first launch, n8n generates a random key and saves it in .n8n. A deployment can supply a custom key through N8N_ENCRYPTION_KEY. Queue workers need the same key as the main instance. n8n encryption key documentation

Check your existing key source:

  • For a generated key, preserve the persistent .n8n directory.
  • For N8N_ENCRYPTION_KEY, keep the exact value in a protected secret store.
  • For queue mode, record how the main instance and workers receive that key.

Do not replace the key during recovery. Keep an independent protected copy so losing the service disk does not remove your only copy.

A masked presence check shows that a key setting exists. It does not show whether the key matches a backup. Record the key source with the backup date, then check the pairing during recovery.

Encrypt backups and restrict access. Treat the database and matching key together as sensitive credential material.

n8n stores Example service login as a saved credential; recovering it requires the matching encryption key
A saved credential like this one is stored encrypted. Restore the database with a different key and it stops working.

Step 2: Copy a consistent set of files

The standard Docker persistence mount is /home/node/.n8n. Find the named volume or host directory behind it. By default, n8n stores workflows, credentials and past executions in SQLite. With PostgreSQL, .n8n still holds other state, including a generated encryption key. n8n Docker documentation

Stop n8n before copying its SQLite-backed persistent directory, or use a consistent database snapshot. Copying during a transaction can mix old and new data. SQLite also provides online backup methods for a running database. SQLite backup guidance

For a stopped-service copy:

  1. Schedule downtime and shut down n8n normally.
  2. Confirm that every process using this SQLite database has stopped.
  3. Copy the whole persistent directory while those processes remain stopped.
  4. Keep any database journal or WAL files with their database.
  5. Save the deployment configuration and separately supplied key.

Stopping n8n means no transaction can run during the copy, which is what SQLite asks for. Do not delete companion files to simplify it. SQLite documents that journals can be needed for recovery, and a WAL file forms part of the database’s persistent state. SQLite corruption guidance, SQLite WAL documentation

Deployment Backup materials to check
Default SQLite setup Persistent .n8n directory, including the database and any journal or WAL files
PostgreSQL setup PostgreSQL backup plus the persistent .n8n directory
Key supplied through an environment variable Separate protected copy of the matching key
Queue mode Matching key configuration for the main instance and workers

The directory and database requirements come from n8n’s Docker documentation. The separate key and worker requirements follow its encryption key documentation.

For PostgreSQL, use a database-aware backup method such as pg_dump. It produces a consistent database dump while the database is in use. Copying .n8n alone cannot capture that separate database. PostgreSQL SQL dump documentation

Also record the n8n image reference, storage mappings and database settings needed to recreate the deployment. Check whether your configuration uses storage outside .n8n; include it in your backup plan.

Keep dated copies away from the service disk. Review backup failures and retain earlier copies.

n8n has a masked encryption key and SQLite state; both belong in the recovery plan
The key and the SQLite files, including the -shm and -wal companions, all go in the same backup.

Step 3: Choose full backups or exports

A database backup preserves database state. Workflow and credential exports preserve selected records. n8n documents separate CLI commands for each export type. n8n CLI documentation

Approach What you keep Recovery work to plan
Full service-state backup Database, persistent files, matching key and deployment configuration Restore the components together and check their settings
Workflow exports plus separately protected credentials Workflow JSON and separate credential exports, or credentials to recreate Import workflows and credentials, then check node references
Service-native export tools Records selected by n8n’s CLI export commands Check export scope, key requirements and import behavior

Choose the first when you need the existing database state. Choose exports when you want to move or rebuild selected automations.

For CLI exports, use an n8n environment connected to the intended database. Choose an existing protected output directory:

n8n export:workflow --all --output=backups/workflows.json
n8n export:credentials --all --output=backups/credentials.json

--all selects all records of that type. --output sends them to a file. Keep the matching key with encrypted credential exports. Check command success and confirm both output files exist. n8n CLI documentation

For migration to an installation with a different key, export:credentials --decrypted writes plaintext credential values. Protect that output, encrypt any retained copy and remove unnecessary plaintext files. Workflow and credential --backup exports cover those records rather than the whole service. n8n CLI documentation

docker exec n8n.example n8n export:workflow --all --output=/tmp/workflows.json
Error exporting workflows. See log messages for details.
No workflows found with specified filters

No workflows found means this fresh database has nothing to export.

Step 4: Check recovery before you need it

Plan a rehearsal using separate storage and a separate database. Start with the recorded n8n version to keep recovery and upgrading separate.

Before starting the recovered service:

  1. Restore the database and persistent files into the separate environment.
  2. Supply the matching encryption key.
  3. Check file permissions, mounts and database settings.
  4. Block access to production services and leave public webhooks disconnected.

Keep that isolation in place while reviewing workflows and triggers. For CLI imports, matching IDs can overwrite records. n8n CLI import documentation

Check recovery:

  • Do the expected workflows and credential entries appear?
  • Can a credential-dependent workflow authenticate against a controlled test service?

Allow access only to that controlled service for the check.

Record the backup date, key source, n8n version and test result. Investigate failures using a working copy while preserving the original backup.

Common questions

Why do my restored n8n workflows have broken credentials?

Check whether the restored service uses the original encryption key. The database may contain encrypted credentials even when the service has a different key. Restore the matching key source. If decryption works but authentication fails, check token expiry and permissions at the connected service. n8n encryption key documentation

Is backing up the n8n Docker volume enough?

For the default SQLite setup, the persistent volume holds the database and generated key. A key supplied separately needs its own backup. PostgreSQL needs a separate database backup. Check any additional storage configured for your deployment. n8n Docker documentation

Can I recover n8n credentials without the encryption key?

A new key cannot decrypt values protected by the old key. Look for the original persistent directory, deployment secret store and older backups. If the matching key is unavailable, recreate the credentials, select them in the affected nodes and test each workflow. n8n encryption key documentation

Does an n8n workflow export include saved passwords?

Use the separate credential export for saved credential records. A workflow export alone is insufficient. Review workflow JSON before sharing it, since secrets entered directly into node settings need separate attention. n8n CLI export documentation

Can I back up n8n while it is running?

Yes, with a consistent database backup method. Use SQLite’s online backup API or another documented SQLite backup method instead of an ordinary live file copy. PostgreSQL supports consistent dumps with pg_dump. Back up the persistent files and matching key as well. SQLite online backup documentation, PostgreSQL dump documentation

Should I change the n8n encryption key during a restore?

Keep the matching key for recovery. For a separate migration to another key, n8n documents decrypted credential exports. Those files contain plaintext secrets and need protected handling. n8n CLI documentation

Related: self-hosting guides · full guide index.

../self-hosting/ every Self-hosting guide