⚙️ Automatic workflow & credentials backup to GitHub with change detection

5,979 views · ⚙️ DevOps & CI/CD

Description

This n8n workflow template uses community nodes and is only compatible with the self-hosted version of n8n.

Title: n8n Credentials and Workflows Backup on Change Detection

Purpose: Never lose track of your n8n changes again! This workflow smartly backs up all your workflows and credentials, automatically detects any changes using hash comparison, and pushes updates to GitHub—but only when something has actually changed. Set your own interval and stop cluttering your repo with redundant commits.

Walkthrough Video on YouTube

image.png


Trigger:

image.png


Workflow Backup Process:

  1. Set Workflow Path: Defines the local backup file path for workflows.

  2. Get Old Workflow Hash: Executes a helper workflow to retrieve the previous hash.

  3. Execute Workflow Backup: Runs n8n export:workflow to export all workflows to the defined file path.

  4. Get New Workflow Hash: Executes a helper workflow to generate the new hash from the exported file.

  5. Compare Hashes (If Workflow Updated): Checks if the new hash differs from the old one.

  6. If Updated:

    • Read Workflow DataExtract TextPush to GitHub: Reads, extracts, and commits the updated workflow JSON to GitHub under a timestamped filename.

Credential Backup Process:

  1. Set Credential Path: Defines the local backup file path for credentials.

  2. Get Old Credential Hash: Executes a helper workflow to retrieve the previous hash.

  3. Execute Credential Backup: Runs n8n export:credentials to export all credentials.

  4. Get New Credential Hash: Executes a helper workflow to generate the new hash from the exported file.

  5. Compare Hashes (If Credential Updated): Checks for changes.

  6. If Updated:

    • Read Credential DataExtract TextPush to GitHub: Commits the new credentials JSON to GitHub if changes are found.

Hash Generator (Helper Flow): Used in both workflow and credential backup paths:


GitHub Integration:


Change Detection Logic:

Error Handling:

🔗 Nodes Used

GitHub, Execute Sub-workflow, Execute Workflow Trigger, Schedule Trigger, Read/Write Files from Disk, Extract from File

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup