8
n8n 中文网amn8n.com

n8n 工作流备份与恢复

高级

这是一个自动化工作流,包含 28 个节点。主要使用 If, N8n, Code, Wait, Telegram 等节点。 使用 Telegram、Google Drive 和表单上传备份与恢复 n8n 工作流

前置要求
  • Telegram Bot Token
  • Google Drive API 凭证

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "3d7eb9567ae690bf8c9bba1cb43396e6e40c18e15eb5889cf9673ed1713da6db",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "5b97598a-3366-4294-b76d-273c00ef1fdd",
      "name": "手动触发器",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        6000,
        1040
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "33b8396b-2889-4daf-8ffb-bc11a4324448",
      "name": "计划备份触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        5984,
        560
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "daysInterval": 3
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "81c12768-16bd-4103-a1eb-24af472c457a",
      "name": "注意:计划触发器",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5904,
        352
      ],
      "parameters": {
        "color": 6,
        "width": 376,
        "height": 176,
        "content": "## ⏰ 计划备份触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "290dfccd-f8a1-467d-a65f-9f5774e2d8ee",
      "name": "获取所有工作流",
      "type": "n8n-nodes-base.n8n",
      "position": [
        6208,
        560
      ],
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "YsSsp8tsvvN7Eau2",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "58f2ba7e-aa94-43fe-a103-9ef22e1d2f2a",
      "name": "注意:获取工作流",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5952,
        720
      ],
      "parameters": {
        "color": 5,
        "width": 488,
        "height": 144,
        "content": "## 🔍 获取所有工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "9d9356c3-9683-47a9-9a21-7ba579cbb280",
      "name": "聚合工作流",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        6416,
        560
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "03200b93-3f13-47f8-a0ff-700e17e2fe6b",
      "name": "注意:聚合数据",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6352,
        368
      ],
      "parameters": {
        "color": 3,
        "width": 360,
        "height": 176,
        "content": "## 📊 聚合工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "862faac9-bfd8-4b11-a467-2eeb0d54292d",
      "name": "转换为备份文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        6640,
        560
      ],
      "parameters": {
        "options": {},
        "operation": "toText",
        "sourceProperty": "data"
      },
      "typeVersion": 1.1
    },
    {
      "id": "ade96952-54bc-444c-9bdd-57fd4a798169",
      "name": "注意:转换文件",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6528,
        720
      ],
      "parameters": {
        "color": 3,
        "width": 472,
        "height": 144,
        "content": "## 📄 转换为备份文件"
      },
      "typeVersion": 1
    },
    {
      "id": "f2b52a80-00ad-4316-aa6f-4bef50626826",
      "name": "发送备份到 Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        6848,
        560
      ],
      "webhookId": "8398a972-7215-47ec-8178-193bd910b5e3",
      "parameters": {
        "chatId": "{{your_chat_id}}",
        "operation": "sendDocument",
        "binaryData": true,
        "additionalFields": {
          "fileName": "All-n8n-workflows.txt"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "Elo6BLaLpBDVgeLW",
          "name": "LinkedIn Post"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b33de46e-16c6-4939-b9dd-ad181bb6d1b2",
      "name": "注意:发送到 Telegram",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7136,
        560
      ],
      "parameters": {
        "color": 6,
        "width": 344,
        "height": 176,
        "content": "## 📤 发送备份到 Telegram"
      },
      "typeVersion": 1
    },
    {
      "id": "72b820a1-4af5-45c2-bb43-e061d8d44177",
      "name": "从 Drive 下载备份",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        6240,
        1040
      ],
      "parameters": {
        "fileId": "{{your_file_id}}",
        "options": {
          "fileName": "all_workflows"
        },
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ojkPtWn622t1FPAy",
          "name": "Ewere"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "75ebfa45-7372-41a6-868e-73c7ea4df4bc",
      "name": "注意:从 Drive 下载",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6352,
        896
      ],
      "parameters": {
        "color": 6,
        "width": 280,
        "height": 208,
        "content": "## 📥 从 Drive 下载备份"
      },
      "typeVersion": 1
    },
    {
      "id": "437b283a-1f3e-4297-be0d-60d9aa5a1e3b",
      "name": "表单恢复触发器",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        6224,
        1264
      ],
      "webhookId": "308ea5b0-fbea-4364-8c08-5237e4f7058f",
      "parameters": {
        "options": {},
        "formTitle": "Upload Backup File",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "data"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "dfe569ab-8a3d-4665-9217-0239fb82cad2",
      "name": "注意:表单触发器",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5952,
        1424
      ],
      "parameters": {
        "color": 6,
        "width": 280,
        "height": 192,
        "content": "## 📝 表单恢复触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "319499bc-5aab-4608-a53f-14681ff37879",
      "name": "提取备份文本",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        6400,
        1184
      ],
      "parameters": {
        "options": {},
        "operation": "text"
      },
      "typeVersion": 1
    },
    {
      "id": "8c8b6f65-2265-4d5e-ae5d-64e060c18a17",
      "name": "注意:提取文本",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6304,
        1424
      ],
      "parameters": {
        "color": 3,
        "width": 392,
        "height": 192,
        "content": "## 📖 提取备份文本"
      },
      "typeVersion": 1
    },
    {
      "id": "c364c0f4-956c-4893-8cfa-2c3f49b87d53",
      "name": "解析备份 JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        6576,
        1184
      ],
      "parameters": {
        "jsCode": "// The input from the previous node is an array of items. We'll work with the first item.\nconst item = items[0];\n\n// --- IMPORTANT ---\n// The 'Extract from File' node will place the file's content into a property.\n// You may need to adjust 'fileContent' to match the actual property name from that node.\nconst jsonString = item.json.data;\n\nif (!jsonString) {\n  throw new Error(\"The property 'fileContent' was not found in the input data. Please check the output of the 'Extract from File' node and update the property name in this code.\");\n}\n\n// Parse the large JSON string into an array of individual workflow objects.\nconst workflows = JSON.parse(jsonString);\n\n// List of settings properties that are not supported by the n8n API\nconst unsupportedSettingsProperties = [\n  'executionOrder',\n  'callerPolicy', \n  'errorWorkflow',\n  'timeSavedPerExecution',\n  'executionTimeout',\n  'maxExecutionTimeout'\n];\n\n// Return each workflow as a separate item.\n// For each item, convert the workflow object back into a string\n// and place it in a property called 'data'.\nreturn workflows.map(workflow => {\n  // Extract workflow name and ID for easier reference\n  const workflowName = workflow.name || 'Unnamed Workflow';\n  const workflowId = workflow.id || 'No ID';\n  \n  // Create a cleaned copy of the workflow\n  const cleanedWorkflow = { ...workflow };\n  \n  // Clean up the settings object by removing unsupported properties\n  if (cleanedWorkflow.settings) {\n    const cleanedSettings = { ...cleanedWorkflow.settings };\n    \n    // Remove unsupported properties\n    unsupportedSettingsProperties.forEach(prop => {\n      delete cleanedSettings[prop];\n    });\n    \n    cleanedWorkflow.settings = cleanedSettings;\n  }\n  \n  // Remove properties that shouldn't be included when creating new workflows\n  delete cleanedWorkflow.id;           // Let n8n assign a new ID\n  delete cleanedWorkflow.createdAt;    // Will be set by n8n\n  delete cleanedWorkflow.updatedAt;    // Will be set by n8n\n  delete cleanedWorkflow.versionId;    // Will be set by n8n\n  delete cleanedWorkflow.shared;       // Will be handled by n8n\n  delete cleanedWorkflow.triggerCount; // Will be reset by n8n\n  \n  // Clean up staticData - remove if empty or clean node-specific data\n  if (cleanedWorkflow.staticData) {\n    const cleanedStaticData = { ...cleanedWorkflow.staticData };\n    // Remove any node-specific data that might reference old node IDs\n    Object.keys(cleanedStaticData).forEach(key => {\n      if (key.startsWith('node:')) {\n        delete cleanedStaticData[key];\n      }\n    });\n    // Remove staticData entirely if it's empty after cleaning\n    if (Object.keys(cleanedStaticData).length === 0) {\n      delete cleanedWorkflow.staticData;\n    } else {\n      cleanedWorkflow.staticData = cleanedStaticData;\n    }\n  }\n  \n  // Keep pinData as it contains important test/development data\n  // Only remove pinData if it's undefined, but preserve empty objects\n  \n  // Clean up meta object - remove or clean problematic properties\n  if (cleanedWorkflow.meta) {\n    const cleanedMeta = { ...cleanedWorkflow.meta };\n    // Remove properties that might cause issues with new workflow creation\n    delete cleanedMeta.templateCredsSetupCompleted;\n    delete cleanedMeta.instanceId;\n    \n    // Remove meta entirely if it's empty after cleaning\n    if (Object.keys(cleanedMeta).length === 0) {\n      delete cleanedWorkflow.meta;\n    } else {\n      cleanedWorkflow.meta = cleanedMeta;\n    }\n  }\n  \n  // Clean webhook IDs from nodes that might conflict\n  if (cleanedWorkflow.nodes) {\n    cleanedWorkflow.nodes = cleanedWorkflow.nodes.map(node => {\n      const cleanedNode = { ...node };\n      \n      // Remove webhookId property that might reference old webhook instances\n      if (cleanedNode.webhookId) {\n        delete cleanedNode.webhookId;\n      }\n      \n      return cleanedNode;\n    });\n  }\n  \n  return {\n    json: {\n      data: JSON.stringify(cleanedWorkflow),\n      workflowName: workflowName,\n      originalId: workflowId,\n      // Additional metadata for debugging\n      hasSettings: !!workflow.settings,\n      nodeCount: workflow.nodes ? workflow.nodes.length : 0\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "05297227-aff4-4c99-a45d-c73f7c4c15fa",
      "name": "注意:解析 JSON",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6752,
        1424
      ],
      "parameters": {
        "color": 3,
        "width": 456,
        "height": 176,
        "content": "## 🔄 解析备份 JSON"
      },
      "typeVersion": 1
    },
    {
      "id": "8b7750d5-5edb-4e1c-8abf-6124bc5de56a",
      "name": "处理每个工作流",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        6752,
        1024
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "2c33e527-7e91-4f55-be2e-92d6b2cbbeec",
      "name": "注意:工作流循环",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7104,
        864
      ],
      "parameters": {
        "color": 5,
        "width": 360,
        "height": 192,
        "content": "## 🔄 处理每个工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "74eaf063-91e3-4bfd-a52e-4284fe317a89",
      "name": "检查工作流是否存在",
      "type": "n8n-nodes-base.n8n",
      "position": [
        6944,
        1088
      ],
      "parameters": {
        "filters": {
          "name": "={{ $json.workflowName }}"
        },
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "YsSsp8tsvvN7Eau2",
          "name": "n8n account"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "a7d3a105-06bb-47de-90ce-f0c63ac6f99b",
      "name": "如果工作流存在",
      "type": "n8n-nodes-base.if",
      "position": [
        7104,
        1088
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b384d46d-cd29-4362-8e36-e1b563329156",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.name }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ff3a4413-c015-4b89-a5b8-02b4329669a0",
      "name": "创建新工作流",
      "type": "n8n-nodes-base.n8n",
      "onError": "continueErrorOutput",
      "position": [
        7504,
        1200
      ],
      "parameters": {
        "operation": "create",
        "requestOptions": {},
        "workflowObject": "={{ $('Process Each Workflow').item.json.data }}"
      },
      "credentials": {
        "n8nApi": {
          "id": "YsSsp8tsvvN7Eau2",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "12136a58-7361-4693-ae20-09f29c5c2357",
      "name": "更新现有工作流",
      "type": "n8n-nodes-base.n8n",
      "position": [
        7280,
        1216
      ],
      "parameters": {
        "operation": "update",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "requestOptions": {},
        "workflowObject": "={{ $('Process Each Workflow').item.json.data }}"
      },
      "credentials": {
        "n8nApi": {
          "id": "YsSsp8tsvvN7Eau2",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f9de86be-f71a-449d-8968-1353d04dd32c",
      "name": "等待完成",
      "type": "n8n-nodes-base.wait",
      "position": [
        7696,
        1216
      ],
      "webhookId": "a6cb7280-b53e-465a-b61d-3b4ef03928db",
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "9a316313-8f57-4376-90d4-1c5d68f03a7a",
      "name": "注意:等待延迟",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7680,
        1008
      ],
      "parameters": {
        "color": 2,
        "width": 328,
        "height": 176,
        "content": "## ⏳ 等待完成"
      },
      "typeVersion": 1
    },
    {
      "id": "9c3e12fb-9375-4c5c-b19e-e67c7a717599",
      "name": "概述注释3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5280,
        368
      ],
      "parameters": {
        "color": 4,
        "width": 600,
        "height": 1256,
        "content": "# 自动化 n8n 工作流备份与多路径恢复"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Download Backup from Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Backup JSON": {
      "main": [
        [
          {
            "node": "Process Each Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Workflow Exists": {
      "main": [
        [
          {
            "node": "Create New Workflow",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Existing Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Workflows": {
      "main": [
        [
          {
            "node": "Convert to Backup File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create New Workflow": {
      "main": [
        [
          {
            "node": "Wait for Completion",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Process Each Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Backup Text": {
      "main": [
        [
          {
            "node": "Parse Backup JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch All Workflows": {
      "main": [
        [
          {
            "node": "Aggregate Workflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Completion": {
      "main": [
        [
          {
            "node": "Process Each Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Form Restore Trigger": {
      "main": [
        [
          {
            "node": "Extract Backup Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Each Workflow": {
      "main": [
        [],
        [
          {
            "node": "Check Workflow Existence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to Backup File": {
      "main": [
        [
          {
            "node": "Send Backup to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Backup Trigger": {
      "main": [
        [
          {
            "node": "Fetch All Workflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Workflow Existence": {
      "main": [
        [
          {
            "node": "If Workflow Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Existing Workflow": {
      "main": [
        [
          {
            "node": "Process Each Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Backup from Drive": {
      "main": [
        [
          {
            "node": "Extract Backup Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量28
分类-
节点类型14
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Daniel Nkencho

Daniel Nkencho

@daniel-automates

AI Automation Consultant | Helping Business Owners Implement AI Systems for Growth and Lead Gen

外部链接
在 n8n.io 查看

分享此工作流