I did a bit of cleaning up, to make things a little easier to read. Can you spot something that is obviously wrong?
Here is the complete flow (except for the Dropbox node):
[
{
"id": "b9e243ba.d1081",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": ""
},
{
"id": "6273b7f8.ff81e",
"type": "comment",
"z": "b9e243ba.d1081",
"name": "Nightly Backups",
"info": "",
"x": 220,
"y": 100,
"wires": []
},
{
"id": "7d3acada.026084",
"type": "inject",
"z": "b9e243ba.d1081",
"name": "Start backup",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "00 03 * * *",
"once": false,
"x": 227,
"y": 150,
"wires": [
[
"aaa9bd2a.8cdbf8"
]
]
},
{
"id": "1e7979a0.4c4ad6",
"type": "function",
"z": "b9e243ba.d1081",
"name": "Triggered queue",
"func": "// if queue doesn't exist, create it\ncontext.queue = context.queue || [];\ncontext.busy = context.busy || false;\n\n// if the msg is a trigger one release next message\nif (msg.hasOwnProperty("trigger")) {\n if (context.queue.length > 0) {\n var m = context.queue.shift();\n return {payload:m};\n }\n else {\n context.busy = false;\n // node.send({payload:"result"});\n var msg2 = { payload:"OK" };\n }\n}\nelse {\n if (context.busy) {\n // if busy add to queue\n context.queue.push(msg.payload);\n }\n else {\n // otherwise we are empty so just pass through and set busy flag\n context.busy = true;\n return msg;\n }\n}\n\nreturn [null,msg2];",
"outputs": "2",
"noerr": 0,
"x": 400,
"y": 240,
"wires": [
[
"5f65c136.b3456"
],
[
"17c228d2.0f6de7"
]
]
},
{
"id": "3467a1aa.1b8016",
"type": "function",
"z": "b9e243ba.d1081",
"name": "set trigger",
"func": "// handle the return from the exec in here \n// if all is good then set msg.trigger property to exist\nmsg.trigger = 1;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 680,
"y": 200,
"wires": [
[
"1e7979a0.4c4ad6"
]
]
},
{
"id": "5f65c136.b3456",
"type": "exec",
"z": "b9e243ba.d1081",
"command": "",
"addpay": true,
"append": "",
"useSpawn": "false",
"timer": "",
"oldrc": false,
"name": "Execute commands",
"x": 750,
"y": 140,
"wires": [
[
"3467a1aa.1b8016"
],
[],
[
"17d51249.48eea6"
]
]
},
{
"id": "17c228d2.0f6de7",
"type": "function",
"z": "b9e243ba.d1081",
"name": "Read filenames",
"func": "var path = ('/home/pi/.temp_nodered');\nvar fs = (global.get('fse'));\n\nfs.readdirSync(path).forEach(file => {\n node.send({localFilename: "/home/pi/.temp_nodered/"+(file)});\n});\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 400,
"y": 340,
"wires": [
[]
]
},
{
"id": "aaa9bd2a.8cdbf8",
"type": "function",
"z": "b9e243ba.d1081",
"name": "Generate commands",
"func": "//--Edit these to your own installation\n//Don't change these!\nvar path = '/home/pi/.temp_nodered';\nvar tmp_path = '/tmp/mysql_backup';\n\n//Create directory structure\nvar m1={payload: "rm -rf "+[path]};\nvar m2={payload: "mkdir "+[path]};\nvar m3={payload: "mkdir "+[tmp_path]};\n\n// ************************************************************************* //\n// *** The below commands will archive the entire node-red user directory,\n// *** emoncms data directories & mysql. To add further commands, use the\n// *** same format, and add the corresponding msg id to the 'return' statement.\n// ************************************************************************* //\n//---NODE-RED---//\n //Create ~/.node-red archive\n var m4={payload: "/home/root/logfiler"};\n\n\n// Output the commands for execution\nreturn [ [ m1, m2, m3, m4, ] ];",
"outputs": "1",
"noerr": 0,
"x": 431,
"y": 150,
"wires": [
[
"1e7979a0.4c4ad6"
]
]
},
{
"id": "17d51249.48eea6",
"type": "function",
"z": "b9e243ba.d1081",
"name": "Report any errors",
"func": "var code = (msg.payload.code);\nif ([code] != "0") {\nmsg.payload = (msg.payload.message);\nmsg.topic = "Raspberry backup process failed";\nreturn msg;\n}\nelse {\nreturn null;\n}",
"outputs": 1,
"noerr": 0,
"x": 390,
"y": 480,
"wires": [
[]
]
},
{
"id": "c33bf6c3.2bc5e",
"type": "comment",
"z": "b9e243ba.d1081",
"name": "README (select & view in info panel!)",
"info": "REQUIREMENTS \nRequires the library fs-extra installing & enabling\nglobally in settngs.js \n(used in Read Filenames
function node)\n\nTO INSTALL FS-EXTRA \n\ncd ./node-red \nnpm install --save fs-extra\n
\nTO MAKE FS-EXTRA GLOBAL \nAdd fse:require('fs-extra')
to the\nfunctionGlobalContext
section in NR settings.js file.\n\nCONFIGURATION \nEdit the Generate commands
function node with \nyour own; \n- Emoncms data directory path\n- Emoncms MYSQL username (default = emoncms)\n- Emoncms MYSQL password \n\nSetup the dropbox
node, (details in the node info) \nAlso edit the Start backup
inject node with your preferred time to run. \nIf you want to be alerted about archive problems or failures, you can use the Report any errors
node output to dispatch the message via Pushover, email, twitter or whatever.",
"x": 476,
"y": 99,
"wires": []
}
]