自动清理超过2周的Cloudflare R2文件(含Telegram通知)
中级
这是一个DevOps领域的自动化工作流,包含 10 个节点。主要使用 S3, Code, Telegram, ScheduleTrigger 等节点。 自动清理超过2周的Cloudflare R2文件(含Telegram通知)
前置要求
- •Telegram Bot Token
使用的节点 (10)
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "651cb210bfbe30e7e5b06f0378c3cb8d15e18849a4b48e0d63ab0d98c4f6e232",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "1d6e7f05-a102-47aa-adf7-a5c99fd6de24",
"name": "S3",
"type": "n8n-nodes-base.s3",
"position": [
-140,
-80
],
"parameters": {
"options": {
"folderKey": "Folder/",
"fetchOwner": false
},
"operation": "getAll",
"returnAll": true,
"bucketName": "bucketName"
},
"credentials": {
"s3": {
"id": "KvkwePsDzvVha9Gs",
"name": "Cloudflare S3 account"
}
},
"notesInFlow": false,
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "bbc59eb2-b927-48ae-9b05-9dde8f8bb076",
"name": "代码",
"type": "n8n-nodes-base.code",
"position": [
140,
-80
],
"parameters": {
"jsCode": "const TWO_WEEKS = 14 * 24 * 60 * 60 * 1000;\nconst now = Date.now();\nconst today = new Date().toISOString().split(\"T\")[0]; // YYYY-MM-DD\n\nconst items = $items(\"S3\", 0); // ดึงไฟล์ทั้งหมดจาก AWS S3 Node\n\nreturn items.filter(item => {\n const lastModified = new Date(item.json.LastModified).getTime();\n const age = now - lastModified;\n return age > TWO_WEEKS;\n // const fileDate = new Date(item.json.LastModified).toISOString().split(\"T\")[0];\n // return fileDate === today;\n});\n\n"
},
"typeVersion": 2
},
{
"id": "0612b8b7-23e1-4ccc-8563-3e2396f67c6d",
"name": "S31",
"type": "n8n-nodes-base.s3",
"position": [
420,
-80
],
"parameters": {
"fileKey": "={{ $json.Key }}",
"options": {},
"operation": "delete",
"bucketName": "bucketName"
},
"credentials": {
"s3": {
"id": "KvkwePsDzvVha9Gs",
"name": "Cloudflare S3 account"
}
},
"executeOnce": false,
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "0864095d-e7eb-47d3-9b21-2103b6f64a01",
"name": "Telegram",
"type": "n8n-nodes-base.telegram",
"position": [
680,
-80
],
"webhookId": "1062fade-271c-4f43-a88b-ae6b18bb0153",
"parameters": {
"text": "=✅ Remove R2 backup complete \n👌*{{ $('Code').item.json.Key }}*",
"chatId": "TELEGRAM_CHAT_ID",
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "LZCmAP9hvCTi7vQo",
"name": "Telegram account name"
}
},
"executeOnce": false,
"typeVersion": 1.2
},
{
"id": "808e756e-7a74-4b03-86ac-c915578a7c04",
"name": "定时触发器",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-400,
-80
],
"parameters": {
"rule": {
"interval": [
{
"triggerAtHour": 9
}
]
}
},
"typeVersion": 1.2
},
{
"id": "86406c94-fa65-446c-aad9-47cd6073e61d",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-460,
-240
],
"parameters": {
"height": 340,
"content": "## 调度"
},
"typeVersion": 1
},
{
"id": "a8fc923d-623b-4d68-8896-d97411d8be10",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-200,
-240
],
"parameters": {
"color": 5,
"width": 220,
"height": 340,
"content": "## R2对象(S3)"
},
"typeVersion": 1
},
{
"id": "3db54850-3f7c-4638-ae04-4110efeb69d0",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
60,
-240
],
"parameters": {
"color": 6,
"width": 260,
"height": 340,
"content": "## 过滤文件"
},
"typeVersion": 1
},
{
"id": "8814b537-f0e0-4e18-a1b3-9a43beae7f72",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
340,
-240
],
"parameters": {
"color": 5,
"height": 340,
"content": "## 删除文件"
},
"typeVersion": 1
},
{
"id": "1442dabd-cfb8-4c79-8ff3-c53d6f06009f",
"name": "便签说明4",
"type": "n8n-nodes-base.stickyNote",
"position": [
620,
-240
],
"parameters": {
"color": 5,
"height": 340,
"content": "## Telegram通知"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"S3": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"S31": {
"main": [
[
{
"node": "Telegram",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "S31",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "S3",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 开发运维
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
UniFi控制器:检查并在新发布时升级
通过SSH和Telegram通知自动化UniFi控制器更新
If
Ssh
Code
+5
11 节点Dominic Spatz
开发运维
高级 n8n 工作流与 GitHub 同步
使用 GitHub 的智能变更检测自动化工作流备份
If
N8n
Set
+10
38 节点Maksym Brashenko
开发运维
n8n备份管家v3
工作流自动备份至GitHub,支持邮件/Telegram通知
If
Code
Gmail
+6
21 节点Builds.Cool
开发运维
Lighthouse报告
使用Lighthouse、Gemini AI、Telegram警报和Google Sheets监控核心网页指标
If
Code
Telegram
+6
13 节点Rully Saputra
开发运维
n8n网站停机监控
多网站监控系统,支持电话通知
If
Code
Gmail
+7
20 节点InfyOm Technologies
开发运维
我的工作流程2
基于ScrapeGraphAI和Telegram的智能物联网设备健康监控
If
Code
Telegram
+3
13 节点vinci-king-01
开发运维