Node-Red Flow Samples/Sharing

Title - Backup Node Red

Summary
This flow is one I found, I'm not sure where though so unable to credit the person who created it. But thought it useful after I trashed my Node Red recently, due to an oversight on my part (oops).

This requires a piece of software installing on your PI called Resilio.
Instructions can be found here. You can also install on Windows too on their main website here.

To configure, browse to you PI IP and port 8888, you can then set up the pairing, and share the key to yourself, for another machine to access your backups.

The flow

You can modify the paths accordingly in the nodes "backup .node-red" and "delete older than 7 days" (and the number of days to keep). I added Pushover and receive a nice message when complete. Which I use as a reminder to copy the backup back.

The Flow

[{"id":"cad1c731.992228","type":"tab","label":"Pi-Backup","disabled":false,"info":"Rotating backup of .node-red folder"},{"id":"9f50db03.848e48","type":"exec","z":"cad1c731.992228","command":"sudo zip -rq /home/royski/sync/Backups/node-red-pi4-backup-$(date +%Y-%m-%d).zip /home/royski/.node-red","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"backup .node-red","x":410,"y":40,"wires":[["ef8d10db.d8e83"],["ef8d10db.d8e83"],["1bd3ae23.6e9f22"]]},{"id":"a7b79704.1505c8","type":"inject","z":"cad1c731.992228","name":"daily @2200","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 22 * * ","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":40,"wires":[["9f50db03.848e48"]]},{"id":"ad21052b.df89d8","type":"debug","z":"cad1c731.992228","name":"backup-log","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":120,"wires":[]},{"id":"1bd3ae23.6e9f22","type":"switch","z":"cad1c731.992228","name":"check op success","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":230,"y":180,"wires":[["b329b40c.035f38"],["45de1bdb.02cd24"]]},{"id":"b329b40c.035f38","type":"exec","z":"cad1c731.992228","command":"sudo find /home/royski/sync/Backups/.zip -mtime +7 -type f -delete","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"delete older than 7 days","x":470,"y":140,"wires":[["ef8d10db.d8e83"],["ef8d10db.d8e83"],["954f68c7.dc2988"]]},{"id":"45de1bdb.02cd24","type":"change","z":"cad1c731.992228","name":"custom error msg","rules":[{"t":"set","p":"payload","pt":"msg","to":":red_circle: There was an error in Pi4 backup flow. Check logs.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":260,"wires":[["ad21052b.df89d8","a45d5a55.614c48"]]},{"id":"954f68c7.dc2988","type":"switch","z":"cad1c731.992228","name":"check op success","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":200,"wires":[["17260390.570bec"],["45de1bdb.02cd24"]]},{"id":"17260390.570bec","type":"template","z":"cad1c731.992228","name":"success msg","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":":white_check_mark: RPi4 Backup compelete.","output":"str","x":750,"y":120,"wires":[["ad21052b.df89d8","a45d5a55.614c48"]]},{"id":"ef8d10db.d8e83","type":"switch","z":"cad1c731.992228","name":"filter null","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":660,"y":40,"wires":[["ad21052b.df89d8"],[]]},{"id":"a45d5a55.614c48","type":"pushover api","z":"cad1c731.992228","keys":"54ad51a1.76db6","title":"","name":"","x":960,"y":260,"wires":[]},{"id":"54ad51a1.76db6","type":"pushover-keys","z":"","name":"Pushover"}]

The backup is scheduled, but can be changed in the first node, and executes here at 22:00 every day.

4 Likes