{
  "createdAt": "2025-04-01T21:11:11.268Z",
  "updatedAt": "2025-05-05T12:57:06.851Z",
  "id": "uAUH1pb9zqogVnVS",
  "name": "backup_workflow",
  "active": false,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {},
      "id": "63c0e422-6a02-485c-8e5c-64f84389a0ce",
      "name": "Execute workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1580,
        420
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "1d49e42f-7c3c-4ad2-9662-87759579924f",
      "name": "Set date",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        -1380,
        420
      ]
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ $json.currentDate }}",
        "format": "custom",
        "customFormat": "dd-MM-yyyy/H:mm",
        "options": {}
      },
      "id": "9fc6c4d4-1516-45f8-8c66-5c4500544a8d",
      "name": "Format date",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        -1180,
        420
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "commitDate",
              "value": "={{ $json.formattedDate }}"
            }
          ]
        },
        "options": {}
      },
      "id": "5ea7812e-52f5-43d0-bec2-c0bcc7e88b55",
      "name": "Set commit date",
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [
        -980,
        420
      ]
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "list",
        "owner": {
          "__rl": true,
          "value": "https://github.com/AndersonNascimentoDosSantos",
          "mode": "url"
        },
        "repository": {
          "__rl": true,
          "value": "n8n-workflow-backup",
          "mode": "list",
          "cachedResultName": "n8n-workflow-backup",
          "cachedResultUrl": "https://github.com/AndersonNascimentoDosSantos/n8n-workflow-backup"
        },
        "filePath": "="
      },
      "id": "33f5051d-d535-419b-9bde-7d794846d6b3",
      "name": "List files from repository [GITHUB]",
      "type": "n8n-nodes-base.github",
      "typeVersion": 1,
      "position": [
        -780,
        420
      ],
      "alwaysOutputData": true,
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "aggregateItems",
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "name"
            }
          ]
        },
        "options": {}
      },
      "id": "402018ac-4d37-404c-9a0f-a7434afcee84",
      "name": "Combine file names [GITHUB]",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 2.1,
      "position": [
        -580,
        420
      ]
    },
    {
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "id": "f1f63607-d7f4-4139-88bf-139072fc4676",
      "name": "Retrieve workflows [N8N]",
      "type": "n8n-nodes-base.n8n",
      "typeVersion": 1,
      "position": [
        -380,
        420
      ],
      "credentials": {
        "n8nApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "options": {
          "fileName": "={{ $json.name.replace(/\\s+/g, '-').toLowerCase() }}-{{ $json.id }}.json"
        }
      },
      "id": "d2340f05-6ecb-47e3-8018-32f4cd5c9c49",
      "name": "Move JSON to binary",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        -180,
        420
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "id": "fe443f81-28e4-44f2-9f7e-b0839441bd00",
      "name": "Split to single items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 2,
      "position": [
        60,
        420
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $node['Combine file names [GITHUB]'].json.name }}",
              "operation": "contains",
              "value2": "={{ $binary.data.fileName }}"
            }
          ]
        }
      },
      "id": "b33ee0c5-7379-4200-b09b-481921715235",
      "name": "Check if file exists in repository",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        300,
        340
      ]
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "edit",
        "owner": {
          "__rl": true,
          "value": "https://github.com/AndersonNascimentoDosSantos",
          "mode": "url"
        },
        "repository": {
          "__rl": true,
          "value": "n8n-workflow-backup",
          "mode": "list",
          "cachedResultName": "n8n-workflow-backup",
          "cachedResultUrl": "https://github.com/GedAlex/n8n-workflow-backup"
        },
        "filePath": "={{ $('Check if file exists in repository').item.binary.data.fileName }}",
        "fileContent": "={{ $json.data }}",
        "commitMessage": "=backup-{{ $node['Set commit date'].json.commitDate }}"
      },
      "id": "69592b89-f2cd-4ba8-885b-7d2dfa32570e",
      "name": "Update file [GITHUB]",
      "type": "n8n-nodes-base.github",
      "typeVersion": 1,
      "position": [
        960,
        140
      ],
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "resource": "file",
        "owner": {
          "__rl": true,
          "value": "https://github.com/AndersonNascimentoDosSantos",
          "mode": "url"
        },
        "repository": {
          "__rl": true,
          "value": "n8n-workflow-backup",
          "mode": "list",
          "cachedResultName": "n8n-workflow-backup",
          "cachedResultUrl": "https://github.com/GedAlex/n8n-workflow-backup"
        },
        "filePath": "={{ $('Check if file exists in repository').item.binary.data.fileName}}",
        "fileContent": "={{ $json.data }}",
        "commitMessage": "=backup-{{ $node['Set commit date'].json.commitDate }}"
      },
      "id": "263de2aa-31c3-4086-8a13-ff4f15bd8a81",
      "name": "Upload file [GITHUB]",
      "type": "n8n-nodes-base.github",
      "typeVersion": 1,
      "position": [
        1020,
        540
      ],
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Trigger\nYou can change it to [\"Schedule\" trigger](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.scheduletrigger/) to make backups on regular basis.",
        "height": 339.51767272727324,
        "width": 182.4715262478496
      },
      "id": "533e7180-1f60-4ef1-b82e-67c49bb1e476",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1620,
        260
      ]
    },
    {
      "parameters": {
        "content": "## Set and format date/time\nThose nodes are responsible for setting a current date and time in format `dd-MM-yyyy/H:mm`. Date and time are used to compose commit messages in GitHub, for example: `backup-12-07-2023/14:18`.",
        "height": 339.42690909090965,
        "width": 585.4045090909088
      },
      "id": "a39a0c81-7ec0-4174-899a-8a84a96797ca",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1420,
        260
      ]
    },
    {
      "parameters": {
        "content": "## Make a list of existing files\nReturn a list of existing files (backups) in GitHub repository. Data returned by those nodes is used by \"IF\" node (later in workflow) to check whether the backup files should be created or updated.",
        "height": 339.42690909090965,
        "width": 389.89265454545443
      },
      "id": "c116ba52-2b5b-4f60-a597-da2b102cd9dc",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -820,
        260
      ]
    },
    {
      "parameters": {
        "content": "## Retrieve workflows\nGet all workflows form your n8n instance. Remember that **your credentials need to point to the instance that you want to backup.**",
        "height": 339.42690909090965,
        "width": 384.14708363636373
      },
      "id": "546a2e20-235b-4e3d-9cc1-20dd6d49aaf3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -400,
        260
      ]
    },
    {
      "parameters": {
        "content": "## Upload backup\nSplit JSON files into batches of 1, check if they were uploaded to repository before. If yes (true), upload the new version of the file. Otherwise (false) create the file in repository.",
        "height": 731.633426614796,
        "width": 703.8733020263451
      },
      "id": "6ae3aa95-1a18-44ed-a67e-97798e4ab34d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "operation": "binaryToPropery",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        760,
        480
      ],
      "id": "c680f4a5-449d-4084-babe-d2ba7ac0ead7",
      "name": "Extract from File"
    },
    {
      "parameters": {
        "operation": "binaryToPropery",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        520,
        240
      ],
      "id": "ccbcb820-756c-4f11-8006-25c0fefe6c67",
      "name": "Extract from File1"
    }
  ],
  "connections": {
    "Execute workflow": {
      "main": [
        [
          {
            "node": "Set date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set date": {
      "main": [
        [
          {
            "node": "Format date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format date": {
      "main": [
        [
          {
            "node": "Set commit date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set commit date": {
      "main": [
        [
          {
            "node": "List files from repository [GITHUB]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List files from repository [GITHUB]": {
      "main": [
        [
          {
            "node": "Combine file names [GITHUB]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine file names [GITHUB]": {
      "main": [
        [
          {
            "node": "Retrieve workflows [N8N]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve workflows [N8N]": {
      "main": [
        [
          {
            "node": "Move JSON to binary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move JSON to binary": {
      "main": [
        [
          {
            "node": "Split to single items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split to single items": {
      "main": [
        [
          {
            "node": "Check if file exists in repository",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if file exists in repository": {
      "main": [
        [
          {
            "node": "Extract from File1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update file [GITHUB]": {
      "main": [
        [
          {
            "node": "Split to single items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload file [GITHUB]": {
      "main": [
        [
          {
            "node": "Split to single items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Upload file [GITHUB]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File1": {
      "main": [
        [
          {
            "node": "Update file [GITHUB]",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "versionId": "f1f04fba-6653-4d0d-b155-76a5862df882",
  "triggerCount": 0,
  "tags": []
}