You have the source code of Workflow Backup for n8n. This guide takes it from the zip file to a published nightly backup on your own computer: every night at 2:00 in your time zone, it saves each of your n8n workflows as a JSON file in a folder you can open, and you can restore any of them later.
By the end, the Workflow backup workflow is published, and the backups folder holds one file for each of your workflows.
Cost: free. Everything runs on your own computer, with no outside accounts. n8n’s Community Edition costs nothing to self-host. Docker Desktop (opens in a new tab) is free for personal use, education and small businesses (fewer than 250 employees and less than $10 million in yearly revenue); larger companies need a paid Docker subscription.
Every screen and output on this page is real, run with n8n 2.49.7 and Docker Desktop on macOS.
Get the Source Code
Get the complete source code of Workflow Backup for n8n on Dewiride Store → (opens in a new tab)
The archive holds the workflow and the Docker Compose file this guide sets up and runs.
Prerequisites
- Docker Desktop (opens in a new tab), installed and running.
Step 1: Unzip the Source Code
Open Terminal and go to the folder that holds the zip, such as Downloads:
cd ~/Downloads
Unzip it:
unzip workflow-backup-n8n-1.0.0.zip
It creates a folder named workflow-backup-n8n. Go into it:
cd workflow-backup-n8n
The folder holds the workflow in workflows, compose.yml for n8n, .env.example with two optional settings, an empty backups folder and a README.
Step 2: Set Your Time Zone
The backup runs at 2:00 in n8n’s time zone and dates each file in it, and n8n starts out on New York time. Save yours in the settings file .env, with your own time zone in place of Asia/Kolkata:
echo "GENERIC_TIMEZONE=Asia/Kolkata" > .env
It creates .env with that one line. Time zone names look like Europe/London or America/Chicago; How to Set the Time Zone in n8n explains them.
Step 3: Start n8n
Already run n8n 2 in Docker? Add the line below under volumes: of its n8n service, so n8n can write the backups to a backups folder next to its compose.yml. Run docker compose up -d there, then skip to Step 5.
- ./backups:/home/node/.n8n-files/backups
compose.yml runs n8n 2.49.7 in Docker, reachable only from your computer, with the time zone from .env. It also connects the backups folder to the one place inside n8n where workflows may save files. Start it:
docker compose up -d
docker compose reads compose.yml in this folder, and up -d starts n8n in the background. If the n8n image isn’t on your computer yet, Docker downloads it first. When the last line says Started, n8n is running:
Volume workflow-backup-n8n_n8n_data Created
Network workflow-backup-n8n_default Created
Container workflow-backup-n8n-n8n-1 Started
Step 4: Create Your Owner Account
Open http://localhost:5678 in your browser. If it says Cannot GET /, n8n is still starting: reload the page. The first time, n8n asks for an owner account: enter your email address, name and a password, and click Next.

n8n then asks a few questions. Answer or skip them until n8n opens. How to Install n8n with Docker shows each of these screens.
Step 5: Create an API Key That Can Only List Workflows
The backup reads your workflows through n8n’s own API, so it needs an API key. Click your name at the bottom of the left sidebar, then Settings, and choose n8n API under Integrations. Click Create API key:

Fill in the dialog:
- Label:
Workflow backup. - Expiration: Never. The backup needs the key every night, and a key that expires would stop the backup on that date. You can still revoke the key at any time on this page.
- Scopes: choose Custom, type
workflowin the search box, and tick only workflow:list. That’s all the backup needs: the key can list your workflows, and nothing else.

Click Save. n8n shows the key once and never again: click the copy button next to it, keep the key for Step 7, and click Done. How to Create an n8n API Key explains scopes in more depth.
Step 6: Import the Workflow
Click + at the top of the left sidebar, then New workflow. In the new workflow, click ⋯ next to its name, then Import › From file, and choose workflows/workflow-backup.json in the unzipped folder:

n8n asks whether the file comes from an AI tool. Click Skip:

The workflow opens with its four steps:

- Nightly schedule starts it every night at 2:00.
- Get all workflows gets every workflow through the n8n API.
- One file per workflow turns each workflow into a JSON file named after the workflow, its ID and the date.
- Save to the backups folder saves the files in
backups.
The warning on Get all workflows means it has no key yet.
Advertisement
Step 7: Connect the Key
Double-click Get all workflows, then click Connect to n8n:

In the new credential:
- API Key: paste the key from Step 5. n8n shows it as dots.
- Base URL:
http://localhost:5678/api/v1. Keep5678even if you changed the port in.env: n8n calls itself inside its container.

Click Save. n8n tests the key, closes the window and shows the credential n8n account in the node:

Part 6 of the n8n Tutorial explains credentials step by step.
Step 8: Run a Backup Now
Close the node and click Execute workflow. Each node turns green, with one item for each of your workflows. This n8n holds three workflows, so it saved three files:

Open the backups folder in Finder, or list it in Terminal:
ls backups
Daily report (nYpK5qpnSoGjboNz) 2026-11-27.json
Order webhook (1rjP5k7I3k5LYb5f) 2026-11-27.json
Workflow backup (yZ76Q3r99yZHbzO9) 2026-11-27.json
Each file is one complete workflow, named after it, its ID in brackets and the date. The ID keeps two workflows with the same name apart. Credentials appear in the files only by name; their keys and passwords never leave n8n.
Step 9: Publish the Workflow
Click Publish at the top right, then Publish in the dialog, and Got it:

From now on, the backup runs every night at 2:00. How to Publish a Workflow in n8n explains publishing.
If n8n Is Off at 2:00
On a laptop, n8n is often off at 2:00. When n8n starts again, the backup runs once to catch up. In a test with n8n stopped over the backup time, the missed backup ran 18 seconds after n8n started. To skip missed backups instead, open Nightly schedule, choose Settings and set If Execution Is Missed to Don’t Run Missed Executions.
Change the Time
Double-click Nightly schedule, change Trigger at Hour and Trigger at Minute, close it and publish again:

Restore a Workflow
One Workflow
Create a new workflow and import the backup file, exactly as in Step 6. The workflow opens as it was on that day. Publish it if it should run on its own.
Every Workflow from One Day
Copy that day’s files to a restore folder inside backups, with your date in place of 2026-11-27:
mkdir backups/restore
cp backups/*2026-11-27.json backups/restore/
Then import them with n8n’s command line. docker compose exec n8n runs a command inside the n8n container, and n8n import:workflow --separate imports every file in the folder:
docker compose exec n8n n8n import:workflow --separate --input=/home/node/.n8n-files/backups/restore
Importing 3 workflows...
Deactivating workflow "Workflow backup".
Successfully imported 3 workflows.
A workflow that still exists with the same ID is replaced by its backup. Every restored workflow comes back unpublished, as the Deactivating line shows, so open the ones that should run on their own, Workflow backup included, and click Publish. Then delete the restore folder:
rm -r backups/restore
Clean Up
To stop n8n, and the nightly backup with it, run this in the folder:
docker compose down
It stops n8n and removes its container:
Container workflow-backup-n8n-n8n-1 Removed
Network workflow-backup-n8n_default Removed
Your workflows stay in Docker’s n8n_data volume and your backups in the backups folder, so docker compose up -d brings everything back.
Warning: docker compose down -v also deletes the volume, with every workflow and credential in it. It can’t be undone. The files in backups stay.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Cannot GET / in the browser | n8n is still starting | Reload the page |
Problem in node ‘Save to the backups folder‘: The file or directory does not exist | n8n can’t see the backups folder | Start n8n with this folder’s compose.yml, or add the volume line from Step 3 to your own n8n and run docker compose up -d |
Problem in node ‘Save to the backups folder‘: Access to the file is not allowed. | The folder path in the node was changed to a place n8n 2 doesn’t let workflows write to | Keep the path under /home/node/.n8n-files/, as in /home/node/.n8n-files/backups/ |
Problem in node ‘Get all workflows‘: Authorization failed - please check your credentials | The API key was revoked | Create a new key (Step 5), click the pencil next to n8n account in the node, paste the key and click Save |
Couldn’t connect with these settings: The Base URL does not point to the n8n API | The Base URL lacks /api/v1 | Use http://localhost:5678/api/v1 |
port is already allocated when n8n starts | Another app, such as another n8n, uses port 5678 | Add N8N_PORT=5701 (or another free port) to .env and run docker compose up -d --force-recreate; Fixed: port is already allocated explains it |
FAQ
Does the backup include my credentials?
No. Each file names the credentials its workflow uses, by name and ID, but their keys and passwords stay encrypted inside n8n. n8n’s own command line can export credentials as well; n8n’s backup guide below explains how.
How much space do the backups take?
Each file is the size of one workflow: here 750 bytes for an empty workflow and about 3 KB for the four-step Workflow backup. A published workflow’s file is about twice as large, because n8n’s API also returns its published version.
What happens if the backup runs twice in one day?
The second run replaces that day’s files, because they have the same names. Files from other days stay.
Does it delete old backups?
No. Delete old files whenever you no longer need them.
Conclusion
Your n8n now backs up every workflow each night, one JSON file per workflow, with a key that can only list workflows. When a workflow breaks, import its file from a day it worked; after a bigger loss, restore a whole day with one command.
Additional Resources
- n8n node (opens in a new tab) (n8n docs)
- Convert to File (opens in a new tab) (n8n docs)
- Read/Write Files from Disk: file locations (opens in a new tab) (n8n docs)
- Authentication for the n8n API (opens in a new tab) (n8n docs)
- Back up and restore (opens in a new tab) (n8n docs)
Related
- n8n Tutorial — Part 6: Credentials: Connect n8n to Your Apps
- How to Create an n8n API Key
- How to Install n8n with Docker
n8n, Docker and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by n8n GmbH.
0 comments