Learn how to restore deleted workflows in n8n by updating the 'deletedAt' field in the database or using the n8n REST API. Step-by-step guide included.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
To restore deleted workflows in n8n, you need to access the database where n8n stores workflow data, locate the deleted workflows in the workflow_entity table, and update their 'deletedAt' field to NULL. This process requires database access and SQL knowledge, and can be done through direct database manipulation or by using n8n's REST API depending on your setup.
Detailed Guide to Restore Deleted Workflows in n8n
Step 1: Understanding How n8n Handles Deleted Workflows
When you delete a workflow in n8n, it's not immediately purged from the database. Instead, n8n uses a "soft delete" approach where it sets a 'deletedAt' timestamp in the database record. This means that deleted workflows still exist in the database and can potentially be recovered.
Step 2: Prerequisites
Before you begin the restoration process, you'll need:
Step 3: Identify Your Database Type
n8n supports several database types, including:
Your approach may vary slightly depending on which database you're using.
Step 4: Connect to Your Database
For SQLite:
The database file is typically located in the n8n data directory. Use a tool like SQLite Browser to open the file.
For PostgreSQL:
Connect using pgAdmin or the psql command-line tool:
psql -h hostname -U username -d n8n\_database
For MySQL/MariaDB:
Connect using MySQL Workbench or the mysql command-line tool:
mysql -h hostname -u username -p n8n\_database
For MS SQL Server:
Use SQL Server Management Studio or the sqlcmd utility to connect.
Step 5: Locate Deleted Workflows
Once connected to your database, execute a query to find all deleted workflows:
SELECT id, name, active, deletedAt FROM workflow\_entity WHERE deletedAt IS NOT NULL;
This query will show you all workflows that have been deleted, along with their IDs, names, and when they were deleted.
Step 6: Restore a Specific Workflow
To restore a specific workflow, you'll need to set its 'deletedAt' field to NULL. Use the following SQL query, replacing [WORKFLOW_ID] with the actual ID of the workflow you want to restore:
UPDATE workflow_entity SET deletedAt = NULL WHERE id = [WORKFLOW_ID];
For example, to restore a workflow with ID 42:
UPDATE workflow\_entity SET deletedAt = NULL WHERE id = 42;
Step 7: Restore Multiple Workflows at Once
If you want to restore all deleted workflows:
UPDATE workflow\_entity SET deletedAt = NULL WHERE deletedAt IS NOT NULL;
To restore workflows deleted within a specific timeframe:
UPDATE workflow\_entity SET deletedAt = NULL
WHERE deletedAt BETWEEN '2023-01-01' AND '2023-01-31';
Step 8: Verify the Restoration
After executing the update query, verify that the workflows have been restored by running:
SELECT id, name, active FROM workflow_entity WHERE id IN ([WORKFLOW_ID1], [WORKFLOW\_ID2]);
Replace [WORKFLOW_ID1], [WORKFLOW_ID2], etc. with the IDs of the workflows you restored.
Step 9: Restart n8n (If Necessary)
In some cases, you might need to restart your n8n instance for the changes to take effect:
# If using pm2
pm2 restart n8n
# If using systemd
sudo systemctl restart n8n
# If running with Docker
docker restart n8n-container
Step 10: Alternative Method - Using n8n REST API
If you have admin access to n8n but not direct database access, you can use the n8n REST API to restore workflows. This method requires you to have an API key.
First, authenticate with the API:
curl -X POST \\
http://your-n8n-instance/rest/login \\
-H 'Content-Type: application/json' \\
-d '{
"email": "[email protected]",
"password": "your-password"
}'
This will return a session cookie that you'll use for subsequent requests.
Then, get a list of deleted workflows:
curl -X GET \\
http://your-n8n-instance/rest/workflows?includeDeleted=true \\
-H 'Cookie: sessionid=your-session-cookie'
Finally, restore a specific workflow:
curl -X PUT \\
http://your-n8n-instance/rest/workflows/[WORKFLOW\_ID]/restore \\
-H 'Cookie: sessionid=your-session-cookie'
Replace [WORKFLOW_ID] with the ID of the workflow you want to restore.
Step 11: Troubleshooting Common Issues
Issue: Workflow doesn't appear in n8n after restoration
Issue: Database errors during restoration
Issue: API method returns errors
Step 12: Preventive Measures for the Future
To avoid needing to restore workflows in the future:
Step 13: Understanding Database Schema Changes
Be aware that the database schema might change between n8n versions. Always check your specific version's database structure if the standard commands don't work. You can examine the schema with:
-- For PostgreSQL or MS SQL
SELECT column_name, data_type
FROM information\_schema.columns
WHERE table_name = 'workflow_entity';
-- For MySQL/MariaDB
DESCRIBE workflow\_entity;
-- For SQLite
PRAGMA table_info(workflow_entity);
Step 14: Special Considerations for Self-Hosted Environments
If you're using a self-hosted n8n instance, you might have additional options:
In some self-hosted configurations, you might be able to restore from a database backup instead of manipulating the current database directly.
Conclusion
Restoring deleted workflows in n8n is possible through direct database manipulation or API calls. The most straightforward method is to update the 'deletedAt' field in the workflow_entity table to NULL for the workflows you want to restore. Always back up your database before making changes, and verify that the restoration was successful by checking the n8n interface after restarting the service if necessary.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.