Automated Daily Workflow Backup to GitHub Repository - n8n Workflow

Learn how to use this robust n8n workflow template to automatically back up all your active n8n workflows daily to a dedicated GitHub repository using the internal n8n API node.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

n8n Users needing reliable disaster recovery and version control.
System Administrators managing a self-hosted n8n instance.
Developers who integrate n8n workflow designs into their CI/CD pipelines.
Anyone looking for advanced examples of using the internal n8n node.

Overview

Maintaining reliable backups of your automation logic is essential. This specialized n8n workflow provides a robust solution for developers and system administrators by automatically exporting every active n8n workflow definition and committing it to a specified GitHub repository.

Triggered by a regular schedule, this n8n automation ensures that all your critical n8n templates are version-controlled externally. It intelligently checks if a file already exists in GitHub, performing an 'Update file' (edit) operation if it does, or an 'Upload file' (create) operation if it is a new n8n workflow. This mechanism prevents duplicated files and keeps the repository clean, making this a crucial n8n workflow template for operational resilience.

How it Works

The execution of this comprehensive n8n workflow follows a precise sequence to ensure accurate backup and version control:


  1. Start Trigger: The process initiates via a Schedule Trigger n8n node, setting the frequency (e.g., daily) for the backup routine.

  2. Retrieve Existing Backups: The workflow first uses a GitHub n8n node to retrieve a list of existing workflow backup file names currently stored in the repository. These names are then aggregated.

  3. Fetch Live Data: The core step involves the internal n8n n8n node, which connects to the local API to retrieve the raw JSON data for every active n8n workflow on the instance.

  4. Data Preparation: The JSON data for each individual n8n workflow is converted into a temporary file format, then immediately encoded into a Base64 string—a requirement for GitHub's file creation API.

  5. Metadata Setting: A Set n8n node dynamically generates the file name (based on the workflow's name and tag) and the commit date, ensuring unique and descriptive entries.

  6. Conditional Check: An If n8n node compares the newly generated file name against the list of existing files retrieved in Step 2. This determines if the file needs to be updated or created.

  7. Commit Action (Update or Create): If the file exists, the GitHub n8n node executes an 'Update file' operation. If it is a new n8n workflow, the GitHub n8n node performs an 'Upload file' operation, thus completing the automated backup.

Installation Guide

To deploy this automated n8n workflow backup solution, follow these steps:


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

  2. Configure Credentials: You will need two main credentials:

GitHub Credentials: Configure an OAuth2 or Personal Access Token connection for the GitHub n8n node. This token requires permissions to read and write content to the target repository.
Internal n8n API Token: The Retrieve workflows n8n node uses the internal n8n API. If your instance requires authentication (which is highly recommended), you must set up an API Key credential for the n8n node itself.

  1. Set GitHub Parameters: In the GitHub n8n nodes (List files from repo, Update file, Upload file):

Specify the target GitHub repository (repository).
Specify the GitHub organization/user owner name (owner).

  1. Activate Trigger: Ensure the Schedule Trigger n8n node is enabled and set to your desired execution frequency (e.g., once daily).

  2. Enable Workflow: Save and activate the n8n workflow to begin the automated backups.

Node Details

Schedule Trigger (n8n trigger):
Function: Serves as the starting n8n trigger, initiating the backup routine on a recurring schedule.
Key Configuration: Set to run at a specific interval (e.g., every 24 hours).
List files from repo (GitHub n8n node):
Function: Retrieves the names of all files currently stored in the backup repository for comparison.
Key Configuration: Resource set to File, Operation set to List.
Aggregate (n8n node):
Function: Consolidates all the retrieved file names from GitHub into a single item list for efficient searching.
Retrieve workflows (n8n node):
Function: Uses the internal n8n API to fetch the JSON definition of every active n8n workflow instance.
Key Configuration: Resource set to Workflow, Operation set to Get All.
Json file & To base64 (n8n node):
Function: Converts the raw n8n workflow JSON data into a Base64 string, required for committing files via the GitHub API.
Commit date & file name (Set n8n node):
Function: Dynamically creates two variables: commitDate (for the message) and fileName (structured using expressions like {{ $().json.name.replace(/\s+/g, '-').toLowerCase() }}-{{ $().json.tags[0].name }}.json).
Check if file exists (If n8n node):
Function: Performs a crucial check to see if the dynamically generated fileName is present in the aggregated list of existing files.
Update file / Upload file (GitHub n8n node):
* Function: Handles the final commit to GitHub. 'Update file' modifies an existing backup; 'Upload file' creates a new backup for a new n8n workflow.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by
Hugo
Hugo

Featured*