Automated Daily Backup of n8n Workflows to GitLab Repositories
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: Retrieve Workflows – Fetch all workflows from the n8n REST API.
Compare with GitLab – For each workflow, fetch the corresponding file from GitLab and compare the JSON.
Update if Changed – If differences exist, commit the updated workflow to GitLab using its API.
Setup
Before using the workflow, ensure the following:
Prerequisites: n8n**: Self-hosted instance with access to the /rest/workflows API.
GitLab**: A repository where workflows will be stored, and a Personal Access Token (PAT) with api and write_repository permissions.
n8n Nodes Required**: HTTP Request (to call n8n and GitLab APIs) Code or Function nodes (for diffing and formatting) Looping (SplitInBatches or similar)
Configuration: Set environment variables or workflow credentials for: GITLAB_TOKEN GITLAB_REPO GITLAB_BRANCH (e.g., main) GITLAB_FILE_PATH_PREFIX (e.g., n8n-workflows/)
How to Use
Import the Workflow into your n8n instance.
Configure GitLab API Credentials: Set the GitLab PAT as a header in the HTTP
Request node:
Private-Token: {{ $env.GITLAB_TOKEN }}
Map Workflows to GitLab Paths:
Use the workflow name or ID to create the file path. Example:
n8n-workflows/workflow-name.json
Trigger the Workflow: Can be manually triggered, or scheduled to run at intervals (e.g., daily).
Review Commits in GitLab:
Each updated workflow will be committed with a message like:
"Update workflow: Sample Workflow"
Disclaimer
This workflow does not handle merge conflicts or manual edits made directly in GitLab. Always ensure proper coordination if multiple sources are modifying workflows. Only structural changes are tracked. Non-functional metadata (like timestamps or IDs) may trigger false positives unless filtered. Use at your own risk. Test in a safe environment before applying to production workflows.
Related Templates
Automate Daily Keyword Research with Google Sheets, Suggest API & Custom Search
Who's it for This workflow is perfect for SEO specialists, marketers, bloggers, and content creators who want to automa...
USDT And TRC20 Wallet Tracker API Workflow for n8n
Overview This n8n workflow is specifically designed to monitor USDT TRC20 transactions within a specified wallet. It u...
Bulk Automated Google Drive Files Sharing and Direct Download Link Generation
This N8N workflow automates the process of sharing files from Google Drive. It includes OAuth2 authentication, batch pro...
🔒 Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments