# How to Restore Deleted Workflows in n8n

- Tool: n8n
- Difficulty: Beginner
- Time required: 10-20 minutes
- Compatibility: n8n 1.0+ (self-hosted)
- Last updated: March 2026

## TL;DR

To restore a deleted workflow in n8n, check the execution history for recent runs that contain the workflow data, query the execution_entity table in the n8n database, or restore from a backup JSON file. n8n does not have a built-in trash or undo for deleted workflows, so prevention through regular backups is the best strategy.

## Recovering Deleted Workflows in n8n

When you delete a workflow in n8n, it is permanently removed from the workflow table. There is no recycle bin or undo button. However, you may still be able to recover the workflow through execution history records, direct database queries, or backup files. This tutorial covers all three recovery methods and shows you how to set up automated backups to prevent future data loss.

## Before you start

- Terminal access to the server running n8n
- Access to the n8n database (SQLite or PostgreSQL)
- Basic familiarity with SQL queries (for the database recovery method)

## Step-by-step guide

### 1. Check execution history for the deleted workflow's data

If the deleted workflow was executed before it was deleted, the execution records may still contain the workflow definition. Go to the Executions tab in the n8n sidebar. If execution data has not been pruned, you may find records from the deleted workflow. Click into an execution to see the full workflow data. However, n8n filters the execution list by existing workflows, so you may need to query the database directly to find executions of deleted workflows.

**Expected result:** You find an execution record that contains the workflow's node structure and connections.

### 2. Query the database for execution data containing the workflow

Connect to your n8n database and query the execution_entity table. Each execution record stores the complete workflow definition in the workflowData column. Even after a workflow is deleted, its execution records remain until pruned. Search for executions by the workflow name or by a known node name. Extract the workflowData JSON, clean it up, and use it to recreate the workflow.

```
-- PostgreSQL: Find executions of deleted workflows
SELECT id, "workflowId", "startedAt", "workflowData"
FROM execution_entity
WHERE "workflowData"::text LIKE '%YourWorkflowName%'
ORDER BY "startedAt" DESC
LIMIT 5;

-- SQLite: Same query with slightly different syntax
SELECT id, workflowId, startedAt, workflowData
FROM execution_entity
WHERE workflowData LIKE '%YourWorkflowName%'
ORDER BY startedAt DESC
LIMIT 5;
```

**Expected result:** The query returns execution records with the full workflow definition in the workflowData column.

### 3. Extract the workflow JSON and import it

Copy the workflowData JSON from the query result. This JSON contains the complete workflow definition including nodes, connections, and settings. Save it to a .json file. Then import it into n8n using the CLI command n8n import:workflow --input=recovered-workflow.json, or use the UI by going to Workflows > Import from File. The imported workflow will appear as a new workflow. You will need to reassign credentials to each node since credential references may not match.

```
# Save the extracted JSON to a file
# (paste the workflowData content into this file)
nano recovered-workflow.json

# Import using CLI
n8n import:workflow --input=recovered-workflow.json

# Or in Docker
docker cp recovered-workflow.json n8n:/tmp/
docker exec -it n8n n8n import:workflow --input=/tmp/recovered-workflow.json
```

**Expected result:** The recovered workflow appears in the n8n workflow list and can be edited and activated.

### 4. Restore from a backup JSON file

If you previously exported your workflows as JSON backups (which you should do regularly), simply import the backup file. Go to the n8n editor, click the menu icon, and select Import from File. Choose the backup JSON file for the deleted workflow. Alternatively, use the CLI command to import. This is the fastest and most reliable recovery method, but it only works if you have a recent backup.

```
# Import a single workflow from backup
n8n import:workflow --input=./backups/my-workflow.json

# Import all workflows from a backup directory
n8n import:workflow --input=./backups/ --separate
```

**Expected result:** The workflow is restored from the backup file with all nodes, connections, and settings intact.

### 5. Set up automated backups to prevent future data loss

Create an n8n workflow that automatically backs up all workflows on a schedule. Use a Schedule Trigger node to run daily, an HTTP Request node or Code node to call the n8n API and fetch all workflows, and a Write Binary File node or an FTP/S3 node to save the backup. Alternatively, create a cron job on the server that runs the n8n CLI export command daily and stores the files in a backup directory or cloud storage.

```
# Cron job for daily backups (add to crontab -e)
0 2 * * * n8n export:workflow --all --output=/backups/n8n/workflows/$(date +\%Y\%m\%d)/ 2>&1 >> /var/log/n8n-backup.log

# Docker version
0 2 * * * docker exec n8n n8n export:workflow --all --output=/tmp/backup/ && docker cp n8n:/tmp/backup/ /backups/n8n/$(date +\%Y\%m\%d)/
```

**Expected result:** A daily backup runs automatically, creating a timestamped directory with JSON exports of all workflows.

## Complete code example

File: `backup-workflow.js`

```javascript
// n8n Code node: Backup all workflows via internal API
// Use in a workflow with Schedule Trigger → Code → Write Binary File
// Mode: Run Once for All Items

const baseUrl = $env.WEBHOOK_URL || 'http://localhost:5678';
const apiKey = $env.N8N_API_KEY; // Set in n8n env vars

if (!apiKey) {
  throw new Error('N8N_API_KEY environment variable is not set. Enable API access in n8n settings.');
}

// Fetch all workflows via n8n API
const response = await this.helpers.httpRequest({
  method: 'GET',
  url: `${baseUrl}/api/v1/workflows`,
  headers: {
    'X-N8N-API-KEY': apiKey
  }
});

const workflows = response.data || response;
const timestamp = new Date().toISOString().split('T')[0];

// Create a single backup file with all workflows
const backup = {
  exportDate: new Date().toISOString(),
  n8nVersion: $env.N8N_VERSION || 'unknown',
  workflowCount: workflows.length,
  workflows: workflows
};

const backupJson = JSON.stringify(backup, null, 2);

// Return as binary for Write Binary File node
const binaryData = Buffer.from(backupJson, 'utf-8');

return [{
  json: {
    filename: `n8n-backup-${timestamp}.json`,
    workflowCount: workflows.length,
    backupSize: `${(binaryData.length / 1024).toFixed(1)} KB`
  },
  binary: {
    data: await this.helpers.prepareBinaryData(
      binaryData,
      `n8n-backup-${timestamp}.json`,
      'application/json'
    )
  }
}];
```

## Common mistakes

- **Assuming deleted workflows can be recovered from the n8n UI** — undefined Fix: n8n has no trash or undo for workflow deletion. Recovery requires database queries or backup files.
- **Having execution pruning enabled with a short retention period, destroying recovery data** — undefined Fix: Set EXECUTIONS_DATA_MAX_AGE to at least 168 hours (7 days) so execution data with workflow definitions is available for recovery.
- **Not backing up credentials alongside workflows** — undefined Fix: Run n8n export:credentials --all in addition to workflow exports. Credentials are needed for the recovered workflows to function.
- **Importing a recovered workflow without checking credential references** — undefined Fix: After importing, open each node and verify that credentials are correctly assigned. Credential IDs may differ between instances.

## Best practices

- Export all workflows as JSON backups at least once a week, preferably daily
- Store backups off-server in cloud storage like S3 or Google Cloud Storage
- Keep at least 30 days of backup history with timestamped directories
- Enable execution data saving so deleted workflows can be recovered from execution records
- Do not set aggressive execution pruning if you want recovery options for deleted workflows
- Use version control (Git) to track workflow changes and enable full history
- Test your backup restoration process regularly to ensure backups are valid

## Frequently asked questions

### Is there a way to undo a workflow deletion in n8n?

No. n8n does not have an undo feature for workflow deletion. Once a workflow is deleted, it is permanently removed from the workflow table. Recovery is only possible through execution history records, database backups, or exported JSON files.

### How long are execution records kept after a workflow is deleted?

Execution records follow your pruning settings (EXECUTIONS_DATA_MAX_AGE and EXECUTIONS_DATA_PRUNE_MAX_COUNT). If pruning is disabled, they are kept indefinitely. The execution records are not automatically deleted when the parent workflow is deleted.

### Can I recover a workflow from n8n Cloud?

On n8n Cloud, you do not have direct database access. Check the Executions tab for recent runs of the deleted workflow, or contact n8n support for assistance. Having exported JSON backups is the most reliable recovery method.

### Will the recovered workflow keep its original credentials?

The recovered workflow JSON references credentials by ID. If you restore on the same n8n instance with the same credentials, they may work automatically. If credential IDs have changed, you will need to manually reassign credentials in each node.

### How do I prevent accidental workflow deletions?

Set up role-based access control if available on your plan so that only admins can delete workflows. Always maintain automated backups. Consider using GitHub integration to version-control your workflows.

### Can RapidDev help me recover lost workflows and set up backup systems?

Yes, RapidDev can help recover workflows from database records and set up automated backup pipelines that export workflows daily to cloud storage, ensuring you never lose critical automation data.

---

Source: https://www.rapidevelopers.com/n8n-tutorial/how-to-restore-deleted-workflows-in-n8n
© RapidDev — https://www.rapidevelopers.com/n8n-tutorial/how-to-restore-deleted-workflows-in-n8n
