# node-RED Backup Flow

**URL:** <https://discourse.nodered.org/t/node-red-backup-flow/25033>\
**Category:** Share Your Projects\
**Created:** [17 April 2020 20:52 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033 "2020-04-17T20:52:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [17 April 2020 20:52 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/1 "2020-04-17T20:52:55Z")

</div>

I read a [post a few days ago](https://discourse.nodered.org/t/ive-lost-everything-connection-lost-to-machine-error-subflow-connections/24782) by @Trying_to_learn about losing his node-RED flow, which had taken him no doubt many hours to construct, and as his backup was on the same machine - he lost that too.  
So... I've spent a few days looking at off-site storage, and stumbled upon `node-red-contrib-dsm` which was written by @cflurin complete with an example flow to perform automated backups to dropbox.

![dsm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/b/2b5d7bf836c7cee3bee5b11afbc9cc62c5567bed.gif)

I played about with the configuration, and made some changes to the way that the backups are stored, basically to stop dropbox from filling up, yet conduct a nightly backup and be able to retrieve any one of those backups for 30 days (30 backups). The older ones are automatically weeded by dropbox, so it's 'fit & forget'.  
Instead of the backups being named as a timestamp, they are named as the day of the week - `Monday_nodered.zip`, `Tuesday_nodered.zip` etc.  
Looking at the dropbox web dashboard, you will only see 7 files (the current 7 days), but if you go to 'Version History', you can see & download the previous versions of that day, so for example every Monday's backup for the past 30 days.

 ![dbox](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e2378822ebfbbe9807f05076ec89439b483877cf.gif)

Anyway, here's the flow, it uses `node-red-contrib-dsm`, `node-red-node-dropbox` and a couple of inject nodes.  
Also you need to ensure that `zip` is installed, try `zip --help` and if help isn't displayed, then install it as `sudo apt-get install zip unzip`.  
The flow should work out of the box, once you've configured the dropbox node (leave the Filename & Local Filename boxes empty).  
_PS The inject node is set to run the flow 3.15am every night._

**NOTE:** See edit 17/4/21 below for +v1.3.0 version

```auto
[{"id":"7868f6a6.feb728","type":"dropbox out","z":"4487e413.bb781c","dropbox":"","filename":"","localFilename":"","name":"","x":430,"y":780,"wires":[]},{"id":"72f00992.3036f8","type":"inject","z":"4487e413.bb781c","name":"backup","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"start","vt":"string"}],"repeat":"","crontab":"15 03 * * *","once":false,"onceDelay":0.1,"topic":"start","payload":"","payloadType":"date","x":132,"y":760,"wires":[["b0bc8692.a8e948"]]},{"id":"8b602104.6656a","type":"inject","z":"4487e413.bb781c","name":"reset","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reset","payload":"","payloadType":"date","x":140,"y":800,"wires":[["b0bc8692.a8e948"]]},{"id":"b0bc8692.a8e948","type":"dsm","z":"4487e413.bb781c","name":"backup","sm_config":"{\n \"currentState\": \"step1\",\n \"states\": {\n \"step1\": {\n \"start\": \"step2\",\n \"reset\": \"step1\"\n },\n \"step2\": {\n \"zip\": \"step3\",\n \"reset\": \"step1\"\n },\n \"step3\": {\n \"upload\": \"step1\",\n \"reset\": \"step1\"\n }\n },\n \"data\": {\n },\n \"methods\": {\n \"init\": [\n \"sm.udir = RED.settings.userDir + '/';\",\n \"sm.exec = require('child_process').exec;\",\n \"sm.hostname = require('os').hostname();\",\n \"sm.unlink = require('fs').unlink;\"\n],\n \"start\": [\n \"/* delete old zip file */\",\n \"var zipfile = sm.udir+'node-red.zip';\",\n \n \"sm.fill = 'grey';\",\n \"sm.text = 'deleting';\",\n \"output = false;\",\n\n \"sm.unlink(zipfile, function (err) {\",\n \" if (err) {\",\n \" node.warn('no file '+zipfile);\",\n \" }\",\n \" resume('zip', msg);\",\n \"});\"\n],\n \"zip\": [\n \"var pre = ' ' + sm.udir;\",\n \"var cmd = 'zip -r';\",\n \"cmd += pre + 'node-red.zip';\",\n \"cmd += pre + 'flows*.json';\",\n \"cmd += pre + '.config*.json';\",\n \"cmd += pre + 'settings.js';\",\n \"cmd += pre + 'package.json';\",\n \"cmd += pre + 'package-lock.json';\",\n \"cmd += pre + 'lib/*';\",\n\n \"sm.fill = 'grey';\",\n \"sm.text = 'zipping';\",\n \"output = false;\",\n \n \"sm.exec(cmd, function(error, stdout, stderr) {\",\n \" if (error) {\",\n \" node.warn(error);\",\n \" } else {\",\n \" resume('upload', msg);\",\n \" }\",\n \"});\"\n],\n \"upload\": [\n \"sm.ts = new Date();\",\n \"sm.days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];\",\n \"sm.day = sm.days[sm.ts.getDay()];\",\n \"msg.filename = sm.day + '_nodered.zip';\",\n \"msg.localFilename = sm.udir+'node-red.zip';\",\n \"sm.fill = 'green';\",\n \"sm.text = sm.day;\"\n ],\n \"reset\": [\n \"sm.fill = 'grey';\",\n \"sm.text = 'reset';\",\n \"output = false;\"\n],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.fill\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.text\"\n }\n }\n }\n}","x":285,"y":780,"wires":[["7868f6a6.feb728"]]}]

```

**EDIT 20/10/2020** - Flow amended to ensure that all of the config files are backed up following the changes to node-RED in v1.2.0

**EDIT 17/4/2021** - Flow updated below to include the additional `package.json` contained within the `externalModules` folder, which **was introduced in v1.3.0**

```auto
[{"id":"7868f6a6.feb728","type":"dropbox out","z":"b3b413d1.05b1b","dropbox":"","filename":"","localFilename":"","name":"","x":470,"y":1605,"wires":[]},{"id":"72f00992.3036f8","type":"inject","z":"b3b413d1.05b1b","name":"backup","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"start","vt":"string"}],"repeat":"","crontab":"15 03 * * *","once":false,"onceDelay":0.1,"topic":"start","payload":"","payloadType":"date","x":172,"y":1585,"wires":[["b0bc8692.a8e948"]]},{"id":"8b602104.6656a","type":"inject","z":"b3b413d1.05b1b","name":"reset","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reset","payload":"","payloadType":"date","x":180,"y":1625,"wires":[["b0bc8692.a8e948"]]},{"id":"b0bc8692.a8e948","type":"dsm","z":"b3b413d1.05b1b","name":"backup","sm_config":"{\n \"currentState\": \"step1\",\n \"states\": {\n \"step1\": {\n \"start\": \"step2\",\n \"reset\": \"step1\"\n },\n \"step2\": {\n \"zip\": \"step3\",\n \"reset\": \"step1\"\n },\n \"step3\": {\n \"upload\": \"step1\",\n \"reset\": \"step1\"\n }\n },\n \"data\": {\n },\n \"methods\": {\n \"init\": [\n \"sm.udir = RED.settings.userDir + '/';\",\n \"sm.exec = require('child_process').exec;\",\n \"sm.hostname = require('os').hostname();\",\n \"sm.unlink = require('fs').unlink;\"\n],\n \"start\": [\n \"/* delete old zip file */\",\n \"var zipfile = sm.udir+'node-red.zip';\",\n \n \"sm.fill = 'grey';\",\n \"sm.text = 'deleting';\",\n \"output = false;\",\n\n \"sm.unlink(zipfile, function (err) {\",\n \" if (err) {\",\n \" node.warn('no file '+zipfile);\",\n \" }\",\n \" resume('zip', msg);\",\n \"});\"\n],\n \"zip\": [\n \"var pre = ' ' + sm.udir;\",\n \"var cmd = 'zip -r';\",\n \"cmd += pre + 'node-red.zip';\",\n \"cmd += pre + 'flows*.json';\",\n \"cmd += pre + '.config*.json';\",\n \"cmd += pre + 'settings.js';\",\n \"cmd += pre + 'package.json';\",\n \"cmd += pre + 'package-lock.json';\",\n \"cmd += pre + 'externalModules/package.json';\",\n \"cmd += pre + 'externalModules/package-lock.json';\",\n \"cmd += pre + 'lib/*';\",\n\n \"sm.fill = 'grey';\",\n \"sm.text = 'zipping';\",\n \"output = false;\",\n \n \"sm.exec(cmd, function(error, stdout, stderr) {\",\n \" if (error) {\",\n \" node.warn(error);\",\n \" } else {\",\n \" resume('upload', msg);\",\n \" }\",\n \"});\"\n],\n \"upload\": [\n \"sm.ts = new Date();\",\n \"sm.days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];\",\n \"sm.day = sm.days[sm.ts.getDay()];\",\n \"msg.filename = sm.day + '_nodered.zip';\",\n \"msg.localFilename = sm.udir+'node-red.zip';\",\n \"sm.fill = 'green';\",\n \"sm.text = sm.day;\"\n ],\n \"reset\": [\n \"sm.fill = 'grey';\",\n \"sm.text = 'reset';\",\n \"output = false;\"\n],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.fill\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.text\"\n }\n }\n }\n}","x":325,"y":1605,"wires":[["7868f6a6.feb728"]]}]

```

**EDIT 21/7/2021** - Flow updated below to accommodate changes made in node-RED v2.0.  
The `externalModules` is now depreciated, and the file `.config.modules.json` has been added to the backup set.

```auto
[{"id":"7868f6a6.feb728","type":"dropbox out","z":"b3b413d1.05b1b","dropbox":"","filename":"","localFilename":"","name":"","x":440,"y":1380,"wires":[]},{"id":"72f00992.3036f8","type":"inject","z":"b3b413d1.05b1b","name":"backup","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"15 03 * * *","once":false,"onceDelay":0.1,"topic":"start","payloadType":"date","x":137,"y":1360,"wires":[["b0bc8692.a8e948"]]},{"id":"8b602104.6656a","type":"inject","z":"b3b413d1.05b1b","name":"reset","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reset","payload":"","payloadType":"date","x":145,"y":1400,"wires":[["b0bc8692.a8e948"]]},{"id":"b0bc8692.a8e948","type":"dsm","z":"b3b413d1.05b1b","name":"backup","sm_config":"{\n \"currentState\": \"step1\",\n \"states\": {\n \"step1\": {\n \"start\": \"step2\",\n \"reset\": \"step1\"\n },\n \"step2\": {\n \"zip\": \"step3\",\n \"reset\": \"step1\"\n },\n \"step3\": {\n \"upload\": \"step1\",\n \"reset\": \"step1\"\n }\n },\n \"data\": {\n },\n \"methods\": {\n \"init\": [\n \"sm.udir = RED.settings.userDir + '/';\",\n \"sm.exec = require('child_process').exec;\",\n \"sm.hostname = require('os').hostname();\",\n \"sm.unlink = require('fs').unlink;\"\n],\n \"start\": [\n \"/* delete old zip file */\",\n \"var zipfile = sm.udir+'node-red.zip';\",\n \n \"sm.fill = 'grey';\",\n \"sm.text = 'deleting';\",\n \"output = false;\",\n\n \"sm.unlink(zipfile, function (err) {\",\n \" if (err) {\",\n \" node.warn('no file '+zipfile);\",\n \" }\",\n \" resume('zip', msg);\",\n \"});\"\n],\n \"zip\": [\n \"var pre = ' ' + sm.udir;\",\n \"var cmd = 'zip -r';\",\n \"cmd += pre + 'node-red.zip';\",\n \"cmd += pre + 'flows*.json';\",\n \"cmd += pre + '.config*.json';\",\n \"cmd += pre + 'settings.js';\",\n \"cmd += pre + 'package.json';\",\n \"cmd += pre + 'package-lock.json';\",\n \"cmd += pre + '.config.modules.json';\",\n \"cmd += pre + 'lib/*';\",\n\n \"sm.fill = 'grey';\",\n \"sm.text = 'zipping';\",\n \"output = false;\",\n \n \"sm.exec(cmd, function(error, stdout, stderr) {\",\n \" if (error) {\",\n \" node.warn(error);\",\n \" } else {\",\n \" resume('upload', msg);\",\n \" }\",\n \"});\"\n],\n \"upload\": [\n \"sm.ts = new Date();\",\n \"sm.days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];\",\n \"sm.day = sm.days[sm.ts.getDay()];\",\n \"msg.filename = sm.day + '_nodered.zip';\",\n \"msg.localFilename = sm.udir+'node-red.zip';\",\n \"sm.fill = 'green';\",\n \"sm.text = sm.day;\"\n ],\n \"reset\": [\n \"sm.fill = 'grey';\",\n \"sm.text = 'reset';\",\n \"output = false;\"\n],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.fill\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.text\"\n }\n }\n }\n}","x":290,"y":1380,"wires":[["7868f6a6.feb728"]]}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 April 2020 22:12 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/2 "2020-04-17T22:12:34Z")

</div>

@Paul-Reed Nice, but I have a suggestion, why not run the flow every hour or half hour and compare it to the previous version. If they are different, save the new one then while developing you would have multiple backups to fall back to if you mess something up (not like I've ever done that...more than a few dozen or more times 🤣)

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [17 April 2020 23:25 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/3 "2020-04-17T23:25:13Z")

</div>

As the DSM saves the zip file in the /node-red user directory, you would probably need to regularly check the size of the zip file, and if it's changed, then upload that file to dropbox.  
However, I like this because of its simplicity, and maybe if it starts to get too complicated, some users may be deterred from using it.

Users could always trigger a backup at anytime, just by clicking the inject node.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [18 April 2020 10:34 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/4 "2020-04-18T10:34:13Z")

</div>

> [@Paul-Reed](#):
>
> However, I like this because of its simplicity, and maybe if it starts to get too complicated, some users may be deterred from using it.

I'm using the version from the dsm-wiki for months on 3 Rpis. Two of them are running without any changes for weeks, so I only manually backup node-red by changes.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [16 June 2020 20:53 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/5 "2020-06-16T20:53:02Z")

</div>

This topic was automatically closed after 60 days. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 July 2020 13:44 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/6 "2020-07-06T13:44:27Z")

</div>



---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 July 2020 13:47 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/7 "2020-07-06T13:47:59Z")

</div>

Just came here following the backup dicussion in another thread and decided to try it out on my win10 machine

It didn't work because win10 has no command line tool called zip

But it does have one called tar so I just did a simple mode of the dsm node and it works fine 🙂  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/0764fa3ef61bd80843e8e25619346e48f7b2a8ba.png)

here is the win10 alternative dsm node only

```auto
[{"id":"20a4ec54.6c6454","type":"dsm","z":"fa1b22c7.a8823","name":"backup","sm_config":"{\n \"currentState\": \"step1\",\n \"states\": {\n \"step1\": {\n \"start\": \"step2\",\n \"reset\": \"step1\"\n },\n \"step2\": {\n \"zip\": \"step3\",\n \"reset\": \"step1\"\n },\n \"step3\": {\n \"upload\": \"step1\",\n \"reset\": \"step1\"\n }\n },\n \"data\": {\n },\n \"methods\": {\n \"init\": [\n \"sm.udir = RED.settings.userDir + '/';\",\n \"sm.exec = require('child_process').exec;\",\n \"sm.hostname = require('os').hostname();\",\n \"sm.unlink = require('fs').unlink;\"\n],\n \"start\": [\n \"/* delete old zip file */\",\n \"var zipfile = sm.udir+'node-red.zip';\",\n \n \"sm.fill = 'grey';\",\n \"sm.text = 'deleting';\",\n \"output = false;\",\n\n \"sm.unlink(zipfile, function (err) {\",\n \" if (err) {\",\n \" node.warn('no file '+zipfile);\",\n \" }\",\n \" resume('zip', msg);\",\n \"});\"\n],\n \"zip\": [\n \"var pre = ' ' + sm.udir;\",\n \"var cmd = 'tar.exe -a -c -f';\",\n \"cmd += pre + 'node-red.zip';\",\n \"cmd += pre + 'flows*.json';\",\n \"cmd += pre + '.config.json';\",\n \"cmd += pre + '.sessions.json';\",\n \"cmd += pre + 'settings.js';\",\n \"cmd += pre + 'package.json';\",\n \"cmd += pre + 'package-lock.json';\",\n \"cmd += pre + 'lib/*';\",\n\n \"sm.fill = 'grey';\",\n \"sm.text = 'zipping';\",\n \"output = false;\",\n \n \"sm.exec(cmd, function(error, stdout, stderr) {\",\n \" if (error) {\",\n \" node.warn(error);\",\n \" } else {\",\n \" resume('upload', msg);\",\n \" }\",\n \"});\"\n],\n \"upload\": [\n \"sm.ts = new Date();\",\n \"sm.days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];\",\n \"sm.day = sm.days[sm.ts.getDay()];\",\n \"msg.filename = sm.day + '_nodered.zip';\",\n \"msg.localFilename = sm.udir+'node-red.zip';\",\n \"sm.fill = 'green';\",\n \"sm.text = sm.day;\"\n ],\n \"reset\": [\n \"sm.fill = 'grey';\",\n \"sm.text = 'reset';\",\n \"output = false;\"\n],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.fill\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.text\"\n }\n }\n }\n}","x":355,"y":160,"wires":[["44702648.1f2418"]]}]

```

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [6 July 2020 20:41 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/8 "2020-07-06T20:41:57Z")

</div>

Just a note, the user may need to install zip. All my installs have unzip but none had zip

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [6 July 2020 20:48 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/9 "2020-07-06T20:48:34Z")

</div>

Hi @Buckskin, I've moved your post here because that issue was raised earlier today by @cymplecy, and also other users trying this solution will read it.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [6 July 2020 21:10 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/10 "2020-07-06T21:10:59Z")

</div>

Cheers, thanks for the flow. Works well.

I have no clue about the DSM node so I have changed the save filename (to distinguish WHICH Pi I am backing up) in a Change node between it and the Dropbox node. Is there any way of specifying something in the Inject node to do the same thing?

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [6 July 2020 21:48 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/11 "2020-07-06T21:48:51Z")

</div>

Probably something that the DSM node author @cflurin may be able to answer.  
I'm not sure that the msg.payload is accessible from within the node itself.

I've just tried adding ` "sm.id = msg.payload;",` but it didn't seem to like it!

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 July 2020 09:05 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/12 "2020-07-07T09:05:22Z")

</div>

The flow did its first auto backup early this morning 🙂  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/90f1559266f0f76c9cf8aa577b2a2bc2f7667139.png)

I then managed to modify it to prefix the file name with the msg.payload from the inject node  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/9/997bcca8e799c218cc2506a36c250b908e830735.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b030e021840caa66a0e720542d0ba7728c046138.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7b07c45ce425fdf2cb5bf0654b43291e148c549a.png)

Modified DSM node only

```auto
[{"id":"20a4ec54.6c6454","type":"dsm","z":"fa1b22c7.a8823","name":"backup","sm_config":"{\n \"currentState\": \"step1\",\n \"states\": {\n \"step1\": {\n \"start\": \"step2\",\n \"reset\": \"step1\"\n },\n \"step2\": {\n \"zip\": \"step3\",\n \"reset\": \"step1\"\n },\n \"step3\": {\n \"upload\": \"step1\",\n \"reset\": \"step1\"\n }\n },\n \"data\": {\n },\n \"methods\": {\n \"init\": [\n \"sm.udir = RED.settings.userDir + '/';\",\n \"sm.exec = require('child_process').exec;\",\n \"sm.hostname = require('os').hostname();\",\n \"sm.unlink = require('fs').unlink;\"\n],\n \"start\": [\n \"/* delete old zip file */\",\n \"var zipfile = sm.udir+'node-red.zip';\",\n \n \"sm.fill = 'grey';\",\n \"sm.text = 'deleting';\",\n \"output = false;\",\n\n \"sm.unlink(zipfile, function (err) {\",\n \" if (err) {\",\n \" node.warn('no file '+zipfile);\",\n \" }\",\n \" resume('zip', msg);\",\n \"});\"\n],\n \"zip\": [\n \"var pre = ' ' + sm.udir;\",\n \"var cmd = 'tar -a -c -f';\",\n \"cmd += pre + 'node-red.zip';\",\n \"cmd += pre + 'flows*.json';\",\n \"cmd += pre + '.config.json';\",\n \"cmd += pre + '.sessions.json';\",\n \"cmd += pre + 'settings.js';\",\n \"cmd += pre + 'package.json';\",\n \"cmd += pre + 'package-lock.json';\",\n \"cmd += pre + 'lib/*';\",\n\n \"sm.fill = 'grey';\",\n \"sm.text = 'zipping';\",\n \"output = false;\",\n \n \"sm.exec(cmd, function(error, stdout, stderr) {\",\n \" if (error) {\",\n \" node.warn(error);\",\n \" } else {\",\n \" resume('upload', msg);\",\n \" }\",\n \"});\"\n],\n \"upload\": [\n \"sm.ts = new Date();\",\n \"sm.days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];\",\n \"sm.day = sm.days[sm.ts.getDay()];\",\n \"msg.filename = msg.payload + '_' + sm.day + '_nodered.zip';\",\n \"msg.localFilename = sm.udir + 'node-red.zip';\",\n \"sm.fill = 'green';\",\n \"sm.text = sm.day;\"\n ],\n \"reset\": [\n \"sm.fill = 'grey';\",\n \"sm.text = 'reset';\",\n \"output = false;\"\n],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.fill\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.text\"\n }\n }\n }\n}","x":355,"y":160,"wires":[["44702648.1f2418"]]}]

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [7 July 2020 10:49 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/13 "2020-07-07T10:49:38Z")

</div>

I think that I must have been overthinking it last night 🤫

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [7 July 2020 11:56 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/14 "2020-07-07T11:56:01Z")

</div>

You probably added it in the `init` method.  
This method is called once on deploy/start, as the input isn't triggered the msg object is undefined. All other methods can access the msg object (payload, topic etc.).

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 July 2020 19:15 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/15 "2020-07-07T19:15:04Z")

</div>

JFI I tried my modified DSM node out on a Pi but it kept erroring out

The tar command didn't like the fact that there was no .sessions.json file on my Pi

It worked fine once I deleted it from the list of backup files

Is it important to backup .sessions.json? what is that file for?

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [7 July 2020 19:41 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/16 "2020-07-07T19:41:39Z")

</div>

> [@cymplecy](#):
>
> Is it important to backup .sessions.json? what is that file for?

I did give some thought to removing that, because as far as I'm aware, it's a file that keeps users logged in, with the assumption that if deleted, all users would again need to login, and the file would be recreated (I'm happy to be corrected @dceejay ).  
If so, maybe restoring the `.sessions.json` could create more problems than not?

But... it was in @cflurin's [original DSM configuration](https://github.com/cflurin/node-red-contrib-dsm/wiki/Backup), and [this post](https://discourse.nodered.org/t/choosing-an-architecture-for-home-automation/6107/18), which persuaded me to keep it in.  
Maybe it should go??

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [8 July 2020 08:25 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/17 "2020-07-08T08:25:58Z")

</div>

As far as I know the `.session.json` can be omitted.  
I thought it would not be wrong to backup `.session.json`.  
At restore you can decide to use it or not.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [10 July 2020 14:07 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/18 "2020-07-10T14:07:29Z")

</div>

What is the consensus re `.sessions.json`, does it stay, or shall I remove it from the example flow config that I posted in post #1?

ie. Is it necessary for `.sessions.json` to form part of a node-RED backup archive.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [12 July 2020 21:26 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/19 "2020-07-12T21:26:19Z")

</div>

> [@Paul-Reed](#):
>
> What is the consensus re `.sessions.json` , does it stay, or shall I remove it from the example flow config that I posted in post #1?

No responses... so it has now been removed from the example flow above.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 July 2020 21:28 UTC](https://discourse.nodered.org/t/node-red-backup-flow/25033/20 "2020-07-12T21:28:01Z")

</div>

Missed your original question. The sessions file contains the active login tokens for the editor. No need to back it up.

[Next page](https://discourse.nodered.org/t/node-red-backup-flow/25033.md?page=2)
