My flow to make a compressed backup of Node-red on Linux.
If you only inject a payload, it will backup ~/.node-red to ~/nodered.tar.gz but you can override these with msg.nodereddirectory and msg.backupfilename.
Everything in the directory except for node_modules* will be included in the archive
[{"id":"7f20ad1a9174e987","type":"tab","label":"Backup Node-red","disabled":false,"info":"","env":[]},{"id":"f854b7672172886b","type":"inject","z":"7f20ad1a9174e987","name":"Node-red location & backup file name","props":[{"p":"payload"},{"p":"nodereddirectory","v":".node-red","vt":"str"},{"p":"backupfilename","v":"$moment().format(\"YYYYMMDD.HHmm\") & \"nr.tar.gz\"","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"go","payloadType":"str","x":190,"y":80,"wires":[["40ec46521782eb90"]]},{"id":"40ec46521782eb90","type":"template","z":"7f20ad1a9174e987","name":"Backup script","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"# To override defaults pass these as msg properties\nNODEREDDIR={{{nodereddirectory}}}\nBACKUPTO={{{backupfilename}}}\n\n# Default location\nif [ -z $NODEREDDIR ]\nthen\nNODEREDDIR=.node-red\nfi\n\n# Default backup file\nif [ -z $BACKUPTO ]\nthen\n BACKUPTO=nodered.tar.gz\nfi\n\n# Don't overwrite backupfile\n#if [ -s \"$BACKUPTO\" ]\n#then\n# echo \"Error: $BACKUPTO already exists\" >&2\n# exit 1\n#fi\n\necho \"$BACKUPTO: $(tar -cvzf $BACKUPTO --exclude=\"node_modules*\" $NODEREDDIR | wc -l) files\"","output":"str","x":260,"y":140,"wires":[["cf19faaabdfb2dbe"]]},{"id":"cf19faaabdfb2dbe","type":"exec","z":"7f20ad1a9174e987","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":430,"y":140,"wires":[["fb47ca1393ddc5aa"],["3c4d7bf52fe7f7f6"],[]]},{"id":"fb47ca1393ddc5aa","type":"debug","z":"7f20ad1a9174e987","name":"Count files saved","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":610,"y":100,"wires":[]},{"id":"3c4d7bf52fe7f7f6","type":"debug","z":"7f20ad1a9174e987","name":"Errors","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":570,"y":160,"wires":[]}]
Listing backup contents
tar -tvf nodered.tar.gz
Restoring from the backup
If you backed up the default .node-red directory to the default file, the backup will have relative pathnames eg .node-red/settings.js To restore, put the backup file in the home directory ~ and runtar -xf nodered.tar.gz
cd .node-red
npm install
Note that if your settings file is owned by root for security, you need to run
sudo tar -xf nodered.tar.gz
