8
n8n 中文网amn8n.com

每日工作流备份至 GitLab 并发送 Slack 通知

高级

这是一个自动化工作流,包含 22 个节点。主要使用 If, N8n, Set, Code, Slack 等节点。 每日工作流备份至 GitLab 并发送 Slack 通知

前置要求
  • Slack Bot Token 或 Webhook URL
  • GitLab Personal Access Token

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "cfcdd4aa7acb600106c0a4bff4e6959e8e3b32b3b8cbc7d93531b2a4c9012a32"
  },
  "nodes": [
    {
      "id": "05ee377d-5402-46ee-81b4-c56e6115ecd4",
      "name": "获取所有工作流",
      "type": "n8n-nodes-base.n8n",
      "position": [
        -496,
        16
      ],
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "L1VsfzLKd4G6IpiP",
          "name": "backup-internal"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f107d96b-26cf-47ad-97fc-83f64c7b621e",
      "name": "丢弃已归档的工作流",
      "type": "n8n-nodes-base.filter",
      "position": [
        -336,
        16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3d21f751-35bf-439c-8536-ff5e8968672e",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              },
              "leftValue": "={{ $json.isArchived }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "67333676-710a-4721-82a4-f9288366c6d0",
      "name": "转换为文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        240,
        112
      ],
      "parameters": {
        "mode": "each",
        "options": {
          "format": true
        },
        "operation": "toJson"
      },
      "typeVersion": 1.1
    },
    {
      "id": "2d508a48-be41-40cd-be68-2aad83038cce",
      "name": "如果文件存在",
      "type": "n8n-nodes-base.if",
      "position": [
        400,
        112
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9798deb6-300a-48ff-9f5c-a581b2d941a7",
              "operator": {
                "type": "array",
                "operation": "contains",
                "rightType": "any"
              },
              "leftValue": "={{ $('List of Names').item.json.name }}",
              "rightValue": "={{ $('Process Each File').item.json.name }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b816f0b9-26b1-438d-877a-d1d4ad86fe89",
      "name": "配置",
      "type": "n8n-nodes-base.set",
      "position": [
        -992,
        16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "558377f5-54a6-4dd2-872a-dd1fa8f1fc9f",
              "name": "project_owner",
              "type": "string",
              "value": "PROJECT_OWNER e.g. mookielian"
            },
            {
              "id": "063bbfbf-697e-4825-8c68-af5cc7b6aa2d",
              "name": "project_name",
              "type": "string",
              "value": "PROJECT_NAME e.g. n8n"
            },
            {
              "id": "7938d2e2-b203-45fc-8432-f9f3ac241946",
              "name": "branch",
              "type": "string",
              "value": "main"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "517ef436-5323-4ffc-8ead-5c303930987e",
      "name": "名称列表",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -656,
        16
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "name"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5befe173-4171-4107-be94-4c5ad235ca76",
      "name": "创建新文件 - GitLab",
      "type": "n8n-nodes-base.gitlab",
      "onError": "continueErrorOutput",
      "position": [
        560,
        192
      ],
      "parameters": {
        "owner": "={{ $('Configuration').item.json.project_owner }}",
        "branch": "={{ $('Configuration').item.json.branch }}",
        "filePath": "={{ $('Process Each File').item.json.name }}",
        "resource": "file",
        "binaryData": true,
        "repository": "={{ $('Configuration').item.json.project_name }}",
        "commitMessage": "=File created! {{ $('Process Each File').item.json.name }}"
      },
      "credentials": {
        "gitlabApi": {
          "id": "CV2TdcFVqfePX5QH",
          "name": "GitLab Account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "20270a8c-ac47-4449-a506-618fe2362e17",
      "name": "更新文件 - GitLab",
      "type": "n8n-nodes-base.gitlab",
      "onError": "continueErrorOutput",
      "position": [
        560,
        0
      ],
      "parameters": {
        "owner": "={{ $('Configuration').item.json.project_owner }}",
        "branch": "={{ $('Configuration').item.json.branch }}",
        "filePath": "={{ $('Process Each File').item.json.name }}",
        "resource": "file",
        "operation": "edit",
        "binaryData": true,
        "repository": "={{ $('Configuration').item.json.project_name }}",
        "commitMessage": "=File was updated! {{ $('Process Each File').item.json.name }}"
      },
      "credentials": {
        "gitlabApi": {
          "id": "CV2TdcFVqfePX5QH",
          "name": "GitLab Account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "62bc4120-f641-456d-ae3c-2d450941ebe6",
      "name": "列出所有文件 - GitLab",
      "type": "n8n-nodes-base.gitlab",
      "position": [
        -832,
        16
      ],
      "parameters": {
        "owner": "={{ $('Configuration').item.json.project_owner }}",
        "resource": "file",
        "operation": "list",
        "returnAll": true,
        "repository": "={{ $('Configuration').item.json.project_name }}",
        "additionalParameters": {}
      },
      "credentials": {
        "gitlabApi": {
          "id": "CV2TdcFVqfePX5QH",
          "name": "GitLab Account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2e8a6259-5530-4e15-babf-febbad2095ac",
      "name": "每日触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1136,
        16
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 12
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "de6637b3-1a90-4683-b785-ee168de26cbe",
      "name": "处理每个文件",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -144,
        16
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "17b4693e-d52c-4f1a-97fa-2c42da170df3",
      "name": "移除不需要的字段",
      "type": "n8n-nodes-base.code",
      "position": [
        64,
        112
      ],
      "parameters": {
        "jsCode": "return $input.all().map(item => {\n  const { createdAt, updatedAt, id, name, active, isArchived, ...rest } = item.json;\n  return { json: rest };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "d96386b2-75df-49c1-9645-f50a96c92d23",
      "name": "发送消息到频道",
      "type": "n8n-nodes-base.slack",
      "position": [
        64,
        -80
      ],
      "webhookId": "7204c9cc-0e71-46ce-9760-3c49075bc472",
      "parameters": {
        "text": "=*Successful Backup!*\n\n- Execution ID: {{ $execution.id }}\n- Mode: {{ $execution.mode }}\n- Timestamp(Workflow Region): {{$now.toFormat('yyyy-MM-dd HH:mm:ss')}}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09KF70UXL3",
          "cachedResultName": "backup-notifications"
        },
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "id": "jkWLdvbGqIn5uLSh",
          "name": "n8n-backup-bot-v2"
        }
      },
      "executeOnce": true,
      "typeVersion": 2.3
    },
    {
      "id": "25cc4169-c68e-4ed8-a85c-43e432cf5dbf",
      "name": "新文件 - 失败",
      "type": "n8n-nodes-base.slack",
      "position": [
        752,
        208
      ],
      "webhookId": "5354db33-36b0-4f5b-ba5e-4d902660a1dd",
      "parameters": {
        "text": "=*Failed creating a new file - GitLab.*\n\n- File Name: {{ $('Process Each File').item.json.name }}\n- Error: {{ $json.error }}\n- Workflow State: _active={{ $('Process Each File').item.json.active }}_\n- Execution ID: {{ $execution.id }}\n- Mode: {{ $execution.mode }}\n- Timestamp(Workflow Region): {{$now.toFormat('yyyy-MM-dd HH:mm:ss')}}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09KF70UXL3",
          "cachedResultName": "backup-notifications"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "id": "jkWLdvbGqIn5uLSh",
          "name": "n8n-backup-bot-v2"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "2a2bad0d-af10-494b-aa21-48c2b1f277c3",
      "name": "更新文件 - 失败",
      "type": "n8n-nodes-base.slack",
      "position": [
        752,
        16
      ],
      "webhookId": "5354db33-36b0-4f5b-ba5e-4d902660a1dd",
      "parameters": {
        "text": "=*Failed updating specified file - GitLab.*\n\n- File Name: {{ $('Process Each File').item.json.name }}\n- Error: {{ $json.error }}\n- Workflow State: _active={{ $('Process Each File').item.json.active }}_\n- Execution ID: {{ $execution.id }}\n- Mode: {{ $execution.mode }}\n- Timestamp(Workflow Region): {{$now.toFormat('yyyy-MM-dd HH:mm:ss')}}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09KF70UXL3",
          "cachedResultName": "backup-notifications"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "id": "jkWLdvbGqIn5uLSh",
          "name": "n8n-backup-bot-v2"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "48ea9738-ef97-452b-b6ce-10db70d0920c",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1856,
        -240
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 704,
        "content": "# 欢迎"
      },
      "typeVersion": 1
    },
    {
      "id": "bbaad52a-b34c-4b43-aad2-cf187bf7c6be",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1440,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 2608,
        "height": 704,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "a5eabdaa-c744-4272-868a-7a60740278b9",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1856,
        480
      ],
      "parameters": {
        "color": 6,
        "width": 3024,
        "height": 336,
        "content": "# 凭据"
      },
      "typeVersion": 1
    },
    {
      "id": "cdcf207f-0efd-4124-95b3-3d6a329e14c2",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1840,
        576
      ],
      "parameters": {
        "width": 496,
        "height": 176,
        "content": "## 配置节点"
      },
      "typeVersion": 1
    },
    {
      "id": "45f50d44-40c7-4e04-9e7f-36ee2cc075d4",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1328,
        576
      ],
      "parameters": {
        "width": 480,
        "height": 176,
        "content": "## GitLab - [文档](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.gitlab/)"
      },
      "typeVersion": 1
    },
    {
      "id": "819a6463-8222-47e9-aca2-36e4f20e0489",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        576
      ],
      "parameters": {
        "width": 496,
        "height": 176,
        "content": "## n8n 内部 - [文档](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.n8n/)"
      },
      "typeVersion": 1
    },
    {
      "id": "ef82a762-7d0c-4928-a404-5a1f691aed71",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        576
      ],
      "parameters": {
        "width": 1440,
        "height": 176,
        "content": "## Slack - [文档](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.slack/)"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Configuration": {
      "main": [
        [
          {
            "node": "List All Files - GitLab",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Trigger": {
      "main": [
        [
          {
            "node": "Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List of Names": {
      "main": [
        [
          {
            "node": "Get All Workflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If File Exists": {
      "main": [
        [
          {
            "node": "Update File - GitLab",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create New File - GitLab",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "If File Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get All Workflows": {
      "main": [
        [
          {
            "node": "Discard Archived Workflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New File - Failed": {
      "main": [
        [
          {
            "node": "Process Each File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Each File": {
      "main": [
        [
          {
            "node": "Send Message to Channel",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Remove Unwanted Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update File - Failed": {
      "main": [
        [
          {
            "node": "Process Each File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update File - GitLab": {
      "main": [
        [
          {
            "node": "Process Each File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update File - Failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Unwanted Fields": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List All Files - GitLab": {
      "main": [
        [
          {
            "node": "List of Names",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create New File - GitLab": {
      "main": [
        [
          {
            "node": "Process Each File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "New File - Failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Discard Archived Workflows": {
      "main": [
        [
          {
            "node": "Process Each File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级

需要付费吗?

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

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

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

作者

AI Developer & Automation Consultant

外部链接
在 n8n.io 查看

分享此工作流