Google Drive へのワークフロー備份とスマートクリーンアップ

上級

これはDevOps, Multimodal AI分野の自動化ワークフローで、17個のノードを含みます。主にN8n, Set, Code, GoogleDrive, ConvertToFileなどのノードを使用。 Google Drive へのワークフロー バックアップの自動化と スマートなクリーンアップ

前提条件
  • Google Drive API認証情報
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
  "meta": {
    "instanceId": "c582d54231d7262c638a00ee408faa972b8030c20ecfa02b3d445f84745245ff",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "b7a4ebea-711b-473d-b18a-7bf84a888a17",
      "name": "スケジュールトリガー",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1456,
        -72
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 3
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c7d51e5b-0add-4c66-8d85-e98d3a09f72e",
      "name": "手動トリガー",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1456,
        -264
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "73b8a7f5-d038-4366-b30b-a92195db3a35",
      "name": "ファイルとフォルダを検索",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -16,
        -480
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "id",
            "value": "={{ $('CONFIG - Set your variables here').item.json.parentFolderId }}"
          }
        },
        "options": {},
        "resource": "fileFolder",
        "returnAll": true,
        "queryString": "Workflows backup - "
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ardYGrL3hsVqtoGo",
          "name": "Google Drive"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "adc967fc-746c-462c-9de8-f823100d833d",
      "name": "クリーンアップ開始(1回実行)",
      "type": "n8n-nodes-base.set",
      "position": [
        -240,
        -480
      ],
      "parameters": {
        "options": {}
      },
      "executeOnce": true,
      "typeVersion": 3.4
    },
    {
      "id": "1f4ad497-fbf8-4053-80fc-f22c9200370c",
      "name": "古いフォルダを仕分け・分離",
      "type": "n8n-nodes-base.code",
      "position": [
        208,
        -480
      ],
      "parameters": {
        "jsCode": "// Get the number of backups to keep from the config node\nconst backupsToKeep = $json.backupsToKeep;\n\n// 'items' contains the list of folders from the previous node\nconst folders = $input.all(); \nconst sortedFolders = folders.map(item => item.json);\n\n// 1. Sort the folders from newest to oldest\nsortedFolders.sort((a, b) => new Date(b.createdTime) - new Date(a.createdTime));\n\n// 2. Get only the excess folders to delete\nconst foldersToDelete = sortedFolders.slice(backupsToKeep);\n\n// 3. Return the final list to be passed to the loop\nreturn foldersToDelete;"
      },
      "typeVersion": 2
    },
    {
      "id": "ff6c6c87-2751-4429-a196-edc65f898e43",
      "name": "削除対象フォルダをループ処理",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        432,
        -480
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "7669d1df-6225-47aa-841b-c14f48cbd2e3",
      "name": "各ワークフローをループ処理",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -560,
        -144
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "c7a911aa-e8a2-42a3-a64b-5c2c4318720a",
      "name": "すべてのn8nワークフローを取得",
      "type": "n8n-nodes-base.n8n",
      "position": [
        -784,
        -144
      ],
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "iV99kO3Ts0Yartt4",
          "name": "N8n"
        }
      },
      "executeOnce": false,
      "retryOnFail": false,
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "id": "20acb740-7157-4e30-bd4d-04b8663a8f8d",
      "name": "新規バックアップフォルダを作成",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -1008,
        -144
      ],
      "parameters": {
        "name": "=Workflows backup - {{ $now.format('yyyy-MM-dd') }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('CONFIG - Set your variables here').item.json.parentFolderId }}"
        },
        "resource": "folder"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ardYGrL3hsVqtoGo",
          "name": "Google Drive"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "82b9a618-2765-4c53-baa7-66a025808c2d",
      "name": "ワークフローをファイルに変換",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -240,
        16
      ],
      "parameters": {
        "options": {
          "format": true,
          "fileName": "={{ $json.name + \".json\" }} "
        },
        "operation": "toJson"
      },
      "typeVersion": 1.1
    },
    {
      "id": "1f14d31c-9ab6-4b4f-b054-a02f1b75336f",
      "name": "ワークフローをGoogle Driveにアップロード",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -16,
        16
      ],
      "parameters": {
        "name": "={{ $('Loop over each workflow').item.json.name + \".json\" }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive",
          "cachedResultName": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Create new backup folder').item.json.id }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ardYGrL3hsVqtoGo",
          "name": "Google Drive"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "db4893e5-8a63-4d3d-9067-6a6d68ed3119",
      "name": "古いフォルダを削除",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        656,
        -480
      ],
      "parameters": {
        "options": {},
        "resource": "folder",
        "operation": "deleteFolder",
        "folderNoRootId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ardYGrL3hsVqtoGo",
          "name": "Google Drive"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "d6769f88-ffc4-4c1d-b8be-082109b12dde",
      "name": "CONFIG - 変数をここで設定",
      "type": "n8n-nodes-base.set",
      "position": [
        -1232,
        -144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "5da1b756-88b7-4ba2-bc87-0ea4298b78ce",
              "name": "parentFolderId",
              "type": "string",
              "value": "PASTE_YOUR_GOOGLE_DRIVE_PARENT_FOLDER_ID_HERE"
            },
            {
              "id": "79da4836-d768-4b7d-b64f-bc820583613a",
              "name": "backupsToKeep",
              "type": "number",
              "value": 30
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "06268a9d-854e-47ee-b6f5-38c8dd57ee20",
      "name": "付箋",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2112,
        -336
      ],
      "parameters": {
        "width": 560,
        "height": 432,
        "content": "## How to find your Google Drive Folder ID\nTo tell the workflow where to save your backups, you need to provide the ID of a parent folder in your Google Drive.\n\n1.  Go to [Google Drive](https://drive.google.com) and navigate to the folder you want to use. You can also create a new one (e.g., a folder named \"n8n Backups\").\n2.  Click on the folder to open it.\n3.  Look at the URL in your browser's address bar. The Folder ID is the long string of characters at the end of the URL.\n\n**Example:**\nIf your browser URL is:\n`https://drive.google.com/drive/folders/`**`1Fs3gg7pSVhbvODJQLcgAfP-V0rCGC_Oc`**\n\nThen your Folder ID is:\n**`1Fs3gg7pSVhbvODJQLcgAfP-V0rCGC_Oc`**\n\nCopy this ID and paste it into the `parentFolderId` field in the **\"CONFIG - Set your variables here\"** node."
      },
      "typeVersion": 1
    },
    {
      "id": "1907cd86-02d6-473a-a605-4518d83c2b1b",
      "name": "付箋1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        -608
      ],
      "parameters": {
        "color": 7,
        "width": 1168,
        "height": 336,
        "content": "## Cleanup Logic: Finds and deletes old backup folders\nThis first part of the workflow handles automatic maintenance. It searches for all existing backup folders in your Google Drive, sorts them by creation date, and keeps only the most recent ones (the number is configurable). All older folders are then automatically deleted to save space.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "dcad82b1-69e9-484f-8d06-cadc311a5ac7",
      "name": "付箋2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        -208
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 432,
        "content": "## Backup Logic: Fetches all workflows and uploads them to a new daily folder\nThis is the core backup process. It begins by creating a new, dated folder for the current day's backup. It then fetches a complete list of all your n8n workflows, converts each one into a .json file, and uploads them to the new folder, creating a complete and organized daily snapshot."
      },
      "typeVersion": 1
    },
    {
      "id": "fb976047-3811-437a-b19c-de8def3fe06c",
      "name": "付箋3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2736,
        -560
      ],
      "parameters": {
        "width": 560,
        "height": 848,
        "content": "## Backup n8n workflows to Google Drive with automatic cleanup\n\nThis template automates the process of backing up all your n8n workflows to Google Drive, ensuring you always have a safe copy of your automations. It also includes a smart cleanup mechanism to automatically delete old backups, keeping your Drive organized and saving space.\n\n## Who’s it for\nThis workflow is ideal for any n8n user, from solo developers to teams, who want a reliable and automated \"set-it-and-forget-it\" backup solution for their critical workflows.\n\n## What it does\n* **Daily Execution**: The workflow runs automatically every night (or can be triggered manually).\n* **Automated Cleanup**: After running a new backup, it searches for all previous backup folders. It keeps the most recent ones (you can define how many) and deletes all the older folders.\n* **Creates Daily Folders**: It creates a new, neatly named folder in your Google Drive for each day's backup (e.g., `Workflows backup - 2025-08-17`).\n* **Fetches and Saves**: It connects to your n8n instance via API, fetches all your workflows, and saves each one as a `.json` file inside the daily folder.\n\n## How to set up\n1.  **Configure Credentials**: Make sure you have valid credentials for:\n    * **n8n API**: To allow the workflow to access its own list of workflows.\n    * **Google Drive**: To allow the workflow to create folders and upload files.\n2.  **Set Your Variables**: In the first `Set` node named **\"CONFIG - Set your variables here\"**:\n    * `parentFolderId`: Paste the ID of the main Google Drive folder where you want all your daily backup folders to be stored.\n    * `backupsToKeep`: Set the number of recent backups you wish to keep (e.g., 30 for a month's worth).\n\nActivate the workflow, and you're all set!"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "c7d51e5b-0add-4c66-8d85-e98d3a09f72e": {
      "main": [
        [
          {
            "node": "d6769f88-ffc4-4c1d-b8be-082109b12dde",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "b7a4ebea-711b-473d-b18a-7bf84a888a17": {
      "main": [
        [
          {
            "node": "d6769f88-ffc4-4c1d-b8be-082109b12dde",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "db4893e5-8a63-4d3d-9067-6a6d68ed3119": {
      "main": [
        [
          {
            "node": "ff6c6c87-2751-4429-a196-edc65f898e43",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "c7a911aa-e8a2-42a3-a64b-5c2c4318720a": {
      "main": [
        [
          {
            "node": "7669d1df-6225-47aa-841b-c14f48cbd2e3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7669d1df-6225-47aa-841b-c14f48cbd2e3": {
      "main": [
        [
          {
            "node": "adc967fc-746c-462c-9de8-f823100d833d",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "82b9a618-2765-4c53-baa7-66a025808c2d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "82b9a618-2765-4c53-baa7-66a025808c2d": {
      "main": [
        [
          {
            "node": "1f14d31c-9ab6-4b4f-b054-a02f1b75336f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "20acb740-7157-4e30-bd4d-04b8663a8f8d": {
      "main": [
        [
          {
            "node": "c7a911aa-e8a2-42a3-a64b-5c2c4318720a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "73b8a7f5-d038-4366-b30b-a92195db3a35": {
      "main": [
        [
          {
            "node": "1f4ad497-fbf8-4053-80fc-f22c9200370c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "adc967fc-746c-462c-9de8-f823100d833d": {
      "main": [
        [
          {
            "node": "73b8a7f5-d038-4366-b30b-a92195db3a35",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ff6c6c87-2751-4429-a196-edc65f898e43": {
      "main": [
        [],
        [
          {
            "node": "db4893e5-8a63-4d3d-9067-6a6d68ed3119",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1f4ad497-fbf8-4053-80fc-f22c9200370c": {
      "main": [
        [
          {
            "node": "ff6c6c87-2751-4429-a196-edc65f898e43",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1f14d31c-9ab6-4b4f-b054-a02f1b75336f": {
      "main": [
        [
          {
            "node": "7669d1df-6225-47aa-841b-c14f48cbd2e3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d6769f88-ffc4-4c1d-b8be-082109b12dde": {
      "main": [
        [
          {
            "node": "20acb740-7157-4e30-bd4d-04b8663a8f8d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
よくある質問

このワークフローの使い方は?

上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。

このワークフローはどんな場面に適していますか?

上級 - DevOps, マルチモーダルAI

有料ですか?

このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。

ワークフロー情報
難易度
上級
ノード数17
カテゴリー2
ノードタイプ9
難易度説明

上級者向け、16ノード以上の複雑なワークフロー

外部リンク
n8n.ioで表示

このワークフローを共有

カテゴリー

カテゴリー: 34