{ "active": true, "connections": { "n8n": { "main": [ [ { "node": "OneAtATime", "type": "main", "index": 0 } ] ] }, "new": { "main": [ [ { "node": "GitHub Create", "type": "main", "index": 0 } ] ] }, "same": { "main": [ [ { "node": "OneAtATime", "type": "main", "index": 0 } ] ] }, "Merge": { "main": [ [ { "node": "isDiffOrNew", "type": "main", "index": 0 } ] ] }, "GitHub": { "main": [ [ { "node": "Merge", "type": "main", "index": 0 } ] ] }, "Globals": { "main": [ [ { "node": "n8n", "type": "main", "index": 0 } ] ] }, "different": { "main": [ [ { "node": "GitHub Edit", "type": "main", "index": 0 } ] ] }, "OneAtATime": { "main": [ [ { "node": "GitHub", "type": "main", "index": 0 }, { "node": "Merge", "type": "main", "index": 1 } ] ] }, "GitHub Edit": { "main": [ [ { "node": "OneAtATime", "type": "main", "index": 0 } ] ] }, "isDiffOrNew": { "main": [ [ { "node": "github_status", "type": "main", "index": 0 } ] ] }, "GitHub Create": { "main": [ [ { "node": "OneAtATime", "type": "main", "index": 0 } ] ] }, "github_status": { "main": [ [ { "node": "same", "type": "main", "index": 0 } ], [ { "node": "different", "type": "main", "index": 0 } ], [ { "node": "new", "type": "main", "index": 0 } ] ] }, "Every 12 hours": { "main": [ [ { "node": "Globals", "type": "main", "index": 0 } ] ] }, "On clicking 'execute'": { "main": [ [ { "node": "Globals", "type": "main", "index": 0 } ] ] } }, "createdAt": "2023-08-25T09:22:16.778Z", "id": "2", "meta": null, "name": "n8n Backup", "nodes": [ { "parameters": {}, "id": "85130382-8fe5-440c-89cd-d38345a844f0", "name": "On clicking 'execute'", "type": "n8n-nodes-base.manualTrigger", "position": [ -1185, 355 ], "typeVersion": 1 }, { "parameters": { "authentication": "oAuth2", "resource": "file", "operation": "get", "owner": "={{$node[\"Globals\"].json[\"repo\"][\"owner\"]}}", "repository": "={{$node[\"Globals\"].json[\"repo\"][\"name\"]}}", "filePath": "={{$node[\"Globals\"].json[\"repo\"][\"path\"]}}{{$json[\"name\"]}}.json", "asBinaryProperty": false, "additionalParameters": {} }, "id": "670f96a9-0299-4e92-9c85-9ce12eb6311d", "name": "GitHub", "type": "n8n-nodes-base.github", "position": [ -340, 320 ], "typeVersion": 1, "alwaysOutputData": true, "credentials": { "githubOAuth2Api": { "id": "4", "name": "GitHub account" } }, "continueOnFail": true }, { "parameters": { "dataType": "string", "value1": "={{$json[\"github_status\"]}}", "rules": { "rules": [ { "value2": "same" }, { "value2": "different", "output": 1 }, { "value2": "new", "output": 2 } ] } }, "id": "a53c7f77-c6f4-4da4-92ba-324dd1a8145b", "name": "github_status", "type": "n8n-nodes-base.switch", "position": [ 300, 460 ], "typeVersion": 1 }, { "parameters": {}, "id": "a98b3acc-b3a1-4c75-91be-e4b55a6ad25f", "name": "same", "type": "n8n-nodes-base.noOp", "position": [ 540, 260 ], "typeVersion": 1 }, { "parameters": {}, "id": "9c4b5247-4c8f-4744-84fe-4f1047778813", "name": "different", "type": "n8n-nodes-base.noOp", "position": [ 540, 460 ], "typeVersion": 1 }, { "parameters": {}, "id": "2b3610ba-26f6-4eb4-a93f-a687a5bde275", "name": "new", "type": "n8n-nodes-base.noOp", "position": [ 540, 640 ], "typeVersion": 1 }, { "parameters": { "authentication": "oAuth2", "resource": "file", "operation": "edit", "owner": "={{$node[\"Globals\"].json[\"repo\"][\"owner\"]}}", "repository": "={{$node[\"Globals\"].json[\"repo\"][\"name\"]}}", "filePath": "={{$node[\"Globals\"].json[\"repo\"][\"path\"]}}{{$node[\"OneAtATime\"].json[\"name\"]}}.json", "fileContent": "={{$node[\"isDiffOrNew\"].json[\"n8n_data_stringy\"]}}", "commitMessage": "=[N8N Backup] {{$node[\"OneAtATime\"].json[\"name\"]}}.json ({{$json[\"github_status\"]}})" }, "id": "5093f483-1f89-461e-923b-2b2ec242d231", "name": "GitHub Edit", "type": "n8n-nodes-base.github", "position": [ 720, 460 ], "typeVersion": 1, "credentials": { "githubOAuth2Api": { "id": "4", "name": "GitHub account" } } }, { "parameters": { "authentication": "oAuth2", "resource": "file", "owner": "={{$node[\"Globals\"].json[\"repo\"][\"owner\"]}}", "repository": "={{$node[\"Globals\"].json[\"repo\"][\"name\"]}}", "filePath": "={{$node[\"Globals\"].json[\"repo\"][\"path\"]}}{{$node[\"OneAtATime\"].json[\"name\"]}}.json", "fileContent": "={{$node[\"isDiffOrNew\"].json[\"n8n_data_stringy\"]}}", "commitMessage": "=[N8N Backup] {{$node[\"OneAtATime\"].json[\"name\"]}}.json ({{$json[\"github_status\"]}})" }, "id": "7948af39-295e-496e-bab4-6558e6f1fc12", "name": "GitHub Create", "type": "n8n-nodes-base.github", "position": [ 720, 640 ], "typeVersion": 1, "credentials": { "githubOAuth2Api": { "id": "4", "name": "GitHub account" } } }, { "parameters": { "batchSize": 1, "options": {} }, "id": "026290e1-7db2-4aca-990e-acebc3098880", "name": "OneAtATime", "type": "n8n-nodes-base.splitInBatches", "position": [ -560, 480 ], "typeVersion": 1 }, { "parameters": { "values": { "string": [ { "name": "repo.owner", "value": "m3tam3re" }, { "name": "repo.name", "value": "n8n-backup" }, { "name": "repo.path", "value": "workflows/" } ] }, "options": {} }, "id": "b1f6bda3-493b-4616-ac83-9445b8ed49f4", "name": "Globals", "type": "n8n-nodes-base.set", "position": [ -1000, 480 ], "typeVersion": 1 }, { "parameters": { "triggerTimes": { "item": [ { "mode": "everyX", "value": 12 } ] } }, "id": "7d03c69b-ab45-4126-ae89-e4b9655bb838", "name": "Every 12 hours", "type": "n8n-nodes-base.cron", "position": [ -1185, 615 ], "typeVersion": 1 }, { "parameters": { "filters": {} }, "id": "482a6d9f-100f-4976-a38d-0ff385f09918", "name": "n8n", "type": "n8n-nodes-base.n8n", "position": [ -800, 480 ], "typeVersion": 1, "credentials": { "n8nApi": { "id": "3", "name": "n8n account" } } }, { "parameters": { "jsCode": "// File Returned with Content\nif (Object.keys($input.all()[0].json).includes(\"content\")) {\n // Get JSON Objects\n var origWorkflow = JSON.parse(Buffer.from($input.all()[0].json.content, 'base64'));\n var n8nWorkflow = $input.all()[1].json;\n \n // Order JSON Objects\n var orderedOriginal = {}\n var orderedActual = {}\n \n Object.keys(origWorkflow).sort().forEach(function(key) {\n orderedOriginal[key] = origWorkflow[key];\n });\n \n Object.keys(n8nWorkflow).sort().forEach(function(key) {\n orderedActual[key] = n8nWorkflow[key];\n });\n\n // Determine Difference\n if ( JSON.stringify(orderedOriginal) === JSON.stringify(orderedActual) ) {\n $input.all()[0].json.github_status = \"same\";\n $input.all()[0].json.content_decoded = orderedOriginal;\n } else {\n $input.all()[0].json.github_status = \"different\";\n $input.all()[0].json.content_decoded = orderedOriginal;\n $input.all()[0].json.n8n_data_stringy = JSON.stringify(orderedActual, null, 2);\n }\n// No File Returned / New Workflow\n} else {\n // Order JSON Object\n var n8nWorkflow = ($input.all()[1].json);\n var orderedActual = {}\n Object.keys(n8nWorkflow).sort().forEach(function(key) {\n orderedActual[key] = n8nWorkflow[key];\n });\n \n // Proper Formatting\n $input.all()[0].json.github_status = \"new\";\n $input.all()[0].json.n8n_data_stringy = JSON.stringify(orderedActual, null, 2);\n}\n\n// Return Items\nreturn $input.all();" }, "id": "170eb381-afa6-4cd0-9ed3-6a4686fef31b", "name": "isDiffOrNew", "type": "n8n-nodes-base.code", "position": [ 60, 460 ], "typeVersion": 1 }, { "parameters": {}, "id": "9889f4d7-7e6b-4522-8f00-1110d7f2768a", "name": "Merge", "type": "n8n-nodes-base.merge", "position": [ -120, 460 ], "typeVersion": 2 } ], "pinData": {}, "settings": {}, "staticData": null, "tags": [], "triggerCount": 1, "updatedAt": "2023-08-25T09:50:30.000Z", "versionId": "6be3d1b5-554e-41a1-83e3-bffd640ce9da" }