Skip to main content
0 reactions

How to Set Up and Run the Workflow Backup for n8n

Card titled Set Up the n8n Workflow Backup, labelled n8n Tutorial setup guide, showing a clock, a steps node, a document and a folder linked in a row, with the notes n8n 2.49.7 in Docker, Runs every night at 2:00, and Key can only list workflows.

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

Step 1: Unzip the Source Code

Open Terminal and go to the folder that holds the zip, such as Downloads:

TerminalBash
cd ~/Downloads

Unzip it:

TerminalBash
unzip workflow-backup-n8n-1.0.0.zip

It creates a folder named workflow-backup-n8n. Go into it:

TerminalBash
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:

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

compose.yml (excerpt)YAML
      - ./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:

TerminalBash
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:

Output (the lines that matter)Plain text
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.

The n8n Set up owner account form with the email user@example.com, the first name Demo, the last name User, a password shown as dots and the Next button.
Create the owner account of your new n8n.

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:

The n8n Settings page with n8n API selected under Integrations, the API heading, and an empty box that says Control n8n programmatically using the n8n API with a Create API key button.
Settings › n8n API, before any key exists.

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 workflow in the search box, and tick only workflow:list. That’s all the backup needs: the key can list your workflows, and nothing else.
The Create API Key dialog with the label Workflow backup, Expiration set to Never, Scopes set to Custom with 1 of 119 scopes selected, and only workflow:list ticked in the list filtered by workflow.
A key that never expires and can only list workflows.

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:

A new n8n workflow named My workflow with its menu open at Import, and the submenu showing From URL and From file.
⋯ › Import › From file on a new workflow.

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

The n8n dialog Importing this from an AI tool? with a Don’t show again checkbox and the buttons Skip and Connect n8n.
Click Skip.

The workflow opens with its four steps:

The imported Workflow backup with four nodes in a row: Nightly schedule, Get all workflows with a red warning sign, One file per workflow (Convert to JSON) and Save to the backups folder (Write File to Disk).
The imported workflow. Get all workflows still needs its key.
  • 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:

The parameters of the Get all workflows node: Credential with a Connect to n8n button, Resource Workflow, Operation Get Many, Return All turned on and no filters.
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. Keep 5678 even if you changed the port in .env: n8n calls itself inside its container.
The new credential n8n account of type n8n API with the API key shown as dots, the Base URL http://localhost:5678/api/v1 and Allowed HTTP Request Domains set to All.
The key as dots and the Base URL of n8n’s API.

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

The parameters of the Get all workflows node with the credential n8n account selected, Resource Workflow, Operation Get Many and Return All turned on.
The node now uses the n8n account credential.

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:

The Workflow backup after a run, every node green with a tick: 1 item from Nightly schedule, then 3 items through Get all workflows, One file per workflow and Save to the backups folder.
Three workflows, three files.

Open the backups folder in Finder, or list it in Terminal:

TerminalBash
ls backups
OutputPlain text
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:

The n8n dialog Workflow published saying that the schedule trigger will now trigger executions on the schedule you have defined, with a Got it button.
Published: the backup now runs every night.

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:

The Nightly schedule node with Trigger Interval Days, Days Between Triggers 1, Trigger at Hour 2am and Trigger at Minute 0.
Every day at 2:00. Change the hour and minute here.

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:

TerminalBash
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:

TerminalBash
docker compose exec n8n n8n import:workflow --separate --input=/home/node/.n8n-files/backups/restore
Output (the lines that matter)Plain text
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:

TerminalBash
rm -r backups/restore

Clean Up

To stop n8n, and the nightly backup with it, run this in the folder:

TerminalBash
docker compose down

It stops n8n and removes its container:

Output (the lines that matter)Plain text
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

ProblemCauseFix
Cannot GET / in the browsern8n is still startingReload the page
Problem in node ‘Save to the backups folder‘: The file or directory does not existn8n can’t see the backups folderStart 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 toKeep 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 credentialsThe API key was revokedCreate 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 APIThe Base URL lacks /api/v1Use http://localhost:5678/api/v1
port is already allocated when n8n startsAnother app, such as another n8n, uses port 5678Add 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, Docker and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by n8n GmbH.

0 comments