Automated Daily Workflow Backup to GitHub - n8n Workflow

Use this robust n8n workflow to automatically backup all your active n8n workflows to a GitHub repository, ensuring version control and disaster recovery for every n8n template.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • n8n users running self-hosted instances who require disaster recovery.

  • Automation developers needing version control for their n8n templates and custom solutions.

  • Technical managers who need auditable logs of changes to their critical business n8n workflows.

  • Anyone seeking a differential backup solution for their n8n data.

Overview

Maintaining reliable backups for custom automation solutions is crucial. This advanced n8n workflow solves the critical problem of workflow loss by providing automated, differential version control for all your deployed n8n templates. The system intelligently checks for changes between the live n8n workflow and the last saved version on GitHub. It uses the dedicated n8n node to retrieve data, ensuring that only modified or newly created n8n workflows trigger a push to the repository, minimizing API usage and maximizing efficiency. Furthermore, it incorporates Discord notifications, providing real-time visibility into the backup status of every n8n workflow.

How it Works

This comprehensive n8n workflow operates in two main phases: the main loop and the sub-workflow execution.


  1. Trigger & Initialization: The process begins with either a Schedule Trigger (weekly in this template) or a manual n8n trigger. A Discord message is immediately sent via the Discord n8n node, indicating the start of the backup run.

  2. Workflow Retrieval: The primary n8n node queries the internal n8n API to fetch metadata for all active n8n workflows in the instance.

  3. Looping and Execution: The results are split into batches using the Loop Over Items n8n node. For each individual n8n workflow, the main workflow executes a self-call to an 'Execute Workflow' n8n node, which initiates the sub-workflow process for that single item. Wait n8n nodes are used after the sub-workflow call to manage Discord rate limits before sending success or failure notifications.

  4. Sub-Workflow Logic: The 'Execute Workflow Trigger' receives the single n8n workflow data.

  5. Configuration and Pathing: A Config n8n node prepares the data, setting repository details and structuring the n8n workflow JSON for backup. The 'Create sub path' n8n node determines the dated file path (e.g., yyyy/MM/dd).

  6. Differential Check: A GitHub n8n node attempts to retrieve any existing backup file for the current n8n workflow ID. The core logic resides in a Code n8n node (verifyTheDifference), which uses underscore.js to perform a deep comparison (_.isMatch) between the current n8n workflow data and the existing GitHub file content.

  7. Routing: A Switch n8n node routes the flow based on the comparison status: 'new', 'same', or 'different'.

  8. GitHub Action: If the status is 'new', a new file is created using the GitHub n8n node. If the status is 'different', the existing file is updated using the GitHub n8n node's 'Edit' operation. If 'same', no action is taken.

  9. Completion: After all items in the loop are processed, a final summary notification is sent via a Discord n8n node, confirming the successful backup of all targeted n8n templates.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON and import it into your n8n instance via the Workflows section (New > Import from JSON).

  2. API Credentials Setup (n8n node):

The 'n8n' node requires an n8n API Key credential. This key must have permissions to read workflow data across your instance. Configure this credential for the 'n8n' n8n node.

  1. GitHub Credentials Setup:

The GitHub n8n node requires a GitHub Personal Access Token (PAT). This token must have the repo scope enabled to allow reading, writing, and modifying files in the target repository. Configure this credential for the relevant GitHub n8n node instances.

  1. Discord Credentials Setup:

All Discord n8n nodes require a Discord Bot API credential to send notifications. Configure this for all Discord nodes ('Starting Message', 'Inform Success Flows', 'Inform Failed Flows', 'Completed Notification').

  1. Configuration Node Customization:

Open the 'Config' n8n node (located in the sub-workflow section).
Set the repoowner value to your GitHub username.
Set the repo
name value to the name of the repository designated for the n8n workflow backups. This repository must already exist.

  1. Activation: Ensure the n8n workflow is active to begin scheduled execution via the n8n trigger, or execute it manually using the 'On clicking 'execute'' n8n trigger.

Node Details

Schedule Trigger / Manual Trigger: The starting point of this automation. Allows the user to run the n8n workflow on a defined schedule or on-demand.
n8n (API) Node: Fetches a list of all current n8n workflows in the system using an internal API key. This is the source data for all n8n templates being backed up.
Loop Over Items: Breaks the list of workflows retrieved by the n8n node into individual items, initiating a loop for processing each n8n workflow sequentially.
Execute Workflow: Crucial for recursion. It calls the current n8n workflow as a sub-workflow for each item, isolating the processing and error handling for each unique n8n workflow backup attempt.
Config (Set Node): Used in the sub-workflow to define global variables like repoowner and reponame, and to structure the incoming n8n workflow JSON payload.
GitHub Node (Get file data): Attempts to fetch the existing backup file from GitHub using the n8n workflow ID and the current date path. Configured to continue on failure if the file is new.
Code Node (verifyTheDifference): The core logic comparison. It deserializes the existing GitHub file (if found) and compares it with the latest n8n workflow data using the _.isMatch function from underscore.js to determine if the file status is 'new', 'same', or 'different'.
Switch Node: Routes the execution path based on the 'githubStatus' output from the Code n8n node.
GitHub Node (Create new file / Edit existing file): Performs the necessary action (creation or modification) on the GitHub repository, committing the full n8n workflow JSON file with a commit message indicating the status and the n8n workflow name.
Discord Node: Used extensively to send notifications about the start, individual success/failure, and overall completion of the n8n workflow execution, ensuring transparency throughout the backup process.

Related n8n Workflows

Free

Nodes: 16 Nodes
Updated: December 26 2025
View all
Created by
Dat Proto
Dat Proto

Featured*