A lot of this is borrowed from @Royski posts on ‘that other site’. I made some modifications and will post my version of it below.
First THANK YOU!! @Royski this just saved my week! I recently got a message in NR saying that changes were made outside the page I was on. It said there were no conflicts so just merge them. When the page reloaded ALL my Flows were gone. All I had was a single blank Flow.
After I picked my chin up off my desk I remembered my backups. With-in 10 minutes I had everything thing back.
If you do not have a backup routine for NR do it now!
Title - Backup Node Red
Summary
Pretty straight froward this creates a backup zip of your .node-red directory, and retains a given number of them. I use a minimac, so these commands are geared toward that deployment. You can edit the backup .node-red, and deleted older than, nodes according to your setup.
My plans is to have these zip files then stored on another machine, but I’m still working those commends out.
Sequence
[{"id":"55b429b6.23dd98","type":"exec","z":"102546f5.2a0b69","command":"zip -rq /Users/minimac/Backups/node-red-backup-$(date +%Y-%m-%d).zip /Users/minimac/.node-red","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"backup .node-red","x":410,"y":880,"wires":[[],[],["d64a5bd4.0cd4c8"]]},{"id":"83228b65.b859a8","type":"inject","z":"102546f5.2a0b69","name":"daily @2200","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 22 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":880,"wires":[["55b429b6.23dd98"]]},{"id":"bc9940d4.62799","type":"debug","z":"102546f5.2a0b69","name":"backup-log","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1250,"y":960,"wires":[]},{"id":"d64a5bd4.0cd4c8","type":"switch","z":"102546f5.2a0b69","name":"check success","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":600,"y":900,"wires":[["fada7520.17dc78"],["bc9940d4.62799","2b64fef9.8cd882"]]},{"id":"fada7520.17dc78","type":"exec","z":"102546f5.2a0b69","command":"find /Users/minimac/Backups *.zip -ctime +7 -print0 | /usr/bin/xargs -0 rm","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"delete older than 7 days","x":710,"y":840,"wires":[[],[],["e2a2439c.8253f"]]},{"id":"e2a2439c.8253f","type":"switch","z":"102546f5.2a0b69","name":"check success","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":900,"y":900,"wires":[["54c47c9a.23c7c4"],["bc9940d4.62799","2b64fef9.8cd882"]]},{"id":"54c47c9a.23c7c4","type":"template","z":"102546f5.2a0b69","name":"success msg","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":" NR Backup compelete.","output":"str","x":1070,"y":860,"wires":[["bc9940d4.62799","ad48a65f.464328"]]},{"id":"91d29e4f.d8223","type":"comment","z":"102546f5.2a0b69","name":"Daily Backups","info":"__","x":150,"y":820,"wires":[]},{"id":"fe6d17d1.659898","type":"switch","z":"102546f5.2a0b69","name":"check success","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1160,"y":720,"wires":[[],[]]},{"id":"a955dc5c.617ca","type":"link out","z":"102546f5.2a0b69","name":"NR BAckup Failed Request Input","links":["f045d7ed.ebeea8"],"x":1075,"y":1000,"wires":[]},{"id":"2b64fef9.8cd882","type":"change","z":"102546f5.2a0b69","name":"NR Backup Failed","rules":[{"t":"set","p":"payload","pt":"msg","to":"NR Backup Failed","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":950,"y":1000,"wires":[["a955dc5c.617ca"]]},{"id":"ad48a65f.464328","type":"link out","z":"102546f5.2a0b69","name":"Backup Success","links":["f045d7ed.ebeea8"],"x":1215,"y":840,"wires":[]},{"id":"d92e72be.2ba3d","type":"exec","z":"102546f5.2a0b69","command":"cp -rf /Users/minimac/.node-red /Volumes\"/Personal/~HE Stuff/node-red/Backups/\"","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"copy file to NAS","x":980,"y":780,"wires":[[],[],["fe6d17d1.659898"]]}]
The backup is scheduled, but can be changed in the first node, and executes here at 22:00 every day.