Hi Jbudd,
after a morning of going backwards and forwards with chat gpt I have a flow that works when I click on Backup now, and it does actually backup and send me a success email, chat gpt's version sent 1 success email and 4 emails saying that it wasn't successful, but I am not sure how to test it if it truly is unsuccessful, could you tell from looking at the flow ?
[
{
"id": "b69d691090d14131",
"type": "function",
"z": "d5abf393d3c8d4ce",
"name": "Start Backup",
"func": "return msg;",
"outputs": 1,
"x": 390,
"y": 540,
"wires": [
[
"def8a7864c6b3f12"
]
]
},
{
"id": "def8a7864c6b3f12",
"type": "exec",
"z": "d5abf393d3c8d4ce",
"command": "mount | grep -q /mnt/usb_backup",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"name": "Check USB Mounted",
"x": 650,
"y": 540,
"wires": [
[
"87247002d94b14b8"
],
[],
[]
]
},
{
"id": "87247002d94b14b8",
"type": "exec",
"z": "d5abf393d3c8d4ce",
"command": "touch /mnt/usb_backup/.nr_test && rm /mnt/usb_backup/.nr_test",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"name": "Check USB Writable",
"x": 930,
"y": 540,
"wires": [
[
"be6b4f11a33ac7ce"
],
[],
[]
]
},
{
"id": "be6b4f11a33ac7ce",
"type": "function",
"z": "d5abf393d3c8d4ce",
"name": "Build Backup Command",
"func": "const date = new Date().toISOString().slice(0,10);\nmsg.payload = `mkdir -p /mnt/usb_backup/node-red-backups && tar -czf /mnt/usb_backup/node-red-backups/node-red-${date}.tar.gz --exclude=node_modules -C /home/pi/.node-red .`;\nreturn msg;",
"outputs": 1,
"x": 1210,
"y": 540,
"wires": [
[
"e2bcdee2f6db52af"
]
]
},
{
"id": "e2bcdee2f6db52af",
"type": "exec",
"z": "d5abf393d3c8d4ce",
"command": "",
"addpay": true,
"useSpawn": false,
"name": "Create Backup",
"x": 1450,
"y": 540,
"wires": [
[
"5ac99bb92372b7e3"
],
[],
[]
]
},
{
"id": "5ac99bb92372b7e3",
"type": "exec",
"z": "d5abf393d3c8d4ce",
"command": "find /mnt/usb_backup/node-red-backups -name 'node-red-*.tar.gz' -mtime +28 -delete",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"name": "Cleanup Old Backups",
"x": 1710,
"y": 540,
"wires": [
[
"a23e5b1b0bd8f77c"
],
[
"c9dbe409740e626f"
],
[]
]
},
{
"id": "a23e5b1b0bd8f77c",
"type": "function",
"z": "d5abf393d3c8d4ce",
"name": "Build Success Email",
"func": "const now = new Date().toLocaleString();\nmsg.topic = \"System update\";\nmsg.payload = `Hello,\\n\\nYour scheduled Node Red backup completed successfully.\\n\\nDate: ${now}\\n\\nKind regards Savio Sensors`;\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2000,
"y": 520,
"wires": [
[]
]
},
{
"id": "c9dbe409740e626f",
"type": "function",
"z": "d5abf393d3c8d4ce",
"name": "Build Error Email",
"func": "// Ignore empty or harmless stderr messages\nif (!msg.payload || msg.payload.toString().trim() === \"\") {\n return null;\n}\n\nmsg.topic = \"System notification\";\nmsg.payload = `Node-RED backup FAILED.\\n\\nError details:\\n${msg.payload}`;\nreturn msg;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2010,
"y": 820,
"wires": [
[]
]
},
{
"id": "84cd95aaa671dcae",
"type": "inject",
"z": "d5abf393d3c8d4ce",
"name": "â–¶ Backup Now",
"props": [
{
"p": "payload",
"v": "manual",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"x": 150,
"y": 470,
"wires": [
[
"b69d691090d14131"
]
]
},
{
"id": "5e1441ae0a972d88",
"type": "inject",
"z": "d5abf393d3c8d4ce",
"name": "⏰ Weekly Backup",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "weekly",
"payloadType": "str",
"x": 180,
"y": 570,
"wires": [
[
"b69d691090d14131"
]
]
}
]
Thanks