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
How it works
- Every night runs at 2:00.
- Get all workflows reads every workflow through n8n's own API.
- Prepare file builds a readable file name from the workflow name and ID.
- 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
- Create a private repository, for example n8n-backups.
- In n8n, create an API key and add an n8n credential with your instance URL ending in /api/v1.
- Add a GitHub credential, then set the owner and repository name in Does file exist?, Update file and Create file.
- 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
Related
Error alerts on Telegram
get a Telegram message with the workflow name, failed node, error and a link whenever any n8n workflow fails.
n8n templateView →Website form to Google Sheets and Slack
send website contact form leads to Google Sheets and Slack, with email validation and a reply to the form.
n8n templateView →AI reply drafts for Gmail
Free n8n workflow that writes an AI reply draft for every new Gmail message and saves it in the same thread. N
n8n templateView →