Backup n8n Workflows to GitHub
detail.loadingPreview
Automates the backup of all n8n workflows to a specified GitHub repository.
About This Workflow
This workflow is designed to systematically back up all your n8n workflows to a GitHub repository. It periodically scans your n8n instance, retrieves each workflow's JSON definition, and stores it as a JSON file in a designated GitHub repository. The filename is based on the workflow's ID, ensuring easy identification. The workflow also handles updates by comparing the current workflow definition with the one stored in GitHub, creating new files or updating existing ones as needed. This ensures a robust version control system for your automation setups.
Key Features
- Automated Backups: Schedules regular backups of all n8n workflows.
- GitHub Integration: Leverages GitHub API for secure and version-controlled storage.
- Selective Storage: Stores each workflow as a separate JSON file named
workflow_id.json. - Delta Detection: Compares existing GitHub files with current workflows to determine if a file is new, different, or the same.
- Conditional Operations: Creates new files or edits existing ones in the GitHub repository based on the comparison results.
- Configurable Repository: Allows easy configuration of GitHub owner, repository name, and path via a 'Globals' node.
- Error Handling: Includes basic checks for file retrieval and status comparison.
How To Use
Setup Instructions:
- Configure GitHub Credentials: Ensure your
GitHub accountcredential is set up and accessible by n8n. - Update 'Globals' Node: Navigate to the
Globalsnode (ID:d42ddc37-3bd9-4f19-8831-695bec4d0137).repo.owner: Enter your GitHub username.repo.name: Enter the name of your GitHub repository where backups will be stored.repo.path: Specify the folder within your repository. This folder will be created if it doesn't exist. For example,workflows/.
- Set Backup Schedule: Configure the
Schedule Triggernode (ID:2a139d59-1387-4899-88b3-21106cd01099) to your desired backup frequency (e.g., every 2 hours). - Execute: You can manually trigger the workflow by clicking the 'execute' button on the
On clicking 'execute'node (ID:42cc4260-626e-4f83-b1c3-c78c99b78b38) or rely on the scheduled trigger.
Workflow Explanation:
- The
Schedule TriggerorOn clicking 'execute'node initiates the backup process. - The
n8nnode (ID:82851e4a-33a1-461b-965f-f51efcb5af90) retrieves all workflows from your n8n instance. Loop Over Items(ID:d05e2a25-24be-43fb-baa4-9c3391840e70) iterates through each retrieved workflow.- For each workflow, the
Execute Workflownode (ID:8e5b3f71-0c5e-4e78-a3f7-0b574c9ddf06) is used to call the sub-workflow, passing the workflow's details. - The sub-workflow starts with
Execute Workflow Trigger(ID:5b1991f7-0351-44de-908d-9aa8b8262d60), which receives the workflow data. Globals(ID:d42ddc37-3bd9-4f19-8831-695bec4d0137) provides the GitHub repository configuration.Get file data(ID:c9bfa393-e120-4bfe-b957-702756b91aaf) attempts to fetch the existing workflow file from GitHub.If file too large(ID:08af670c-ac82-422f-9938-c649dfdfbcf6) checks if the GitHubget fileoperation returned an error or empty content. If it did, it proceeds toGet File(ID:11046021-89ba-4e61-b03f-d606e7dd0a56) which seems to be intended for binary file handling (though its use here for JSON is unconventional).Merge Items(ID:795fd895-94b2-46f1-b559-748b0db01c49) consolidates the data from the previous steps.isDiffOrNew(ID:3d3399f3-bbfb-48ab-8644-91b28e731026) is a code node that compares the original workflow JSON with the current n8n workflow JSON. It determines if the file isnew,different, orsameand prepares then8n_data_stringyfor GitHub.Check Status(ID:2f2f42d0-d27c-4856-a263-4d5e9eda2c4c) routes the workflow based on the comparison result.Same file - Do nothing(ID:5316029f-f32f-4a8d-95de-50ee57051a08) is a no-operation node for when no changes are detected.File is different(ID:37c5983b-48fe-41d5-8e3a-eb56dec2140b) leads to theEdit existing filenode.File is new(ID:a4dcce9e-b0d0-4b9e-ab16-9142e641c73d) leads to theCreate new filenode.Create new file(ID:03fcfdc4-2e52-42f0-a129-3ebaf8dd8fc1) uses the GitHub API to create a new file.Edit existing file(ID:dd35cc39-4ab4-4d53-b439-b425a2177e8f) uses the GitHub API to update an existing file.- The
Returnnode (ID:90cac8e2-9509-4d48-9038-bb653ffbdf9d) signifies the end of the sub-workflow execution for each item.
Apps Used
Workflow JSON
{
"id": "25a20f3a-7d13-4da2-bbda-34d431443fd7",
"name": "Backup n8n Workflows to GitHub",
"nodes": 22,
"category": "Backup & Recovery",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: 25a20f3a-7d13...
About the Author
Free n8n Workflows Official
System Admin
The official repository for verified enterprise-grade workflows.
Statistics
Related Workflows
Discover more workflows you might like
Universal CSV to JSON API Converter
Effortlessly transform CSV data into structured JSON with this versatile n8n workflow. Integrate it into any application as a custom API endpoint, supporting various input methods including file uploads and raw text.
Automate Local Business Outreach with AI-Powered Yelp Scraper
This workflow automates the process of scraping local business details from Yelp using AI, then leverages that data to send personalized partnership proposals via Gmail. It's perfect for sales and marketing teams looking to streamline lead generation and outreach campaigns.
Automate Getty Images Editorial Search & CMS Integration
This n8n workflow automates searching for editorial images on Getty Images, extracts key details and embed codes, and prepares them for seamless integration into your Content Management System (CMS), streamlining your content creation process.