AI Template Search
N8N Bazar

Find n8n Templates with AI Search

Search thousands of workflows using natural language. Find exactly what you need, instantly.

Start Searching Free
Oct 5, 2025

Backup n8n Workflows to Gitea (Automated Guide)

Backup n8n Workflows to Gitea (Automated Guide) Every powerful automation you build in n8n represents time saved, problems solved, and ideas turned into reality. Losing that work or not knowing what changed between versions can slow your momentum and make you cautious about experimenting. Imagine instead that every workflow you create is safely versioned, backed […]

Backup n8n Workflows to Gitea (Automated Guide)

Backup n8n Workflows to Gitea (Automated Guide)

Every powerful automation you build in n8n represents time saved, problems solved, and ideas turned into reality. Losing that work or not knowing what changed between versions can slow your momentum and make you cautious about experimenting.

Imagine instead that every workflow you create is safely versioned, backed up, and ready to roll back at any time. You can iterate boldly, refine your automations, and scale your systems with confidence.

This guide walks you through an n8n workflow template that automatically backs up all your n8n workflows to a Gitea Git repository. It runs on a schedule, checks for changes, encodes workflow JSON, and either creates or updates files in your Gitea repo. Think of it as a safety net for your automations and a foundation for more advanced workflow management.

The problem: fragile automations and invisible changes

As your n8n usage grows, so does the risk of:

  • Accidental deletions or overwrites
  • Breaking changes that are hard to undo
  • No clear history of who changed what and when
  • Manual exports that take time and are easy to forget

Without a reliable backup and version control strategy, you may hesitate to improve existing workflows or try new ideas. That hesitation costs time and slows your growth.

The mindset shift: treat workflows like code

When you start treating n8n workflows as valuable assets, not disposable experiments, everything changes. Version control, backups, and repeatable processes become part of your automation culture.

By exporting workflows to Gitea, you:

  • Gain a complete version history for every automation
  • Create a transparent audit trail for teams and stakeholders
  • Make it easy to roll back or compare versions
  • Lay the groundwork for CI/CD and more advanced DevOps practices

This template is not just about backup. It is about giving yourself permission to build, experiment, and iterate with confidence because you know your work is safely stored and tracked.

Why Gitea is a powerful home for your n8n workflows

Gitea is a lightweight, self-hosted Git service that fits perfectly for teams and individuals who want control over their own infrastructure. When you store n8n workflows as JSON files in a Gitea repository, you unlock:

  • Version history and diffs to see exactly how workflows evolve over time
  • Secure, off-instance backups so your automations survive instance failures or migrations
  • Easy rollback and change review through standard Git tooling
  • Integration with CI/CD and team workflows so automations become part of your broader engineering practices

In short, Gitea turns your n8n workflows into a managed, traceable asset library instead of a black box.

The template: an automated n8n to Gitea backup workflow

The supplied n8n workflow acts as your automated archivist. On a schedule, it:

  • Retrieves all workflows from your n8n instance
  • Checks if a corresponding .json file exists in your Gitea repository
  • Base64-encodes the workflow JSON for API compatibility
  • Creates a new file in Gitea if it does not exist
  • Updates the existing file only if the content has changed
  • Commits changes using a Gitea personal access token

The pattern is simple but powerful: fetch → encode → compare → create or update. This keeps your repository clean and focused on meaningful changes, not noisy commits.

What you need before you start

To use this template, set up a few essentials first. These are quick wins that pay off every time your backup runs.

  • An n8n instance with access to the workflows API (or the built-in n8n node)
  • A Gitea instance and repository, for example a repo named workflows
  • A Gitea personal access token with repository read and write permissions
  • n8n credentials configured:
    • Gitea Token as an HTTP header: Authorization: Bearer <TOKEN>
    • Optionally, API credentials for fetching workflows if required by your setup

Once this is in place, you are ready to connect your n8n instance to your Gitea backup repo and let the automation work for you.

How the workflow is structured in n8n

The workflow is built from a set of focused nodes that each handle a small part of the process. Together, they create a reliable pipeline from n8n to Gitea.

Key nodes and their roles

  • Schedule Trigger – Runs the workflow every X minutes (default is 45). This keeps your backups current without manual effort.
  • Globals – Stores settings like repo.url, repo.owner, and repo.name so you only change them in one place if you move repositories or instances.
  • n8n / API node – Fetches all workflows from your n8n instance as JSON.
  • ForEach (splitInBatches) – Iterates through each workflow so they can be processed one by one.
  • GetGitea (HTTP Request) – Checks if <workflow-name>.json already exists in the repository.
  • Exist (If) – Decides whether to follow the create path or the update path based on the HTTP response from Gitea.
  • Base64EncodeCreate / Base64EncodeUpdate – Encodes the workflow JSON and prepares it for the Gitea API.
  • Changed (If) – Compares the newly encoded content with the current file content returned by Gitea and only proceeds when they differ.
  • PostGitea / PutGitea (HTTP Request) – Creates or updates files in the Gitea repository.

This modular structure makes it easy to understand, debug, and extend. You can modify or swap nodes as your needs evolve without losing the core functionality.

How workflows are stored in Gitea

By default, each workflow is stored as a JSON file named after the workflow:

<workflow-name>.json

The workflow JSON is first pretty-printed, then Base64-encoded to match Gitea’s contents API requirements. The API expects file content in Base64 format, so this step is essential.

If you want more structure, you can adjust the naming convention. For example:

  • id-name.json to include the workflow ID
  • File paths that include folders or environments, such as prod/id-name.json or teamA/id-name.json

These small changes can make your repository more organized and easier to navigate as your automation library grows.

Important configuration details for key nodes

Globals

Use the Globals node to centralize your repository settings:

  • repo.url
  • repo.name
  • repo.owner

With this approach, migrating to a new Gitea instance or repository is as simple as editing a single node.

GetGitea (check file existence)

The GetGitea HTTP Request node checks if a given workflow file already exists.

Endpoint:

{{repo.url}}/api/v1/repos/{{repo.owner}}/{{repo.name}}/contents/{{workflowName}}.json

Configure this node to continue on error. A 404 response (file not found) should not break the workflow. Instead, it signals that the workflow is new and should follow the create path.

Base64EncodeCreate / Base64EncodeUpdate

These code nodes take the workflow object, convert it to a nicely formatted JSON string, then encode it to Base64. The behavior looks like this:

json_string = json.dumps(workflow_object, indent=4)
base64_string = base64.b64encode(json_string.encode('utf-8')).decode('utf-8')

This ensures that what you store in Gitea is both human-readable (once decoded) and API-compliant.

Changed (compare before committing)

To avoid noisy commits, the Changed node compares:

  • The newly encoded content you just produced
  • The existing file content returned by the GetGitea node

If they differ, the workflow triggers the PUT update node. If they are the same, it skips to the next workflow. This keeps your Git history clean and meaningful.

Using the Gitea HTTP API for create and update

The workflow uses Gitea’s repository contents API for both creating and updating workflow files.

  • Create
    HTTP method: POST
    Endpoint: /api/v1/repos/:owner/:repo/contents/:filepath
    Body example:
    {  "content": "<base64>",  "message": "Add workflow ..."
    }
  • Update
    HTTP method: PUT
    Same endpoint as create
    Body example:
    {  "content": "<base64>",  "sha": "<existing file sha>",  "message": "Update workflow ..."
    }

In both cases, make sure your HTTP Request nodes include the Authorization header:

Authorization: Bearer <YOUR_TOKEN>

This token is what allows n8n to write directly to your Gitea repository.

From idea to automation: schedule, test, and activate

Here is a simple path to bring this backup workflow to life.

  1. Configure Globals and credentials Set up the Globals node with your repo.url, repo.owner, and repo.name. Add your Gitea token as a credential and reference it in the HTTP Request nodes.
  2. Run a manual test for creation Execute the workflow manually once. Check your Gitea repository and confirm that new .json files have been created for your n8n workflows.
  3. Validate updates with a small change Make a small edit to one workflow in n8n, then run the backup workflow again. Confirm that the corresponding file in Gitea is updated and that the PUT path and sha handling work correctly.
  4. Enable the Schedule Trigger Once you are confident in both create and update paths, turn on the Schedule Trigger so your backups run automatically at your chosen interval.

With this done, your n8n workflows are no longer fragile. They are part of a living, versioned system that supports your growth.

Security and best practices

As you automate more, protecting your access and data becomes even more important. Follow these guidelines to keep your setup secure and maintainable:

  • Use a scoped Gitea token limited to the specific repository instead of a broad admin token.
  • Store tokens in n8n credentials only. Avoid hard-coding secrets directly in nodes.
  • Create a dedicated backup repository and consider branch protection if multiple people will push backups.
  • Rotate your personal access token periodically and track changes in your internal secret store.

These small steps safeguard your automation infrastructure as it becomes more central to your operations.

Troubleshooting: turning blockers into learning moments

If something does not work the first time, that is an opportunity to refine your understanding and strengthen your setup. Here are common issues and how to resolve them:

  • 404 on GetGitea This is expected for new workflows. Make sure the GetGitea node is configured to continue on error so the create path runs instead of failing the entire workflow.
  • 401 or 403 from Gitea Double-check the Authorization header. Confirm that the token has repository write permission and that it is formatted as Bearer <TOKEN> with a space.
  • Conflicting SHAs when updating Ensure your workflow reads the current file sha from the GetGitea response and passes it correctly to the PutGitea node.
  • Binary or invalid JSON content in Gitea Verify that you are Base64-encoding the pretty-printed JSON string using UTF-8, not a binary object or a different encoding.

Each fix you apply makes your automation more robust and repeatable, which pays off in every future project.

Ideas to extend and customize the template

Once the core backup is running, you can build on it to match your workflow style and team processes. Here are some enhancements you can try:

  • Organize workflows into folders in the repository, for example by environment, owner, or project.
  • Include workflow ID and timestamp in commit messages for easier search and analysis.
  • Commit to branches instead of main and use pull requests for review before merging.
  • Trigger notifications via Slack, email, or another channel whenever backups create or update files.

Each enhancement is a small step that increases visibility, collaboration, and control over your automations.

Example commit message format

A consistent commit message pattern makes it easier to search logs, build dashboards, or trigger downstream automations.

message: "Backup: update workflow 'My Workflow' (id: 12345) - automated backup on 2025-10-05T12:34:56Z"

Adapt this structure to include the details your team cares about most, such as environment, owner, or ticket references.

From backup to growth: your next step

Exporting n8n workflows to a Git repository on Gitea gives you durability, auditability, and version control for your automation assets. More importantly, it frees your mind to focus on higher value work.

With this workflow template in place, you can:

  • Experiment without fear of losing work
  • Collaborate on workflows with clear history and review
  • Integrate your automations into a broader DevOps and CI/CD strategy

You are not just backing up JSON files. You are building a foundation for a more automated, resilient, and focused way of working.

Take action now:

  • Configure your Globals node and Gitea token.
  • Run a manual test and watch your first workflows appear in Gitea.
  • Enable the scheduler so backups become a habit that runs in the background.

If you need help tailoring this template to your naming conventions, branching strategy, or team structure, reach out in the n8n community or talk with your DevOps team. This workflow can be your starting point for an entire ecosystem of automation best practices.

Call to action: Export your first workflow to Gitea today and tag your repository with backup so you can start tracking changes over time. If you would like the JSON for this n8n workflow adapted to your environment, share your repo URL and preferred naming scheme, and build from there.

Leave a Reply

Your email address will not be published. Required fields are marked *

AI Workflow Builder
N8N Bazar

AI-Powered n8n Workflows

🔍 Search 1000s of Templates
✨ Generate with AI
🚀 Deploy Instantly
Try Free Now