Automated n8n Workflow Backup to GitHub Repository
Overview
This workflow automatically backs up every workflow in your n8n instance to a dedicated GitHub repository. It runs on a configurable schedule (or manually) and ensures that all your workflow JSON files are version-controlled and safely stored in a structured folder. The backup process intelligently handles both new workflows (creates a file) and existing ones (updates the file), making it ideal for disaster recovery, collaboration, or tracking changes over time.
Step-by-Step Node Breakdown
- Schedule Trigger (No additional auth) — Triggers the workflow on a recurring interval. By default it runs hourly, but you can customize the schedule (e.g., daily at midnight) to suit your needs. Also supports manual execution via the Manual Trigger node.
- Manual Trigger (No auth) — Provides a manual button to run the backup immediately, useful for testing or on-demand backups.
- Get many workflows (Internal n8n API, no external credentials) — Fetches a list of all workflows from your n8n instance using the built-in n8n node. No separate API key is required; it uses the same authentication as your n8n session.
- Loop Over Items (No auth) — Iterates over each workflow in the list one at a time. This node processes workflows sequentially, preventing race conditions.
- Getafile (GitHub, OAuth2 / Personal Access Token) — Attempts to retrieve the existing workflow file from your GitHub repository at the path
workflows/{workflow-name}.json. If the file does not exist (i.e., a new workflow), the node’s error output is triggered. The expression infilePathsanitizes the workflow name by replacing invalid characters (<>:"|?*), converting->toto, and normalizing spaces. - Convert to File1 (No auth) — Converts the retrieved GitHub file’s binary data back to a JSON object so it can be compared or overwritten.
- Extract from File1 (No auth) — Extracts the JSON content from the binary file, preparing it for an update operation.
- Edit a file (GitHub, OAuth2 / Personal Access Token) — If the workflow already exists on GitHub, this node updates the file with the latest JSON from your n8n instance. The commit message is dynamically generated (e.g.,
MyWorkflow-updated). - Convert to File (No auth) — Converts the current n8n workflow JSON into a binary file (
.json) with the workflow’s name as the filename. - Create a file (GitHub, OAuth2 / Personal Access Token) — If the workflow is new (i.e.,
Getafileerror output), this node creates a new file in theworkflows/folder. The commit message includes the workflow name and-update.
The workflow loops back to the Loop Over Items node to process the next workflow. The Sticky Note at the top serves as a comment.
Setup Instructions
- GitHub account — You need a GitHub account and a repository (e.g.,
n8n-backup) to store the backups. Create an empty repository or use an existing one. - GitHub credential in n8n — Add a GitHub OAuth2 or Personal Access Token credential in n8n under Credentials > GitHub. Ensure the token has
reposcope (or at leastcontents: writeandcontents: read). - Configure the nodes —
- In Get many workflows, no changes needed.
- In Getafile, Create a file, and Edit a file, update the
ownerandrepositoryfields to match your GitHub username and repo name. - Optionally adjust the Schedule Trigger interval (set hours/minutes as desired).
- Error handling — The workflow references an external error workflow (
nkikA5CaVjEKdIIR). If you don’t have that, you should either create a simple error handler or remove theerrorWorkflowsetting in the workflow settings.
Use Cases & Adaptations
- Disaster recovery — Restore all workflows by downloading the JSON files from GitHub and importing them back into n8n.
- Version history — Track changes to workflows over time via GitHub commits and diffs.
- Multi-instance sync — Modify the workflow to run on multiple n8n instances, pushing to the same repo (be cautious with conflicts).
- Selective backup — Add a filter node after
Get many workflowsto only backup workflows with a specific tag or name pattern. - Notification — Insert a Slack or email node after the loop to notify you when a backup completes or if an error occurs.
11 nodesmanual triggerDevOps
N8nSplit In BatchesConvert To FileGithubExtract From FileSticky Note
Workflow JSON
{
"name": "All Workflow Backup to GitHub",
"nodes": [
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-160,
336
],
"id": "b91b0ed2-380f-49f7-b8fa-7596cd0c68e7",
"name": "When clicking ‘Execute workflow’"
},
{
"parameters": {
"filters": {},
"requestOptions": {}
},
"type": "n8n-nodes-base.n8n",
"typeVersion": 1,
"position": [
64,
288
],
"id": "0230a4c7-6bb8-4a80-8ba8-4c070d1e21d0",
"name": "Get many workflows"
},
{
"parameters": {
"rule": {
"interval": [
{}
]
}
},
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [
-160,
144
],
"id": "76af76ea-b753-4447-9ee9-cf980b85bf12",
"name": "Schedule Trigger"
},
{
"parameters": {
"options": {}
},
"type": "n8n-nodes-base.splitInBatches",
// ... truncated (copy to see full JSON)How to Import This Workflow
- 1Copy the workflow JSON above using the Copy Workflow JSON button.
- 2Open your n8n instance and go to Workflows.
- 3Click Import from JSON and paste the copied workflow.
Don't have an n8n instance? Start your free trial at n8nautomation.cloud