Who is this workflow for? This workflow automates the backup of your n8n workflows and credentials to a Git repository. By leveraging the n8n export command combined with git diff, the workflow ensures that backups are created only when changes are detected, optimizing storage and version control..

What does this workflow do?

  • Setup Repository:
  • Create a remote Git repository on platforms like GitHub, GitLab, or a private server.
  • Clone the repository to the server where n8n is hosted: bash cd /path/to/n8n git clone <repository_url> repo
  • Alternatively, initialize a new Git repository and add the remote: bash cd /path/to/n8n git init git remote add origin <repository_url>
  • Configure Git:
  • Ensure Git is configured with the necessary user credentials: bash git config user.name "Your Name" git config user.email "[email protected]"
  • Create an initial empty commit and push to the remote repository: bash cd repo git commit --allow-empty -m "Initial commit" git push -u origin master
  • Export Workflows and Credentials:
  • Use the n8n export commands to back up workflows and credentials: bash npx n8n export:workflow --backup --output ./repo/workflows/ npx n8n export:credentials --backup --output ./repo/credentials/
  • Commit and Push Changes:
  • Navigate to the repository directory, add changes, commit, and push to the remote: bash cd ./repo git add . git commit -m "Backup: Exported latest workflows and credentials" git push
  • Automate with Cron:
  • Schedule the workflow to run at desired intervals using cron. The workflow will only create commits when changes are detected, ensuring efficient backups.
  • Credentials Encryption:
  • By default, credentials are exported in an encrypted format. To export them in plain text, add the --decrypted flag: bash npx n8n export:credentials --backup --output repo/credentials/ --decrypted
  • It is recommended to retain encrypted credentials and securely store the encryption key.

🤖 Why Use This Automation Workflow?

  • Automated Backups: Eliminates the need for manual backup processes, reducing the risk of data loss.
  • Version Control: Maintains a history of changes, allowing you to track modifications and revert if necessary.
  • Efficiency: Commits are only created when changes are detected, minimizing unnecessary repository clutter.

👨‍💻 Who is This Workflow For?

This workflow is ideal for:

  • Developers and DevOps Engineers: Managing and maintaining n8n instances with version-controlled workflows.
  • Organizations: Ensuring that critical automation workflows and credentials are securely backed up.
  • Freelancers and Small Teams: Simplifying the backup process without extensive technical overhead.

🎯 Use Cases

  1. Continuous Integration: Automatically back up and version control workflows as part of a CI/CD pipeline.
  2. Disaster Recovery: Quickly restore workflows and credentials from a Git repository in case of system failures.
  3. Collaboration: Enable multiple team members to collaborate on workflows with a clear history of changes and updates.

TL;DR

This workflow provides an efficient and automated solution for backing up n8n workflows and credentials to a Git repository. By integrating export commands with Git operations, it ensures that your automation assets are securely versioned and easily recoverable, enhancing reliability and collaboration.

Help us find the best n8n templates

About

A curated directory of the best n8n templates for workflow automations.