# Backup and restore Node-red

**URL:** <https://discourse.nodered.org/t/backup-and-restore-node-red/86856>\
**Category:** General\
**Created:** [30 March 2024 00:00 UTC](https://discourse.nodered.org/t/backup-and-restore-node-red/86856 "2024-03-30T00:00:54Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [2 April 2024 22:49 UTC](https://discourse.nodered.org/t/backup-and-restore-node-red/86856/14 "2024-04-02T22:49:54Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1f15cf6aa3a258dddffb0398e37cab6519c52d78.png)

```auto
[{"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

```auto
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 run

```auto
tar -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

```auto
sudo tar -xf nodered.tar.gz

```

---

_[View the full topic](https://discourse.nodered.org/t/backup-and-restore-node-red/86856)._
