Skip to main content
The n8n CLI provides powerful commands for importing and exporting workflows and credentials. This is useful for backups, migrations, version control, and moving data between environments.

Export Workflows

Export workflows from your n8n instance to JSON files.

Basic Usage

n8n export:workflow --id=WORKFLOW_ID --output=file.json

Export Flags

--all
boolean
default:"false"
Export all workflows from the database.
--id
string
The ID of a specific workflow to export.
--output
string
Output file path or directory (when using --separate).
--pretty
boolean
default:"false"
Format JSON output for easier reading.
--separate
boolean
default:"false"
Export each workflow to a separate file. Requires --output to be a directory.
--backup
boolean
default:"false"
Shortcut that enables --all --pretty --separate. Only requires --output.
--version
string
The version ID to export (for workflow versioning).
--published
boolean
default:"false"
Export the published/active version of workflows.

Export Examples

Export one workflow:
n8n export:workflow --id=5 --output=workflow.json
With pretty formatting:
n8n export:workflow --id=5 --output=workflow.json --pretty

Import Workflows

Import workflows from JSON files into your n8n instance.

Basic Usage

n8n import:workflow --input=file.json

Import Flags

--input
string
required
Input file path or directory (when using --separate).
--separate
boolean
default:"false"
Import all *.json files from the specified directory.
--userId
string
Assign imported workflows to a specific user ID.
--projectId
string
Assign imported workflows to a specific project ID.

Import Examples

Import one workflow file:
n8n import:workflow --input=workflow.json
Ownership Rules: You cannot use --userId and --projectId together. If a workflow already exists and is owned by another user/project, the import will fail to prevent accidental ownership changes.

Export Credentials

Export credentials from your n8n instance.
Security Warning: By default, credentials are exported in encrypted form. Use the --decrypted flag only when migrating between instances with different encryption keys.

Basic Usage

n8n export:credentials --id=CREDENTIAL_ID --output=file.json

Export Credential Flags

--all
boolean
default:"false"
Export all credentials from the database.
--id
string
The ID of a specific credential to export.
--output
string
Output file path or directory (when using --separate).
--pretty
boolean
default:"false"
Format JSON output for easier reading.
--separate
boolean
default:"false"
Export each credential to a separate file.
--backup
boolean
default:"false"
Shortcut that enables --all --pretty --separate.
--decrypted
boolean
default:"false"
Export credentials in plain text. USE WITH CAUTION! All sensitive information will be visible.

Export Credential Examples

Export one credential (encrypted):
n8n export:credentials --id=5 --output=credential.json

Import Credentials

Import credentials from JSON files into your n8n instance.

Basic Usage

n8n import:credentials --input=file.json

Import Credential Flags

--input
string
required
Input file path or directory (when using --separate).
--separate
boolean
default:"false"
Import all *.json files from the specified directory.
--userId
string
Assign imported credentials to a specific user ID.
--projectId
string
Assign imported credentials to a specific project ID.

Import Credential Examples

Import one credential file:
n8n import:credentials --input=credential.json
Encryption Handling: If you import decrypted credentials (plain text), n8n automatically encrypts them using the instance’s encryption key before storing.

Migration Workflow

Same Encryption Key

If both instances use the same encryption key:
# On source instance
n8n export:workflow --backup --output=/backup/workflows/
n8n export:credentials --backup --output=/backup/credentials/

Different Encryption Keys

If instances have different encryption keys:
# On source instance
n8n export:workflow --all --output=workflows.json
n8n export:credentials --all --decrypted --output=credentials-plain.json
Security Best Practice: Always delete decrypted credential files immediately after import. Never commit them to version control or store them unencrypted.

Backup Strategy

Recommended backup approach:
#!/bin/bash

# Set backup directory with timestamp
BACKUP_DIR="/backups/n8n/$(date +%Y-%m-%d)"
mkdir -p "$BACKUP_DIR"

# Export workflows
n8n export:workflow --backup --output="$BACKUP_DIR/workflows/"

# Export credentials (encrypted)
n8n export:credentials --backup --output="$BACKUP_DIR/credentials/"

# Create compressed archive
tar -czf "$BACKUP_DIR.tar.gz" "$BACKUP_DIR"

# Remove uncompressed backup
rm -rf "$BACKUP_DIR"

echo "Backup completed: $BACKUP_DIR.tar.gz"

Version Control Integration

Export workflows for Git version control:
# Export with pretty formatting and separate files
n8n export:workflow \
  --all \
  --separate \
  --pretty \
  --output=workflows/

# Add to git
git add workflows/
git commit -m "Update workflow definitions"
git push
Never commit credentials to version control! Only export and version control workflows. Store credentials separately using secure secret management.

Export/Import Best Practices

  • Schedule automated daily/weekly backups
  • Store backups in multiple locations
  • Test restore procedure regularly
  • Keep backups for at least 30 days
  • Never export decrypted credentials unless necessary
  • Delete decrypted files immediately after use
  • Store backup files securely with encryption
  • Use separate credentials for each environment
  • Use --pretty --separate for readable diffs
  • Only commit workflows, never credentials
  • Review changes before committing
  • Tag releases with version numbers
  • Test migration in staging first
  • Verify workflow IDs and references
  • Check credential mappings
  • Update environment-specific values

Troubleshooting

Problem: Workflow/credential already exists with different owner.Solution: Remove --userId or --projectId flag to keep existing ownership, or delete the existing item first.
Problem: Imported credentials don’t work in target instance.Solutions:
  • Ensure same encryption key if importing encrypted
  • Use --decrypted export if keys are different
  • Re-enter credentials manually if issues persist
Problem: Output directory doesn’t exist.Solution: Create directory first or n8n will create it automatically.

Next Steps

CLI Commands

View all CLI commands

User Management

Manage users via CLI

Configuration

Configure n8n settings

Backup & Restore

Complete backup strategies