⚙️ Automated daily backup of n8n workflows to GitLab repositories

2,459 views · ⚙️ DevOps & CI/CD

Description

n8n Workflow: Sync Workflows with GitLab

How It Works

This workflow ensures that your self-hosted n8n workflows are version-controlled in a GitLab repository. It compares each current workflow from n8n with its stored counterpart in GitLab. If any differences are detected, the GitLab file is updated with the latest version.

Core Logic:

  1. Retrieve Workflows – Fetch all workflows from the n8n REST API.

  2. Compare with GitLab – For each workflow, fetch the corresponding file from GitLab and compare the JSON.

  3. Update if Changed – If differences exist, commit the updated workflow to GitLab using its API.


Setup

Before using the workflow, ensure the following:

Prerequisites:

Configuration:


How to Use

  1. Import the Workflow into your n8n instance.

  2. Configure GitLab API Credentials:

    • Set the GitLab PAT as a header in the HTTP

Request node:
Private-Token: {{ $env.GITLAB_TOKEN }}

  1. Map Workflows to GitLab Paths:

    • Use the workflow name or ID to create the file path. Example:
      n8n-workflows/workflow-name.json
  2. Trigger the Workflow:

    • Can be manually triggered, or scheduled to run at intervals (e.g., daily).
  3. Review Commits in GitLab:

    • Each updated workflow will be committed with a message like:
      "Update workflow: Sample Workflow"

Disclaimer


🔗 Nodes Used

GitLab, n8n, Schedule Trigger, Extract from File

📥 Import

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

📖 Importing guide · 🔑 Credential setup