{
  "id": "xbFG1VQgx7lFTfmv",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Back up n8n workflows to Google Drive",
  "tags": [],
  "nodes": [
    {
      "id": "6de42dee-88cb-45cb-918e-e499f0533221",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        736
      ],
      "parameters": {
        "color": 7,
        "height": 624,
        "content": "## Trigger workflow execution\n\nInitiates the workflow manually or on a schedule."
      },
      "typeVersion": 1
    },
    {
      "id": "949ec0b3-c1f7-465a-a9b8-7a9c0515aeec",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1312,
        928
      ],
      "parameters": {
        "color": 7,
        "height": 304,
        "content": "## Create new folder\n\nCreates a new folder in Google Drive to store files."
      },
      "typeVersion": 1
    },
    {
      "id": "e7bd60cb-365d-4692-8bdb-2628d88880d8",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1568,
        912
      ],
      "parameters": {
        "color": 7,
        "width": 784,
        "height": 464,
        "content": "## Process items batch\n\nIterates over items, converts them to files, and uploads files to Google Drive."
      },
      "typeVersion": 1
    },
    {
      "id": "20922698-44b0-48fc-8196-4e2f253a4379",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2384,
        912
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 368,
        "content": "## Filter and delete folders\n\nRetrieves folders, filters them, and deletes those matching criteria."
      },
      "typeVersion": 1
    },
    {
      "id": "d1127f75-5466-4f73-9770-215418ace0ac",
      "name": "Batch Process Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1824,
        1056
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "f3987335-d00e-474f-b338-5f9ed612fc8c",
      "name": "Convert Data to File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        2016,
        1168
      ],
      "parameters": {
        "options": {
          "format": true,
          "fileName": "={{ $json.name + \".json\" }}"
        },
        "operation": "toJson"
      },
      "typeVersion": 1.1
    },
    {
      "id": "39aa1d45-f44d-4407-9bad-60dac270943f",
      "name": "Scheduled Every 4 Hours",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1040,
        1200
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 4
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "85436ae0-053d-4862-8138-9613fa1fdf1f",
      "name": "Filter by Condition",
      "type": "n8n-nodes-base.filter",
      "position": [
        2656,
        1040
      ],
      "parameters": {
        "options": {
          "ignoreCase": true
        },
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "538fc29d-2693-4c62-9848-bdcaf8566909",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": "={{ $('Create Google Drive Folder').item.json.id }}"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "ac59ff8d-61bd-44db-9845-69e6b27f5462",
      "name": "Delete Google Drive Folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2864,
        1040
      ],
      "parameters": {
        "options": {
          "deletePermanently": true
        },
        "resource": "folder",
        "operation": "deleteFolder",
        "folderNoRootId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "06beb07d-9b40-4df5-ba0b-fa23c3079604",
      "name": "List Google Drive Folders",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2464,
        1040
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "list",
            "value": "1lWeMpcjHdDwWWA1OI5N1obxh-TbFBXql",
            "cachedResultUrl": "https://drive.google.com/drive/folders/1lWeMpcjHdDwWWA1OI5N1obxh-TbFBXql",
            "cachedResultName": "Workflow Backups"
          }
        },
        "options": {},
        "resource": "fileFolder"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "ff4943ee-3cf2-4288-a1a2-41fff43f9c2d",
      "name": "Upload File to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2192,
        1168
      ],
      "parameters": {
        "name": "={{ $('Batch Process Items').item.json.name + \".json\" }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Create Google Drive Folder').item.json.id }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "d0bb24d6-bf10-4219-a07e-a7752521bca1",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        624
      ],
      "parameters": {
        "width": 480,
        "height": 768,
        "content": "## Back up n8n workflows to Google Drive\n### How it works\n\n1. Workflow triggered manually or on schedule.\n2. Creates new folder in Google Drive.\n3. Iterates over items to process files.\n4. Converts items to files and uploads them.\n5. Retrieves folders and filters unnecessary ones.\n6. Deletes filtered folders.\n\n### Setup steps\n\n- [ ] Set up Google Drive credentials to allow create, retrieve, upload, and delete operations.\n- [ ] Ensure n8n credentials are properly configured for execution.\n\n### Customization\n\nChange the backup schedule in the Schedule Trigger node.\nModify the backup folder naming format if needed.\nStore backups in a different Google Drive location.\nAdjust the folder cleanup logic to keep more historical backups.\nAdd notifications through email or Slack after successful backups."
      },
      "typeVersion": 1
    },
    {
      "id": "c85c8662-34d8-4893-a822-f0592b2886fa",
      "name": "Process in n8n1",
      "type": "n8n-nodes-base.n8n",
      "position": [
        1616,
        1056
      ],
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "6986456b-a103-4c2b-9098-e390fd1fef34",
      "name": "Manual Trigger Execution",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        1040,
        944
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "eeb40fbb-b2a6-4c67-b70e-6060004b0a35",
      "name": "Create Google Drive Folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1376,
        1056
      ],
      "parameters": {
        "name": "=Workflow Backups {{ $now.format('cccc t dd-MM-yyyy') }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1lWeMpcjHdDwWWA1OI5N1obxh-TbFBXql",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1lWeMpcjHdDwWWA1OI5N1obxh-TbFBXql",
          "cachedResultName": "Workflow Backups"
        },
        "resource": "folder"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "d3e4aa8f-7450-4673-99e0-f5ad0a364d8e",
  "connections": {
    "Process in n8n1": {
      "main": [
        [
          {
            "node": "Batch Process Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Batch Process Items": {
      "main": [
        [
          {
            "node": "List Google Drive Folders",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Convert Data to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter by Condition": {
      "main": [
        [
          {
            "node": "Delete Google Drive Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Data to File": {
      "main": [
        [
          {
            "node": "Upload File to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scheduled Every 4 Hours": {
      "main": [
        [
          {
            "node": "Create Google Drive Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger Execution": {
      "main": [
        [
          {
            "node": "Create Google Drive Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Google Drive Folders": {
      "main": [
        [
          {
            "node": "Filter by Condition",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Google Drive Folder": {
      "main": [
        [
          {
            "node": "Process in n8n1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload File to Google Drive": {
      "main": [
        [
          {
            "node": "Batch Process Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}