Oct 6, 2025

Backup n8n Workflows to Gitea Repository

Backing up automation workflows is essential to maintaining reliable automation infrastructure. This step-by-step guide explains how to automatically back up n8n workflows to a Gitea Git repository using a reusable workflow template. Follow the instructions to establish scheduled, change-detection backups that create or update JSON files in your Gitea repo. Why backup n8n workflows to […]

Backup n8n Workflows to Gitea Repository

Backing up automation workflows is essential to maintaining reliable automation infrastructure. This step-by-step guide explains how to automatically back up n8n workflows to a Gitea Git repository using a reusable workflow template. Follow the instructions to establish scheduled, change-detection backups that create or update JSON files in your Gitea repo.

Why backup n8n workflows to Gitea?

Storing workflow definitions in a Git repository provides versioning, auditability, and an easy way to restore or share workflows. Gitea is a lightweight, self-hosted Git service ideal for private infrastructure. Combining n8n with Gitea gives you automated, secure backups of your workflow logic without manual exports.

What this workflow does (high level)

  • Runs on a schedule (configurable interval)
  • Pulls all workflows from n8n
  • Iterates each workflow and checks if a corresponding file exists in the Gitea repo
  • If file exists, base64-encodes updated content and conditionally updates the file in Gitea
  • If file doesn’t exist, creates a new file in Gitea
  • Only commits when the content has changed

Prerequisites

  • n8n running with API access (to list workflows)
  • Gitea instance (self-hosted or hosted) with a repository to store workflow JSON files
  • Gitea personal access token with repo read/write permissions
  • Access to n8n credentials manager to add the Gitea token

Key nodes used in this template

  • Schedule Trigger – runs the flow at configured intervals
  • Globals (Set) – stores repo.url, repo.name, repo.owner as variables
  • n8n (API) – retrieves all workflows from your n8n instance
  • SplitInBatches (ForEach) – iterates each workflow
  • GetGitea (HTTP Request GET) – checks whether the file exists in the repo
  • Exist (IF) – branches when file exists or not
  • SetDataCreateNode / SetDataUpdateNode (Set) – prepares payload for encoding nodes
  • Base64EncodeCreate / Base64EncodeUpdate (Code) – converts workflow JSON to pretty-printed JSON and encodes to base64
  • PostGitea (HTTP Request POST) – creates new file
  • PutGitea (HTTP Request PUT) – updates existing file with a sha and content
  • Changed (IF) – checks content difference to avoid unnecessary commits

Step-by-step setup

1. Configure Global variables

Open the Globals (Set) node and configure:

  • repo.url → e.g. https://git.yourdomain.com
  • repo.nameworkflows (the repository name)
  • repo.owner → repository owner or organization

2. Create a Gitea personal access token

  1. Log in to Gitea and go to Settings → Applications → Generate Token.
  2. Give it a name and grant repo read & write permissions.
  3. Copy the token (you will not see it again).

In n8n Credentials Manager create a credential (type: HTTP Header Auth) with the header name Authorization and the value Bearer YOUR_PERSONAL_ACCESS_TOKEN (include the space after “Bearer”). Attach this credential to GetGitea, PutGitea and PostGitea nodes.

3. Add API credentials for n8n node

If your n8n instance is protected by an API key or basic auth, add the appropriate credentials to the n8n API node so it can list workflows.

4. Review the Base64 encoding code nodes

Two code nodes take the workflow JSON, pretty-print it, and convert it to base64 for the Gitea API. They also prepare the payload fields the HTTP nodes expect (content and sha when updating).

# Process (conceptual)
json_string = json.dumps(workflow_json, indent=4)
base64_string = base64.b64encode(json_string.encode('utf-8')).decode('utf-8')
# returned payload contains: content (base64 string)

5. Understand how existence and change detection works

The template issues a GET against the repository path (file name: workflowName.json). If the file exists, the response includes a sha and the current base64 content. The workflow compares the encoded content with the new encoded content and only calls the PUT (update) endpoint if they differ. If the file is missing (404), the template uses the POST endpoint to create it.

Testing and activation

  1. Run the workflow manually once to confirm credentials and endpoints are correct.
  2. Check your Gitea repository for created JSON files (named after each workflow).
  3. Inspect logs and the IF node results to confirm that unchanged workflows are skipped.
  4. When happy, enable the scheduled trigger to run automatically on your desired interval (the template uses 45 minutes by default).

Security and best practices

  • Store the Gitea token securely in n8n credentials — never inline it in nodes.
  • Use least-privilege tokens (only repo:create, repo:update if possible).
  • Limit access to the backup repository; treat it as a sensitive backup store.
  • Enable repository branch protection or review settings if multiple services write to the repo.

Troubleshooting

  • 401 Unauthorized — check the Authorization header value and token permissions.
  • 404 Not Found on GET — confirm the repository path and owner in the Globals node.
  • Conflicting SHA errors during PUT — ensure you pass the current file SHA returned by the GET call before updating.
  • Empty or malformed JSON in repository — ensure the Base64 code nodes produce pretty-printed, valid JSON.

Tips to extend this workflow

  • Push backups to a branch and open a Pull Request for review before merging
  • Store workflow metadata (author, timestamp) in the JSON or as a separate index file
  • Encrypt sensitive fields before saving if workflows contain credentials
  • Integrate with a notification node (Slack or email) to report successful backup runs or failures

Conclusion

Using this template you can automate regular backups of your n8n workflows to a Gitea repository, with change detection to avoid noisy commits. The approach is flexible — adapt the interval, repository layout, or add commit messages and metadata to suit your process.

Call to action

Ready to secure your automations? Import the provided n8n template, add your Gitea and n8n credentials, run a test, and enable the schedule. If you need help customizing the flow, leave a comment or join the community forum for assistance.

Pro tip: Keep an additional offsite backup of the repository (mirror to GitHub/GitLab or another storage) for maximum resilience.

Leave a Reply

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