serverserv serverserv

Back up n8n workflows to GitHub: free n8n workflow template

By the serverserv team · 3 min read · Updated

If you self-host n8n, your workflows are only as safe as your last backup. This workflow saves every workflow as its own JSON file in a private GitHub repository each night, so you have version history and can restore any workflow in a minute.

Download the template

Free download
7 nodes · tested on n8n 2.35 · MIT licence · no credentials included
Download JSON
yesnoEvery nightSchedule TriggerGet all workflowsn8n APIPrepare fileCodeDoes file exist?GitHubExists?IfUpdate fileGitHubCreate fileGitHub
How the workflow is wired, from the trigger at the top.

How it works

  1. Every night runs at 2:00.
  2. Get all workflows reads every workflow through n8n's own API.
  3. Prepare file builds a readable file name from the workflow name and ID.
  4. Does file exist? checks GitHub, then the workflow either updates the file or creates it, with a commit message naming the workflow.

Nodes used: Schedule Trigger, n8n API, Code, GitHub, If.

What you need

  • A private GitHub repository and a fine-grained token with Contents read and write on that repository only
  • An n8n API key (Settings, then n8n API)

Set it up

  1. Create a private repository, for example n8n-backups.
  2. In n8n, create an API key and add an n8n credential with your instance URL ending in /api/v1.
  3. Add a GitHub credential, then set the owner and repository name in Does file exist?, Update file and Create file.
  4. Run it once by hand and check the workflows folder in your repository, then activate it.

New to importing? In n8n, open a new workflow, then either paste the copied JSON onto the canvas or use the menu (the three dots) and choose Import from file. Credentials are never included, so you connect your own accounts after importing.

Ways to customise it

  • Also back up credentials' names (not secrets) or tags by adding more API calls.
  • Send yourself a Telegram message when the backup finishes, or only when it fails.
  • Run it hourly if you edit workflows a lot.

Security notes

Use a private repository and a token limited to that one repository. Exported workflows do not contain credential secrets, but they can contain webhook paths, IDs, URLs and notes. Also back up n8n's own data folder and encryption key; without the key, restored credentials cannot be decrypted.

Where to run it

Templates with webhooks or triggers need n8n running all the time and reachable over HTTPS. You can run n8n on your own computer to try it, but for real use it belongs on a server. serverserv n8n Hosting gives you n8n pre-installed on your own KVM server with HTTPS, from $14.99 a month with no execution limits, and we will set up your first workflow for you, this one included.

Questions

Does this back up my credentials?

No. n8n's API does not export credential secrets. Back up the n8n data folder and the encryption key separately for a full restore.

How do I restore a workflow?

Download the JSON file from GitHub and import it in n8n (Workflows, then Import from file), or paste it onto the canvas.

Is this n8n template free to use?

Yes. It is free under the MIT licence, for personal and business use. You need your own n8n instance and your own accounts for the connected apps.

Sources

Plans from $3.99/moSee plans