{
  "id": "yuDGOvdiNkK6deRG",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Auto backup n8n workflows to Google Drive with scheduled cleanup",
  "tags": [
    {
      "id": "lw9FNkMJwR1KXClQ",
      "name": "Produ\u00e7\u00e3o",
      "createdAt": "2025-11-12T12:23:34.954Z",
      "updatedAt": "2025-11-12T12:23:34.954Z"
    }
  ],
  "nodes": [
    {
      "id": "26e182d5-4342-4706-8a22-efc9d46a9354",
      "name": ">15d",
      "type": "n8n-nodes-base.if",
      "position": [
        2496,
        720
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "2507663f-1a26-45e5-ae9e-e505e115590d",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.timeDifference.days }}",
              "rightValue": 15
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "61b154ec-ea37-4ac8-91b3-13451e1210ce",
      "name": "start4h",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1984,
        480
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 4,
              "triggerAtMinute": 1
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5bf5adf9-0aa6-4a44-84af-18373c1353da",
      "name": "start3h",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1984,
        720
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 3,
              "triggerAtMinute": 1
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "50d5d48e-0015-4c54-858e-427a5160784c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1936,
        656
      ],
      "parameters": {
        "width": 996,
        "height": 220,
        "content": "## Delete after 15 days\n"
      },
      "typeVersion": 1
    },
    {
      "id": "563dd560-4c54-4f1a-b4c5-66c59648be91",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1936,
        416
      ],
      "parameters": {
        "color": 4,
        "width": 1420,
        "height": 220,
        "content": "## Daily Backup"
      },
      "typeVersion": 1
    },
    {
      "id": "ad8dcaec-c3e3-4a70-a596-20350813304c",
      "name": "Create folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2192,
        480
      ],
      "parameters": {
        "name": "={{ $json.Month }}-{{ $json[\"Day of month\"] }}-{{ $json.Year }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1HJYupeDiynEpa58lmXas-wRAD3zrpbIf",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1HJYupeDiynEpa58lmXas-wRAD3zrpbIf",
          "cachedResultName": "BKP_AtendON"
        },
        "resource": "folder"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "0d340186-f87e-40d2-84e9-fb8ed0291ba6",
      "name": "ConvertToJson",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        2848,
        480
      ],
      "parameters": {
        "mode": "each",
        "options": {
          "format": true,
          "fileName": "={{ $json.name }}.json\n"
        },
        "operation": "toJson"
      },
      "typeVersion": 1.1
    },
    {
      "id": "4cef7af7-6aab-4509-ae4d-6dc7e583e31f",
      "name": "apiN8N",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2512,
        480
      ],
      "parameters": {
        "url": "https://noiton.atendon.com.br/api/v1/workflows",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "accept",
              "value": "application/json"
            },
            {
              "name": "X-N8N-API-KEY",
              "value": "eyJ_YOUR_JWT_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "0f412098-4774-4df1-8c1b-14d3bf6a7a49",
      "name": "5s",
      "type": "n8n-nodes-base.wait",
      "position": [
        3008,
        480
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "d7d4d4a5-ef02-4cf4-98e5-0f415dcc4211",
      "name": "Delete folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2736,
        720
      ],
      "parameters": {
        "options": {},
        "resource": "folder",
        "operation": "deleteFolder",
        "folderNoRootId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('get folder').item.json.id }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "d913f502-c2ff-4369-9ef2-81f686693dd2",
      "name": "Split",
      "type": "n8n-nodes-base.code",
      "notes": "separa cada flow",
      "position": [
        2672,
        480
      ],
      "parameters": {
        "jsCode": "// A vari\u00e1vel $input.first().json.data cont\u00e9m o array de workflows.\nconst workflows = $input.first().json.data;\n\n// Mapeia o array de workflows para um novo array onde cada workflow\n// \u00e9 encapsulado como um item individual para o n8n.\nconst output = workflows.map(workflow => {\n  return {\n    json: workflow\n  };\n});\n\n// Retorna o array de itens.\nreturn output;"
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "c080bb57-deac-4b04-841c-12d4e685646f",
      "name": "get folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2144,
        720
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "list",
            "value": "1HJYupeDiynEpa58lmXas-wRAD3zrpbIf",
            "cachedResultUrl": "https://drive.google.com/drive/folders/1HJYupeDiynEpa58lmXas-wRAD3zrpbIf",
            "cachedResultName": "BKP_AtendON"
          },
          "whatToSearch": "all"
        },
        "options": {
          "fields": [
            "*"
          ]
        },
        "resource": "fileFolder",
        "returnAll": true
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "18c633d6-baa8-40d2-81b2-5a5411a9fa38",
      "name": "Check date",
      "type": "n8n-nodes-base.dateTime",
      "position": [
        2320,
        720
      ],
      "parameters": {
        "endDate": "={{ new Date().toISOString().split('T')[0] }}",
        "options": {},
        "operation": "getTimeBetweenDates",
        "startDate": "={{ new Date($json.createdTime).toISOString().split('T')[0] }}"
      },
      "typeVersion": 2
    },
    {
      "id": "e31c439a-5a6c-44b7-8e0c-62db858bb510",
      "name": "Format data",
      "type": "n8n-nodes-base.set",
      "position": [
        2336,
        480
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a4766e36-a769-4366-8fff-5c1e826714a1",
              "name": "data",
              "type": "string",
              "value": "={{ $json.name }}"
            },
            {
              "id": "65f42e99-145e-4ba1-86b7-d86a7762e02d",
              "name": "id",
              "type": "string",
              "value": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "6766dcc7-5bb7-4a61-9700-cb684fa1a58c",
      "name": "upload file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        3168,
        480
      ],
      "parameters": {
        "name": "={{ $('Split').item.json.name }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Format data').item.json.id }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "4cfc0fbe-1ece-4c0d-bd0c-edd769263e20",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1472,
        416
      ],
      "parameters": {
        "width": 448,
        "height": 864,
        "content": "## n8n Workflow Backup to Google Drive\n\nThis workflow automatically creates daily backups of all n8n workflows and stores them in Google Drive. It also removes old backups automatically to keep storage organized.\n\nThe workflow runs on a schedule and exports all workflows using the n8n API. Each workflow is saved as an individual .json file inside a folder created with the current date.\n\nA second scheduled process checks existing backup folders and deletes folders older than 15 days.\n\nThis ensures you always have recent backups while keeping your storage clean.\n\n\n## How it works\n\n1. A Schedule Trigger starts the daily backup\n2. A folder is created in Google Drive using the current date\n3. The n8n API retrieves all workflows\n4. Workflows are split into individual items\n5. Each workflow is converted into a .json file\n6. Files are uploaded to the created Google Drive folder\n7. Another schedule lists existing backup folders\n8. The workflow calculates how many days old each folder is\n9. Folders older than 15 days are deleted\n\n\n## Setup steps\n\n1. Connect a Google Drive OAuth credential\n2. Set the Google Drive root folder ID for backups\n3. Configure access to the n8n API\n4. Adjust the schedule times if needed\n5. Adjust the retention period (default 15 days)"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "9849c1c2-f538-40e5-a0c9-d4bb252470b8",
  "connections": {
    "5s": {
      "main": [
        [
          {
            "node": "upload file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    ">15d": {
      "main": [
        [
          {
            "node": "Delete folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split": {
      "main": [
        [
          {
            "node": "ConvertToJson",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "apiN8N": {
      "main": [
        [
          {
            "node": "Split",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "start3h": {
      "main": [
        [
          {
            "node": "get folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "start4h": {
      "main": [
        [
          {
            "node": "Create folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check date": {
      "main": [
        [
          {
            "node": ">15d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get folder": {
      "main": [
        [
          {
            "node": "Check date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format data": {
      "main": [
        [
          {
            "node": "apiN8N",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ConvertToJson": {
      "main": [
        [
          {
            "node": "5s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create folder": {
      "main": [
        [
          {
            "node": "Format data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}