n8n Hands-On Guide 18: How to Backup Workflows to GitHub with One Click

10 months ago

The previous article covered GitHub configuration. In this one, we'll continue by looking at how to back up my workflows.

These are my current workflows. The ultimate goal is to be able to back them up to a GitHub repository with a single click.

image.png

https://appstore.lazycat.cloud/#/shop/detail/cloud.lazycat.app.n8n

Workflow Setup

If you want scheduled automatic backups, you can add a Schedule trigger. For now, I'll use a manual trigger.

image.png

Next, retrieve all n8n workflows. Search for "n8n" on the right side.

image.png

Select "get many workflows".

image.png

Click execute. You can see 18 workflows have been retrieved on the right side.

image.png

Before committing the code, I processed the data to avoid errors with things like filenames.

image.png

Execute to see the result. image.png

In the GitHub repository, I pre-created an n8n-workflows-backup directory to store the JSON files.

image.png

Connect to the GitHub repository.

image.png

Now it's time to add a GitHub node. For configuration, you can refer to the previous guide. Upload the file only if it doesn't already exist.

image.png

image.png

If the file exists, update it. The process flow is shown in the diagram below.

image.png

Select "File" as the source type, choose the correct username and repository name. Pay attention to the node names from previous steps, as they are case-sensitive.

image.png

After clicking execute, you can see the output on the right side.

image.png

Returning to the GitHub repository, you can see the JSON files have been uploaded.

image.png

image.png

With this workflow, you don't have to worry about losing your created workflows. You can simply schedule regular commits of the latest JSON files to GitHub.

Author
天天