# How to Export Workflows from n8n

- Tool: n8n
- Difficulty: Beginner
- Time required: 5 minutes
- Compatibility: n8n 0.170+ (self-hosted, Docker, n8n Cloud)
- Last updated: March 2026

## TL;DR

Export workflows from n8n using the UI or the CLI. In the editor, open a workflow and select Menu then Download to save it as a JSON file. For bulk exports, use the n8n export:workflow --all command to export every workflow at once. These JSON files can be version-controlled, backed up, or imported into another n8n instance.

## Why Export Workflows from n8n

Exporting workflows is essential for backups, version control, and migrating between n8n instances. Every n8n workflow is stored as a JSON object that describes nodes, connections, credentials references, and settings. When you export a workflow, you get a portable file you can share, commit to Git, or import into a different server. This tutorial covers both the visual UI method for single workflows and the CLI method for bulk exports.

## Before you start

- A running n8n instance with at least one saved workflow
- Terminal access for CLI exports (self-hosted only)
- Basic knowledge of JSON files and file management

## Step-by-step guide

### 1. Export a single workflow from the UI

Open the workflow you want to export in the n8n editor. Click the three-dot menu icon in the top bar, then select Download. n8n saves the workflow as a JSON file to your browser's default download location. The file name matches the workflow name. This method works on both self-hosted and n8n Cloud instances. The exported file contains all node configurations, connections, and settings but does not include credential secrets — only credential references.

**Expected result:** A JSON file is downloaded to your computer containing the full workflow definition. The file can be opened in any text editor to inspect the structure.

### 2. Export all workflows using the CLI

For self-hosted n8n, the CLI provides a bulk export command. This exports every workflow in the database to individual JSON files in a specified directory. Each file is named with the workflow ID. This is the fastest way to create a full backup of all workflows. The CLI reads from the same database n8n uses, so make sure n8n has been started at least once to initialize the database.

```
# Create a backup directory
mkdir -p ~/n8n-backups/workflows

# Export all workflows
n8n export:workflow --all --output=~/n8n-backups/workflows/

# Export a specific workflow by ID
n8n export:workflow --id=5 --output=~/n8n-backups/workflows/workflow-5.json
```

**Expected result:** Individual JSON files are created in the backup directory, one per workflow. Each file contains the complete workflow definition.

### 3. Export workflows from Docker

When n8n runs in a Docker container, use docker exec to run the CLI inside the container. Make sure to specify the correct container name or ID. You can copy the exported files from the container to your host machine using docker cp, or mount a volume to write directly to the host filesystem.

```
# Export all workflows inside the container
docker exec -it n8n n8n export:workflow --all --output=/home/node/.n8n/backups/

# Copy the backup folder to the host
docker cp n8n:/home/node/.n8n/backups/ ~/n8n-backups/
```

**Expected result:** Workflow JSON files are exported inside the container and then copied to your host machine for safekeeping.

### 4. Automate exports with a cron job

Set up a cron job to automatically export workflows on a schedule. This creates timestamped backup directories so you have a history of workflow versions. Combine this with git commits to maintain full version control over your workflow definitions.

```
# Add to crontab (crontab -e)
# Export all workflows daily at 2 AM
0 2 * * * BACKUP_DIR=~/n8n-backups/$(date +\%Y-\%m-\%d) && mkdir -p $BACKUP_DIR && n8n export:workflow --all --output=$BACKUP_DIR/
```

**Expected result:** A new dated backup directory is created daily containing all workflow JSON files. Old backups are preserved for history.

### 5. Organize exports for Git version control

For teams, store exported workflows in a Git repository. This gives you change history, code review for workflow modifications, and easy rollback. Create a repository structure with a workflows directory and commit each export. Use meaningful commit messages that describe what changed in the workflows.

```
# Initialize a Git repo for workflow backups
mkdir -p ~/n8n-workflows-repo/workflows
cd ~/n8n-workflows-repo
git init

# Export and commit
n8n export:workflow --all --output=~/n8n-workflows-repo/workflows/
git add workflows/
git commit -m "Backup n8n workflows $(date +%Y-%m-%d)"
```

**Expected result:** Workflow JSON files are tracked in Git. You can view change history with git log and revert to any previous version.

## Complete code example

File: `backup-n8n-workflows.sh`

```bash
#!/bin/bash
# backup-n8n-workflows.sh
# Automated n8n workflow backup script with Git versioning

set -euo pipefail

# Configuration
BACKUP_DIR="${HOME}/n8n-workflows-repo"
WORKFLOW_DIR="${BACKUP_DIR}/workflows"
LOG_FILE="${BACKUP_DIR}/backup.log"
DATE=$(date +%Y-%m-%d_%H-%M-%S)

# Create directories if they don't exist
mkdir -p "${WORKFLOW_DIR}"

# Initialize Git repo if not already initialized
if [ ! -d "${BACKUP_DIR}/.git" ]; then
  cd "${BACKUP_DIR}"
  git init
  echo "backup.log" > .gitignore
  git add .gitignore
  git commit -m "Initialize workflow backup repository"
fi

# Export all workflows
echo "[${DATE}] Starting workflow export..." >> "${LOG_FILE}"

if n8n export:workflow --all --output="${WORKFLOW_DIR}/" 2>> "${LOG_FILE}"; then
  echo "[${DATE}] Export successful" >> "${LOG_FILE}"
else
  echo "[${DATE}] Export failed" >> "${LOG_FILE}"
  exit 1
fi

# Commit changes if there are any
cd "${BACKUP_DIR}"
if [ -n "$(git status --porcelain)" ]; then
  git add workflows/
  git commit -m "Workflow backup ${DATE}"
  echo "[${DATE}] Changes committed to Git" >> "${LOG_FILE}"
else
  echo "[${DATE}] No changes detected" >> "${LOG_FILE}"
fi

echo "[${DATE}] Backup complete" >> "${LOG_FILE}"
```

## Common mistakes

- **Assuming exported workflows include credential secrets** — undefined Fix: Credential secrets are never included in exports. After importing, you must reconnect or re-enter credentials in the new instance.
- **Running the CLI export command while n8n is not installed globally** — undefined Fix: If you installed n8n with npx, use npx n8n export:workflow instead. For Docker, use docker exec to run the command inside the container.
- **Overwriting previous backups by exporting to the same directory without timestamps** — undefined Fix: Use timestamped directories (e.g., backups/2026-03-27/) or Git commits to preserve backup history.
- **Not testing that exported workflows can be imported successfully** — undefined Fix: Periodically import your backups into a test n8n instance to verify they are valid and complete.

## Best practices

- Export workflows before upgrading n8n to a new version as a safety net
- Store exported JSON files in a Git repository for full change history and rollback capability
- Automate daily exports with a cron job so you never lose more than a day of work
- Test your exports by importing them into a staging n8n instance to verify they work
- Note that exported files do not contain credential secrets — you must re-enter credentials after importing
- Use descriptive workflow names so exported file names are meaningful
- Keep at least 30 days of backup history before cleaning up old exports

## Frequently asked questions

### Do exported workflows include my API keys and credentials?

No. Exported workflow JSON files contain credential references (IDs) but never the actual secrets. After importing a workflow into a new instance, you must re-enter or reconnect all credentials.

### Can I export workflows from n8n Cloud?

Yes. Use the UI method: open the workflow, click the three-dot menu, then select Download. The CLI export method is not available on n8n Cloud since you do not have terminal access.

### What format are exported workflows in?

Workflows are exported as standard JSON files. Each file contains the complete workflow definition including nodes, connections, settings, and metadata.

### Can I export a workflow and import it into an older version of n8n?

Workflows exported from a newer n8n version may use node types or settings that do not exist in older versions. This can cause import errors or missing node warnings. Always try to match versions.

### How do I export just one workflow by its ID using the CLI?

Use n8n export:workflow --id=YOUR_WORKFLOW_ID --output=./my-workflow.json to export a single workflow. Replace YOUR_WORKFLOW_ID with the numeric ID shown in the workflow URL.

### Can RapidDev help set up automated n8n workflow backups?

Yes. RapidDev can configure automated backup pipelines with Git versioning, offsite storage, and monitoring for your n8n deployment. Reach out for a free consultation.

---

Source: https://www.rapidevelopers.com/n8n-tutorial/how-to-export-workflows-from-n8n
© RapidDev — https://www.rapidevelopers.com/n8n-tutorial/how-to-export-workflows-from-n8n
