Hướng dẫn backup workflow N8N
Bài viết này sẽ hướng dẫn cách backup workflow N8N. Nếu bạn cần hỗ trợ, xin vui lòng liên hệ VinaHost qua Hotline 1900 6046 ext.3, email về support@vinahost.vn hoặc chat với VinaHost qua livechat https://livechat.vinahost.vn/chat.php.
Hướng dẫn cách backup workflow N8N trên Hosting N8N tại VINAHOST#
Bước 1: Ta đăng nhập vào N8N#
Bạn copy đoạn code dưới đây sau đó tạo workflow rồi paste vào nhé
{ "name": "BACKUP", "nodes": [ { "parameters": { "filters": {}, "requestOptions": {} }, "id": "65fc80cb-60b1-4532-8a4f-e5412bd24820", "name": "n8n", "type": "n8n-nodes-base.n8n", "position": [20, 340], "typeVersion": 1 }, { "parameters": { "options": {} }, "id": "3789df85-ac49-44db-a956-9d8111cbe0bf", "name": "Loop Over Items", "type": "n8n-nodes-base.splitInBatches", "position": [240, 340], "typeVersion": 3 }, { "parameters": { "rule": { "interval": [{ "triggerAtHour": 2 }] } }, "id": "0aee19dc-6a62-460d-8624-e7f96dfbcb3f", "name": "Schedule Trigger", "type": "n8n-nodes-base.scheduleTrigger", "position": [-580, 200], "typeVersion": 1.2 }, { "parameters": { "chatId": "6312104790", "text": " Starting Workflow Backup", "additionalFields": { "appendAttribution": false } }, "type": "n8n-nodes-base.telegram", "typeVersion": 1.2, "position": [-360, 340], "id": "ea58466e-7971-4641-ac9b-1990ba87b512", "name": "Telegram", "webhookId": "cccfe0a1-af40-4532-ac6a-634d1be2e415" }, { "parameters": { "chatId": "", "text": "=✅ Complete backup", "additionalFields": { "appendAttribution": false } }, "type": "n8n-nodes-base.telegram", "typeVersion": 1.2, "position": [680, 180], "id": "47794c25-8ec3-47c8-a098-528d2f03082b", "name": "Completed Notification", "webhookId": "cccfe0a1-af40-4532-ac6a-634d1be2e415" }, { "parameters": { "operation": "write", "fileName": "={{ $('Execute Command').item.json.stdout }}/{{$now.toFormat('yyyy-MM-dd').trim()}}-{{ $('n8n1').first().json.name.replace(/[\\s-]/g, '_') }}.json", "options": {} }, "type": "n8n-nodes-base.readWriteFile", "typeVersion": 1, "position": [920, 360], "id": "345519b4-c379-4582-ad8e-8305178f572b", "name": "Read/Write Files from Disk" }, { "parameters": { "operation": "toJson", "binaryPropertyName": "=data", "options": { "fileName": "={{ $json.name.replace(/[\\s-]/g, '_') }}" } }, "type": "n8n-nodes-base.convertToFile", "typeVersion": 1.1, "position": [720, 360], "id": "b7aa4973-b462-454b-8b42-1ca35949ce23", "name": "Convert to File" }, { "parameters": {}, "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [-580, 460], "id": "47542acc-af80-4ec4-8882-a5f956c066cc", "name": "When clicking ‘Test workflow’" }, { "parameters": { "command": "#!/bin/bash\nif [ ! -d \"backup_n8n\" ]; then\n mkdir backup_n8n\n cd backup_n8n\n pwd\nelse\n cd backup_n8n\n pwd\nfi\nexit\n\n" }, "type": "n8n-nodes-base.executeCommand", "typeVersion": 1, "position": [-160, 340], "id": "cb220888-0b99-4f03-9cf0-24cbc07a5452", "name": "Execute Command" }, { "parameters": { "operation": "get", "workflowId": { "__rl": true, "value": "={{ $json.id }}", "mode": "id" }, "requestOptions": {} }, "type": "n8n-nodes-base.n8n", "typeVersion": 1, "position": [480, 360], "id": "da61efd1-1018-404c-8bde-6278882790c6", "name": "n8n1" } ], "pinData": {}, "connections": { "n8n": { "main": {'node': 'Loop Over Items', 'type': 'main', 'index': 0} }, "Loop Over Items": { "main": [ [{ "node": "Completed Notification", "type": "main", "index": 0 }], [{ "node": "n8n1", "type": "main", "index": 0 }] ] }, "Schedule Trigger": { "main": {'node': 'Telegram', 'type': 'main', 'index': 0} }, "Telegram": { "main": {'node': 'Execute Command', 'type': 'main', 'index': 0} }, "Convert to File": { "main": [ [{ "node": "Read/Write Files from Disk", "type": "main", "index": 0 }] ] }, "Read/Write Files from Disk": { "main": {'node': 'Loop Over Items', 'type': 'main', 'index': 0} }, "When clicking ‘Test workflow’": { "main": {'node': 'Telegram', 'type': 'main', 'index': 0} }, "Execute Command": { "main": {'node': 'n8n', 'type': 'main', 'index': 0} }, "n8n1": { "main": {'node': 'Convert to File', 'type': 'main', 'index': 0} } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "9212d727-8f1c-4ea5-8964-7bc400cf2b5c", "meta": { "templateCredsSetupCompleted": true, "instanceId": "eeffd3494fc444b0b313dd453245891a13a830c0f46ba20431c562c7a18f6563" }, "id": "HD2hZNB7CYuXftGJ", "tags": [] }
Bước 2: Thiết lập xác thực kết nối các node#
-
Chọn node Telegram
Create new credential nếu bạn chưa biết các xác thực với telegram có thể xem hướng dẫn tại: https://kb.vinahost.vn/ket-noi-telegram-voi-n8n/
Telegram cần chatid bạn xem và tham khảo hướng dẫn này để lấy chatID của bot nhé: https://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id
-
Chọn Node N8N
-
Trước tiên ta tạo API của N8N để tiến hành kết nối vào setting chọn n8n API sao đó ấn Create a API Key
- Sau đó đặt nhãn cho API rồi tiến hành Save
- Bạn copy API nhé, nó chỉ hiển thị một lần duy nhất
- Bạn vào node N8N sau đó điền các thông tin sau: điền API Key, thay đổi URL thành https://your_domain/api/v1 sau đó Save lại
Bước 3: Ta kiểm tra backup#
-
Ấn Test flow để chạy, thông báo như phía dưới hiện Workflow đã hoạt động và backup rồi
-
Ta xem tin nhắn ở Telegram với 4 workflow sẽ có 4 tin nhắn backup hoàn tất
- File backup sẽ được lưu trong thư mục của N8N
Bước 4: Restore từ các bản backup#
- Bạn tải các bản backup về máy, sau đó dùng notepad để xóa dấu ngoặc [] nhé. Sau đó ấn Ctrl + s để lưu lại
- Ta tiến hành import như bình thường
Lưu ý#
- Các bản backup sẽ được ghi đè nếu bạn backup trong ngày. Nếu bạn muốn lưu từng bản backup trong ngày xin vui lòng tải các bản backup hiện tại về máy sau đó tiến hành backup
- Ngoài ra ở node Trigger Schedule bạn vui lòng tự cài đặt thời gian để workflow hoạt động nhé
THAM KHẢO CÁC DỊCH VỤ TẠI VINAHOST
>> SERVER – COLOCATION – CDN
>> CLOUD – VPS
>> HOSTING
>> WEBSITE
>> TÊN MIỀN