Backup n8n Workflows to Gitea: A Practical Guide
Backing up your n8n workflows to a Git repository on Gitea is a smart way to ensure versioned, auditable, and recoverable automation assets. This guide walks you through a tested automation that periodically exports workflows from n8n, checks for changes, and either creates or updates JSON files in a Gitea repository using the Gitea API.
Why back up n8n workflows to Gitea?
Using Gitea as the remote storage for your n8n workflows gives you:
- Versioned backups for change history and rollbacks
- Centralized repository access for teams
- Automation for continuous backup without manual intervention
Quick overview of the workflow
The automation follows these high-level steps:
- Trigger on a schedule (e.g., every 45 minutes)
- Fetch all workflows from n8n
- For each workflow, check if a corresponding file exists in the Gitea repo
- If the file exists, compare content and update only when it changed
- If the file doesn’t exist, create it
Prerequisites
- An n8n instance with API access to list/export workflows
- A Gitea server and a repository (for example, repo name
workflows
) - A Gitea Personal Access Token with repository read/write permissions
- Credentials configured in n8n for both the n8n API and Gitea token
Nodes used in the n8n workflow (explanation)
This workflow uses common n8n nodes. Below are each node’s role and important configuration notes.
Schedule Trigger
Starts the backup on a repeating schedule. The example uses a 45-minute interval. Adjust the timing to meet your backup frequency and operational needs.
Globals (Set node)
Store reusable configuration fields such as:
repo.url
— your Gitea base URL (e.g.,https://git.example.com
)repo.owner
— Gitea repo ownerrepo.name
— repository name (e.g.,workflows
)
Keep these values centralized so you can update them in one place.
n8n (API node to get workflows)
Call your n8n API to retrieve all workflows. This node should be configured with appropriate authentication (API key or Basic Auth) and return the full JSON definition for each workflow.
ForEach (splitInBatches)
Processes each workflow item individually so the flow can query, compare, and push files per workflow without mixing data between items.
GetGitea (HTTP Request)
Checks whether a file named <workflow-name>.json
exists in the target repo by calling:
/api/v1/repos/:owner/:repo/contents/:path
Example URL constructed from Globals: https://git.example.com/api/v1/repos/owner/workflows/WorkflowName.json
Important: Configure the request to use your Gitea token in the Authorization
header (Bearer TOKEN — include a space after “Bearer”).
Exist (IF node)
Examines the response from GetGitea
. If the request returns a 404 or an error payload indicating the file does not exist, the node routes the path to file creation; otherwise it prepares to update the existing file.
SetDataCreateNode / SetDataUpdateNode (Set node)
Prepare the workflow data object to be encoded and pushed. These nodes pick the relevant workflow JSON and pass it to the encoding node.
Base64EncodeCreate / Base64EncodeUpdate (Code node)
Gitea’s API requires file content to be base64-encoded when creating or updating a file. The code nodes:
- Pretty-print the workflow JSON
- Encode the JSON string as UTF-8 bytes
- Return a base64 string ready for the API (in
content
)
Note: If updating an existing file, include the file SHA returned by GetGitea
in the update request to avoid conflicts.
Changed (IF node)
Before issuing an update, the workflow compares the base64 content to the repository content. Only if they differ will it call the update API—this prevents unnecessary commits.
PostGitea (HTTP Request) — Create file
Creates a new file using POST /api/v1/repos/:owner/:repo/contents/:path
with a JSON body that includes:
content
— base64-encoded content- Optional:
message
orbranch
parameters
PutGitea (HTTP Request) — Update file
Updates an existing file using PUT /api/v1/repos/:owner/:repo/contents/:path
and sends:
content
— new base64 contentsha
— the current file SHA fromGetGitea
to prevent race conditions
Gitea authentication details
Generate a Personal Access Token in Gitea: Settings → Applications → Generate Token. The token must have repo read/write permissions.
In n8n, configure a Gitea Token credential that adds an HTTP header:
Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN
Important: Make sure there is a space after the word Bearer and before your token.
Tips and best practices
- Use a dedicated service account (owner) in Gitea so tokens are scoped and auditable.
- Protect the repository (branch rules) if you want stricter review before changes.
- Run the workflow manually after configuring credentials to verify the flow and inspect API responses in n8n execution logs.
- Consider storing backups in a separate branch if you’d like to avoid polluting main history with automated commits.
- Set the schedule frequency to balance between timeliness of backups and API rate limits.
Troubleshooting
- If GetGitea returns unexpected errors, confirm the encoded path and owner/repo values and validate the token permissions.
- For authentication failures, verify the header format and try the same API call with curl to isolate n8n configuration issues.
- If updates fail due to SHA mismatch, it likely means another change was committed. Re-fetch the file SHA and re-run the update path.
- Use n8n’s onError: continueRegularOutput for GET calls that may 404 so the workflow can handle create vs update branches cleanly.
Security considerations
Keep tokens out of logs and use n8n credentials to store secrets. Rotate the Gitea token periodically and audit repository access. Limit the token to repository operations only.
Testing and activation
- Set your
Globals
values and add Gitea token credential. - Run the flow manually to confirm a single workflow is exported and committed.
- Inspect the repository to ensure JSON files are created or updated correctly.
- Enable the schedule trigger once you’re satisfied with the results.
Wrap-up
Automating n8n workflow backups to a Gitea repository gives you control, history, and recovery options for your automation assets. The key parts are properly encoding workflow JSON in base64, checking for existing files and their SHAs, and using the Gitea API with a secure token.
Call to action
Want the n8n workflow template and example credentials JSON? Contact us or leave a comment below and we’ll provide the export and configuration tips. Subscribe to our newsletter for more automation tutorials and DevOps guides.
Need help customizing this flow for your environment? Reply with your Gitea setup (self-hosted or cloud) and n8n version and I’ll provide tailored steps.