{
  "active": false,
  "connections": {
    "On clicking 'execute'": {
      "main": [
        [
          {
            "node": "Globals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GitHub": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "n8n1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "same": {
      "main": [
        [
          {
            "node": "OneAtATime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "different": {
      "main": [
        [
          {
            "node": "GitHub Edit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "new": {
      "main": [
        [
          {
            "node": "GitHub Create",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GitHub Edit": {
      "main": [
        [
          {
            "node": "OneAtATime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GitHub Create": {
      "main": [
        [
          {
            "node": "OneAtATime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OneAtATime": {
      "main": [
        [
          {
            "node": "GitHub",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Globals": {
      "main": [
        [
          {
            "node": "n8n",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "n8n": {
      "main": [
        [
          {
            "node": "OneAtATime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "isDiffOrNew": {
      "main": [
        [
          {
            "node": "check_github_status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "isDiffOrNew",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "check_github_status": {
      "main": [
        [
          {
            "node": "same",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "different",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "new",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "backup every 10 minutes": {
      "main": [
        [
          {
            "node": "Globals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "createdAt": "2025-04-06T19:10:32.917Z",
  "id": "ZW9BeDRubuJqk1K3",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Backup",
  "nodes": [
    {
      "parameters": {},
      "id": "735b1055-bf66-459e-8485-55687f593c2b",
      "name": "On clicking 'execute'",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1900,
        60
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "get",
        "owner": {
          "__rl": true,
          "value": "solmorth",
          "mode": "name"
        },
        "repository": {
          "__rl": true,
          "value": "discord_ai_agent",
          "mode": "list",
          "cachedResultName": "discord_ai_agent",
          "cachedResultUrl": "https://github.com/solmorth/discord_ai_agent"
        },
        "filePath": "={{ $json.name }}",
        "additionalParameters": {}
      },
      "id": "1ad358d8-dd9d-45c0-9d88-5a11e08156ec",
      "name": "GitHub",
      "type": "n8n-nodes-base.github",
      "position": [
        -1060,
        20
      ],
      "typeVersion": 1,
      "alwaysOutputData": true,
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      },
      "continueOnFail": true
    },
    {
      "parameters": {},
      "id": "5b3fa61e-563b-4787-9a72-249ef2a44d42",
      "name": "same",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -180,
        -80
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "28c87efe-4b54-48c6-8e07-7f3ddcd3c9aa",
      "name": "different",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -180,
        160
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "64dbd2e3-beba-448d-a7d3-d93279b1de8c",
      "name": "new",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -180,
        340
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "edit",
        "owner": {
          "__rl": true,
          "value": "anilrajrimal1",
          "mode": "name"
        },
        "repository": {
          "__rl": true,
          "value": "n8n-backups",
          "mode": "list",
          "cachedResultName": "n8n-backups",
          "cachedResultUrl": "https://github.com/anilrajrimal1/n8n-backups"
        },
        "filePath": "={{$node[\"Globals\"].json[\"repo\"][\"path\"]}}{{$node[\"OneAtATime\"].json[\"name\"]}}.json",
        "fileContent": "={{$node[\"isDiffOrNew\"].json[\"n8n_data_stringy\"]}}",
        "commitMessage": "=update: n8n backup {{$node[\"OneAtATime\"].json[\"name\"]}}.json ({{$json[\"github_status\"]}})"
      },
      "id": "16182991-7714-4b0e-91ad-554b00b6871f",
      "name": "GitHub Edit",
      "type": "n8n-nodes-base.github",
      "position": [
        0,
        160
      ],
      "typeVersion": 1,
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "file",
        "owner": {
          "__rl": true,
          "value": "anilrajrimal1",
          "mode": "name"
        },
        "repository": {
          "__rl": true,
          "value": "n8n-backups",
          "mode": "list",
          "cachedResultName": "n8n-backups",
          "cachedResultUrl": "https://github.com/anilrajrimal1/n8n-backups"
        },
        "filePath": "={{$node[\"Globals\"].json[\"repo\"][\"path\"]}}{{$node[\"OneAtATime\"].json[\"name\"]}}.json",
        "fileContent": "={{$node[\"isDiffOrNew\"].json[\"n8n_data_stringy\"]}}",
        "commitMessage": "=Add: n8n backup file named {{$node[\"OneAtATime\"].json[\"name\"]}}.json ({{$json[\"github_status\"]}})"
      },
      "id": "9317bf86-8ea7-4f3f-a998-0ad3591bcdab",
      "name": "GitHub Create",
      "type": "n8n-nodes-base.github",
      "position": [
        0,
        340
      ],
      "typeVersion": 1,
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "id": "9f91a33a-718e-4816-b086-94759311a611",
      "name": "OneAtATime",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -1280,
        180
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "repo.owner",
              "value": "n8n-io"
            },
            {
              "name": "repo.name",
              "value": "n8n-backups"
            },
            {
              "name": "repo.path",
              "value": "workflows/"
            }
          ]
        },
        "options": {}
      },
      "id": "b02c5c67-c8f4-4d54-8625-64e2870f25a3",
      "name": "Globals",
      "type": "n8n-nodes-base.set",
      "position": [
        -1720,
        180
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "id": "2f5707cc-0b18-4298-86de-499772198f7a",
      "name": "n8n",
      "type": "n8n-nodes-base.n8n",
      "position": [
        -1480,
        180
      ],
      "typeVersion": 1,
      "credentials": {
        "n8nApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "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": "3da20718-5d7a-4195-98c0-bf7395249f64",
      "name": "isDiffOrNew",
      "type": "n8n-nodes-base.code",
      "position": [
        -660,
        160
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "15d1f823-1879-4ba4-94d9-d8e37fb66961",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        -840,
        160
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{$json[\"github_status\"]}}",
        "rules": {
          "rules": [
            {
              "value2": "same"
            },
            {
              "value2": "different",
              "output": 1
            },
            {
              "value2": "new",
              "output": 2
            }
          ]
        }
      },
      "id": "e43c2020-5951-4881-8b9c-0ee82e00d73e",
      "name": "check_github_status",
      "type": "n8n-nodes-base.switch",
      "position": [
        -420,
        160
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyX",
              "value": 10,
              "unit": "minutes"
            }
          ]
        }
      },
      "id": "68e8e89a-7b1e-4efb-b4bb-fb7fa4c08faa",
      "name": "backup every 10 minutes",
      "type": "n8n-nodes-base.cron",
      "position": [
        -1900,
        320
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.n8n",
      "typeVersion": 1,
      "position": [
        -840,
        20
      ],
      "id": "d6b849a8-77c5-448b-9be6-a44c52bbd8cb",
      "name": "n8n1",
      "credentials": {
        "n8nApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2025-04-06T19:15:09.988Z",
  "versionId": "01aada55-9477-4d1b-bd93-4154e9841bcc"
}