Skip to main content
RapidDev - Software Development Agency
n8n-tutorial

How to Restore Deleted Workflows in n8n

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.

What you'll learn

  • How to recover a workflow from execution history data
  • How to query the n8n database directly for deleted workflow data
  • How to restore from a backup JSON file
  • How to set up automated backups to prevent future data loss
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner7 min read10-20 minutesn8n 1.0+ (self-hosted)March 2026RapidDev Engineering Team
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.

Prerequisites

  • 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.

typescript
1-- PostgreSQL: Find executions of deleted workflows
2SELECT id, "workflowId", "startedAt", "workflowData"
3FROM execution_entity
4WHERE "workflowData"::text LIKE '%YourWorkflowName%'
5ORDER BY "startedAt" DESC
6LIMIT 5;
7
8-- SQLite: Same query with slightly different syntax
9SELECT id, workflowId, startedAt, workflowData
10FROM execution_entity
11WHERE workflowData LIKE '%YourWorkflowName%'
12ORDER BY startedAt DESC
13LIMIT 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.

typescript
1# Save the extracted JSON to a file
2# (paste the workflowData content into this file)
3nano recovered-workflow.json
4
5# Import using CLI
6n8n import:workflow --input=recovered-workflow.json
7
8# Or in Docker
9docker cp recovered-workflow.json n8n:/tmp/
10docker 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.

typescript
1# Import a single workflow from backup
2n8n import:workflow --input=./backups/my-workflow.json
3
4# Import all workflows from a backup directory
5n8n 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.

typescript
1# Cron job for daily backups (add to crontab -e)
20 2 * * * n8n export:workflow --all --output=/backups/n8n/workflows/$(date +\%Y\%m\%d)/ 2>&1 >> /var/log/n8n-backup.log
3
4# Docker version
50 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 working example

backup-workflow.js
1// n8n Code node: Backup all workflows via internal API
2// Use in a workflow with Schedule Trigger → Code → Write Binary File
3// Mode: Run Once for All Items
4
5const baseUrl = $env.WEBHOOK_URL || 'http://localhost:5678';
6const apiKey = $env.N8N_API_KEY; // Set in n8n env vars
7
8if (!apiKey) {
9 throw new Error('N8N_API_KEY environment variable is not set. Enable API access in n8n settings.');
10}
11
12// Fetch all workflows via n8n API
13const response = await this.helpers.httpRequest({
14 method: 'GET',
15 url: `${baseUrl}/api/v1/workflows`,
16 headers: {
17 'X-N8N-API-KEY': apiKey
18 }
19});
20
21const workflows = response.data || response;
22const timestamp = new Date().toISOString().split('T')[0];
23
24// Create a single backup file with all workflows
25const backup = {
26 exportDate: new Date().toISOString(),
27 n8nVersion: $env.N8N_VERSION || 'unknown',
28 workflowCount: workflows.length,
29 workflows: workflows
30};
31
32const backupJson = JSON.stringify(backup, null, 2);
33
34// Return as binary for Write Binary File node
35const binaryData = Buffer.from(backupJson, 'utf-8');
36
37return [{
38 json: {
39 filename: `n8n-backup-${timestamp}.json`,
40 workflowCount: workflows.length,
41 backupSize: `${(binaryData.length / 1024).toFixed(1)} KB`
42 },
43 binary: {
44 data: await this.helpers.prepareBinaryData(
45 binaryData,
46 `n8n-backup-${timestamp}.json`,
47 'application/json'
48 )
49 }
50}];

Common mistakes when restoring Deleted Workflows in n8n

Why it's a problem: Assuming deleted workflows can be recovered from the n8n UI

How to avoid: n8n has no trash or undo for workflow deletion. Recovery requires database queries or backup files.

Why it's a problem: Having execution pruning enabled with a short retention period, destroying recovery data

How to avoid: Set EXECUTIONS_DATA_MAX_AGE to at least 168 hours (7 days) so execution data with workflow definitions is available for recovery.

Why it's a problem: Not backing up credentials alongside workflows

How to avoid: Run n8n export:credentials --all in addition to workflow exports. Credentials are needed for the recovered workflows to function.

Why it's a problem: Importing a recovered workflow without checking credential references

How to avoid: 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

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I accidentally deleted an important n8n workflow. I have a self-hosted instance with PostgreSQL. How do I query the database to find the workflow data in execution records and restore it?

n8n Prompt

Help me write a SQL query to find execution records for a deleted workflow named 'Customer Onboarding' in my n8n PostgreSQL database, then create an import command to restore it.

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.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.