Automated Backup and Deletion Sync for Workflows using GitHub - n8n Workflow

Secure your critical n8n workflow assets with this robust, scheduled automation. It backs up all active n8n templates to GitHub and automatically handles deletion synchronization.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • n8n users requiring robust, offsite backup for their critical automation assets.

  • DevOps teams managing self-hosted or cloud n8n instances who need version control.

  • Users looking for a high-reliability n8n workflow template that handles updates and deletions.

  • Automation Specialists seeking advanced examples of using the n8n node for workflow management.

Overview

Maintaining reliable backups of your crucial business automation logic is essential. This advanced n8n workflow addresses the challenge of managing both active and deleted workflow definitions by synchronizing them with a GitHub repository.

Unlike simple backups, this n8n template doesn't just save new files; it performs a deep comparison of existing backups and current active n8n workflow versions. By using a specialized Code n8n node to canonicalize and compare the JSON structure, it only commits changes if the workflow logic has genuinely been altered, saving API calls and maintaining a clean history. Furthermore, it checks the GitHub repository against the list of active n8n workflows, automatically issuing a file deletion command for any workflows that have been removed from your n8n instance. This ensures your GitHub backup repository perfectly mirrors your active n8n system.

How it Works

This n8n workflow operates in a recursive loop structure, optimized to handle many workflows efficiently:


  1. Trigger: The process starts daily via the Schedule Trigger or manually via the On clicking 'execute' n8n trigger.

  2. Preparation: The Globals n8n node sets the target GitHub repository owner and name. The workflow then fetches all active n8n workflows (Get many workflows) and lists all current files in the GitHub repository (List files).

  3. Recursion/Batching: The workflow uses a subworkflow architecture (Execute Workflow) called via the Execute Workflow Trigger to process each item (active workflow or existing GitHub file) individually, which helps reduce memory usage during large operations.

  4. Routing (Switch): Items are routed based on their origin ('n8n' for active workflows, 'github' for existing backup files).

  5. Handling Active n8n Workflows:

It attempts to fetch the existing file from GitHub (Get file data).
The isDiffOrNew Code n8n node performs a deep comparison between the current active n8n workflow JSON and the backed-up GitHub version. It determines the status: 'new', 'different', or 'same'.
Based on status, a Switch node directs the flow to either Create new file (for new n8n templates), Edit existing file (for updated n8n templates), or does nothing (Same file - Do nothing).

  1. Handling Deleted Workflows:

If the item originated from GitHub, the isDeleted Code n8n node checks if its ID exists in the list of active n8n workflows.
* If deleted, the Delete a file GitHub n8n node executes, removing the corresponding backup file from the repository, completing the synchronization.

Installation Guide

To deploy this specialized n8n template, follow these steps:


  1. Import: Copy the provided JSON and import it into your n8n instance as a new n8n workflow.

  2. Credentials:

Set up a GitHub OAuth2 credential with necessary permissions (repo scope) for the GitHub n8n node operations (create, edit, delete files).
Set up an n8n API credential linked to your n8n instance, allowing the workflow to read its own active workflows.

  1. Configuration (Globals Node): Open the Globals n8n node (ID: e6675677) and update the values:

repo.owner: Your GitHub username (e.g., john-doe).
repo.name: The name of your GitHub repository designated for n8n workflow backups (e.g., n8n-backup).

  1. Activation: Enable the workflow. It is set to run daily via the Schedule Trigger, but you can execute it manually once to test the initial sync.

Node Details

Schedule Trigger: The primary n8n trigger, configured to initiate the backup process daily at 7 AM.
n8n Node (Get many workflows): Retrieves a list of all active n8n workflows from the running instance, providing the data necessary for backup and deletion checks. It uses the required n8n API credential.
GitHub Node (List files, Get file data, Create/Edit/Delete file): This critical n8n node interacts with the GitHub API. It lists existing backups, fetches file content for comparison, and performs the necessary file operations (creating new backups, updating changed n8n templates, or deleting retired workflows).
Code Node (isDiffOrNew): Contains custom JavaScript logic. It is responsible for decoding Base64 content from GitHub, ordering JSON keys to ensure deterministic comparison, and comparing the current active n8n workflow against the backup to accurately determine if a file is 'new', 'same', or 'different'.
Code Node (isDeleted): Checks if a file listed in the GitHub repository corresponds to an active n8n workflow ID. If the ID is missing, the n8n template flags it for deletion synchronization.
Execute Workflow Node: Crucial for the recursive design, this n8n node executes the workflow logic per item, optimizing performance and memory usage for synchronizing large numbers of n8n templates.

Related n8n Workflows

Free

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

Featured*