Automate GitLab Backup with n8n Command Nodes

This workflow automates backing up n8n workflows and credentials to a GitLab repo on a schedule or manual trigger, saving hours and avoiding data loss. Learn step-by-step how to use command nodes in n8n to export, commit, and push your backups effortlessly.
manualTrigger
executeCommand
cron
Workflow Identifier: 1421
NODES in Use: Manual Trigger, Execute Command, Cron

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

1. Opening Problem Statement

Meet Sarah, a busy automation specialist managing multiple workflows in n8n for her team. She manually exports workflows and credentials regularly to keep backups safe in GitLab, spending hours every week running CLI commands and risking human errors. Even with her careful approach, she sometimes misses backups, risking workflow downtime and losing valuable automation configurations.

Sarah needs a reliable, hands-off solution to regularly backup her n8n workflows and credentials to GitLab without any manual intervention. Missing a backup by just one day means risking days of lost productivity and errors that cost her team time and money — roughly estimated at 3-4 hours weekly manually exporting and committing backups.

2. What This Automation Does

This n8n workflow fully automates backing up your n8n workflows and credentials to a GitLab repository using command execution nodes. Here’s what happens when it runs:

  • Automatically exports all n8n workflows into a designated folder inside your repository.
  • Exports all credential data securely into another folder in your GitLab repo.
  • Runs git add to stage all the updated backup files automatically without manual input.
  • Commits the staged files with a timestamped commit message for version tracking.
  • Pushes the commit to the remote GitLab repository so backups are safely stored off-site.
  • Scheduled cron trigger runs this backup routine 4 times daily (midnight, 6 AM, noon, 6 PM) for near real-time backup cadence.

This setup saves Sarah about 3-4 hours weekly, eliminates manual command errors, and ensures her backup workflow is fully reproducible with detailed commit logs.

3. Prerequisites ⚙️

  • n8n account set up and access to your n8n instance where workflows and credentials exist.
  • GitLab repository configured to store backups, including git credentials set up on your n8n server or environment.
  • Basic knowledge of CLI commands as this workflow uses Execute Command nodes.
  • No additional external apps needed beyond GitLab and n8n (no email, APIs, or databases involved).
  • Optional: If you want to self-host your n8n instance, platforms like Hostinger provide easy deployment setups (Hostinger n8n hosting).

4. Step-by-Step Guide

Step 1: Set Up Your Trigger Node

Navigate to Triggers → Cron node inside n8n. Configure it to run backups 4 times a day as shown: set trigger times at 0, 6, 12, and 18 hours (midnight, 6 AM, noon, 6 PM). This ensures automated regular backups without manual intervention.

Visual: You should see the cron node scheduled with these exact trigger hours.

Common mistake: Forgetting to add multiple times or incorrect time zone settings — verify the server timezone aligns with your schedule.

Step 2: Add Manual Trigger for On-Demand Backups

For instant backups, add a Manual Trigger node named “On clicking ‘execute’”. Connect it to start the backup flow when manually triggered.

Expected outcome: When you click “Execute” on this node, it kicks off the full backup automation.

Common mistake: Not connecting this node to the backup sequence disables manual execution.

Step 3: Export n8n Workflows with Execute Command

Add an Execute Command node called “Export Workflows”. Enter this command exactly:

npx n8n export:workflow --backup --output repo/workflows/

This command exports all workflows to the repo/workflows directory relative to your current n8n environment path.

After running this node, you should see files dumped into the specified folder ready to be committed.

Common mistake: Running this outside the n8n project path or lacking node_modules can fail the command.

Step 4: Export Credentials Securely

Next, add another Execute Command node named “Export Credentials”. Use this command:

npx n8n export:credentials --backup --output repo/credentials/

This exports credential files alongside your workflows, keeping all backup data comprehensive.

Common mistake: Forgetting to keep credentials secure or misplacing their output folder.

Step 5: Stage Backup Files with Git Add

Add an “Execute Command” node titled “git add” with:

git -C repo add .

This stages all changed files in the repo folder for commit.

Visual confirmation: no errors means git is tracking your backup updates.

Common mistake: Running this outside the repo folder or without proper git setup causes failure.

Step 6: Commit Backups with Timestamp Message

Add another “Execute Command” node labeled “git commit” with command:

=git -C repo commit -m "Auto backup ({{ new Date().toISOString() }})"

The timestamp ensures clear versioning for each backup commit.

Common mistake: Empty commit errors mean no changes detected, verify previous nodes executed properly.

Step 7: Push Changes to GitLab

Lastly, add a “git push” Execute Command node with:

git -C repo push

This finalizes the push to your remote GitLab repository.

Common mistake: Network issues or missing credentials on the n8n server cause push errors.

5. Customizations ✏️

  • Change Backup Frequency: Adjust the Cron node trigger times to run hourly or weekly. For example, modify the Cron schedule or add/remove hours as needed.
  • Backup Folder Paths: Amend the output folders in the Export Workflows and Export Credentials Execute Command nodes to save backups in different repo subfolders.
  • Commit Message Format: Edit the commit message in the git commit node to include your project or any other custom tags for clarity.
  • Add Email Notification: Integrate a Gmail or SMTP email node after the git push to notify your team when backups succeed.

6. Troubleshooting 🔧

Problem: “git commit” shows “nothing to commit, working tree clean”

Cause: No changes detected because workflow or credential export commands did not update any files.

Solution: Confirm the export commands run properly and output files get updated before staging.

Problem: “git push” fails due to authentication errors

Cause: Your n8n server isn’t correctly authenticated with GitLab to push commits.

Solution: Make sure your git SSH keys or access tokens are set up properly in the environment where n8n runs.

7. Pre-Production Checklist ✅

  • Verify n8n CLI commands work manually on your server before adding them in Execute Command nodes.
  • Ensure git commands execute correctly on your repository from the n8n environment.
  • Test both manual and cron triggers to validate workflow runs without errors.
  • Backup folders called repo/workflows and repo/credentials must exist or be creatable by commands.

8. Deployment Guide

Once verified, activate the workflow by toggling it to Active in n8n. Your scheduled cron will handle automated backups seamlessly from now on.

For manual backups, simply trigger the “On clicking ‘execute’” manual node anytime you want an immediate backup.

Monitor recent executions in n8n’s execution log for troubleshooting or verifying success.

9. FAQs

  • Can I use GitHub instead of GitLab? Yes, just update git remote URLs and credentials accordingly.
  • Does this workflow consume API credits? No, it uses local CLI commands and git operations.
  • Is my credential data safe? Yes, credentials are exported locally then pushed to your private GitLab repo. Protect repo access carefully.
  • Can this handle many workflows and credentials? Yes, but test git repo size limits for very large backups.

10. Conclusion

By implementing this n8n workflow, Sarah transformed her tedious manual backup task into a fully automated, reliable process that runs 4 times a day plus on-demand. This saved her team hours weekly, eliminated mistakes, and provided well-documented backups with timestamps.

Next, Sarah plans to add notification emails after backup and integrate backup encryption for enhanced security. You can also explore integrating this backup workflow with Slack alerts or expanding it for PostgreSQL database backups.

Take control of your n8n backup processes today with this straightforward GitLab automation and enjoy peace of mind for your critical workflow data.

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation in n8n

A complete beginner guide to building an AI-powered SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free