Backup workflows to github

I would like to backup all my workflows to GitHub regularly and systematically.

Looking for some advise brainstorming here, how would you go about making a workflow which checks for diffs between your workflows and github, then commits any changes to a github repo, and adds any new workflows.

Basically runs a backup of your workflows to github.

  • Do you think that is possible?

If it is possible does that open the door for two way sync allowing you to edit workflows in github and have them sync back to n8n?

Hey @roofboard,

I would probably start by using the backup template we published here: https://n8n.io/workflows/1534/ this will take the workflows you have in n8n and commit them to a GitHub repo.

As a follow up step from there it would probably be a case of getting the workflow list from the API and Github then using the merge node to find which ones are missing and go from there.

hi all, error 404

Hey @Christel-Doudet,

New link is Back Up Your n8n Workflows To Github | n8n workflow template it can also be found in the templates section of n8n.

Hey @Jon, I just copied that workflow to back up my workflows, it’s been amazing actually, but recently I got this error at the IsDifforNew node.

ERROR: Unexpected end of JSON input [line 4]
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:4:27
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:44:2
    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/bridge.js:485:11)
    at Sandbox.run (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/nodevm.js:426:23)
    at Sandbox.runCodeAllItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Code/Sandbox.ts:76:33)
    at Sandbox.runCode (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Code/Sandbox.ts:43:56)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Code/Code.node.ts:90:27)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/src/Workflow.ts:1270:42)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/src/WorkflowExecute.ts:939:44

It appears as the same in the logs.

{"level":"debug","message":"Running node \"isDiffOrNew\" finished with error","metadata":{"file":"WorkflowExecute.js","node":"isDiffOrNew","timestamp":"2022-12-30T19:43:19.956Z","workflowId":"82"}}

{"level":"verbose","message":"Workflow execution finished with error","metadata":{"error":{"description":"SyntaxError","lineNumber":4,"message":"Unexpected end of JSON input [line 4]","stack":"SyntaxError: Unexpected end of JSON input\n    at JSON.parse (<anonymous>)\n    
at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:4:27\n    
at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:44:2\n   
at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/bridge.js:485:11)\n   
at Sandbox.run (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/nodevm.js:426:23)\n    
at Sandbox.runCodeAllItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Code/Sandbox.ts:76:33)\n    
at Sandbox.runCode (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Code/Sandbox.ts:43:56)\n    
at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/Code/Code.node.ts:90:27)\n   
at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/src/Workflow.ts:1270:42)\n    
at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/src/WorkflowExecute.ts:939:44"},"file":"WorkflowExecute.js","function":"processSuccessExecution","timestamp":"2022-12-30T19:43:19.960Z","workflowId":"82"}}

It is most likely a parse error because of some weird characters present in the workflows, but I haven’t managed to find the culprit line in the workflow that throws the error. I thought it may be the pinned data on those workflows, since they have emojis and Spanish characters, but I unpinned it and the same error appears.
Any ideas on how to know which one is it?
I appreciate the help,
thanks. :smiley:

Hey @seba5496,

It looks like it is something in workflow 82, I am not sure what it is not happy with but hopefully knowing the workflow will help.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.