Automatical backup for flows

This code is useful for backup the flow at every commit of node-red.

The script actually backup the following file:

  • /root/.node-red/flows_vps.json
  • /root/.node-red/flows_vps_cred.json

cloning in the same directory with a new name with timestamp.

In order to make it work modify the actual URL in file and function nodes checking your enviroment url and filenames.

[{"id":"4bc95209.1caa0c","type":"file in","z":"9261a245.29166","name":"flows_vps.json","filename":"/root/.node-red/flows_vps.json","format":"utf8","x":289,"y":86,"wires":[["5e94d86a.ae1428"]]},{"id":"5224e94d.0a1998","type":"file","z":"9261a245.29166","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"true","x":639,"y":86,"wires":[]},{"id":"a1bf209.b3cbde","type":"inject","z":"9261a245.29166","name":"","topic":"","payload":"restarted","payloadType":"str","repeat":"","crontab":"","once":true,"x":79,"y":86,"wires":[["4bc95209.1caa0c","1e014466.7207fc"]]},{"id":"5e94d86a.ae1428","type":"function","z":"9261a245.29166","name":"","func":"msg.filename = \"/root/.node-red/backup_\"+(new Date().toISOString().replace(':', '_').replace(':', '_').replace(/\\..+/, ''))+\"_flows_vps.json\";\nreturn msg;\n","outputs":1,"noerr":0,"x":519,"y":86,"wires":[["5224e94d.0a1998"]]},{"id":"1e014466.7207fc","type":"file in","z":"9261a245.29166","name":"flows_vps_cred.json","filename":"/root/.node-red/flows_vps_cred.json","format":"utf8","x":309,"y":146,"wires":[["e7750033.69c91"]]},{"id":"18da20c1.32438f","type":"file","z":"9261a245.29166","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"true","x":639,"y":146,"wires":[]},{"id":"e7750033.69c91","type":"function","z":"9261a245.29166","name":"","func":"msg.filename = \"/root/.node-red/backup_\"+(new Date().toISOString().replace(':', '_').replace(':', '_').replace(/\\..+/, ''))+\"_flows_vps_cred.json\";\nreturn msg;\n","outputs":1,"noerr":0,"x":519,"y":146,"wires":[["18da20c1.32438f"]]}]
valerio-vaccaro

Flow Info

created 1 year, 2 months ago

Node Types

Core
  • file (x2)
  • file in (x2)
  • function (x2)
  • inject (x1)

Tags

  • backup
  • file
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option