Saving flows

742 views
Skip to first unread message

Blue Collar Ingenuity

unread,
Nov 19, 2015, 8:32:14 PM11/19/15
to Node-RED
Is it normal to lose all flows when the power is interrupted ??   Ughhh

Jeff  

Emil Oberg

unread,
Nov 20, 2015, 3:18:08 AM11/20/15
to Node-RED
No, they should be persisted in a json file (by default flows_<your-host-name>.json) in your node-red directory (by default ~/.node-red). You can also configure which flows file to be used in settings.js (same folder).

However, that file could have been corrupted on power failure. Check it out.

E

Dave C-J

unread,
Nov 21, 2015, 5:07:08 AM11/21/15
to node...@googlegroups.com
There should also be a one level backup saved in   .flows_{your-host-name}.json.backup   (with a preceeding . )
When you hit deploy - we copy the existing flows file to this - then write the new one. We don't hold any file open.

Peter Scargill

unread,
Nov 21, 2015, 6:32:00 AM11/21/15
to Node-RED
Oh.. that's nice to know - thanks for that.
Message has been deleted

The ThingBox

unread,
Nov 28, 2015, 8:01:13 AM11/28/15
to Node-RED
I don't remember when but we reported here that problem: if you switch off the Pi in a delay of 45s after deploying the flow, it gets lost (file of 0 bytes).
It seems there is no solution to avoid this - Pi problem, thus the backup workaround as stated below.

Notice that in the Thingbox, there is a script that detects at startup that 0 bytes file and replace it with the backup automatically.

Nicolas.

Mark Setrem

unread,
Nov 28, 2015, 8:09:45 AM11/28/15
to Node-RED
Its not a problem I've ever experienced, and certainly writing the flows file has never taken 45 seconds to write on any of my Raspberry Pis.

However if you feel that it is a problem, how about publishing the script so that the wider node-red community could benefit if they feel that have the need?

The ThingBox

unread,
Nov 28, 2015, 8:16:59 AM11/28/15
to Node-RED
It is possible (as you know, all on the thingbox is free), I'll ask the programmers for it but I believe it is a simple 3 lines of script that anyone here knows how to write ...

Nicholas O'Leary

unread,
Nov 28, 2015, 8:18:41 AM11/28/15
to Node-RED Mailing LIst
Out of interest, you say it is free, but are the modifications/scripts published anywhere other than the SD card image?



--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

The ThingBox

unread,
Nov 28, 2015, 8:54:57 AM11/28/15
to Node-RED

New stuff that is not on the Thingbox SDCard is here: https://www.npmjs.com/search?q=ttb

The Thingbox is full of small modifications that would be difficult and time consuming to publish out of the SDCard. 
And writing a SDCard and accessing the files in Samba on a network is matter of minutes: not  difficult if you want some code from the Thingbox...
(and most of the additional features of the Thingbox are written in NodeRED itself, in a workspace named "System", so easy to understand copy and adapt).

Nicolas.

Mark Setrem

unread,
Jan 3, 2016, 5:43:30 AM1/3/16
to Node-RED

Did you manage to get the  3 lines of script from your programmers?

Peter Scargill

unread,
Jan 5, 2016, 12:31:38 PM1/5/16
to Node-RED
Here's my input.

Yesterday - smack in the middle of that frantic activity in here - I was trying out stuff in Node-Red.  I stopped for a moment to reply to someone in here and BANG - the power went out for 2 seconds.

When everything came back up - There was a nice clean empty Node-Red with all my work gone. Ok, there are backups in my case I always keep WinSCP on and back up the flow files to my desktop so no harm done - but I agree that if it were possible to detect an empty system - note that there were backups and automaticallly restore them - it might save some hassle and give a better feel of reliability.

Ok, I know - use battery backup on the Pi... but I have several of them sitting here I'm experimenting with and far less backup batteries :-)

Julian Knight

unread,
Jan 5, 2016, 5:02:42 PM1/5/16
to Node-RED
Well Peter, you can't beat a proper UPS! I was fortunate to get two just before the "Great Sheffield Flood" a few years ago when the power was going out every couple of hours. I meant that I could carry on working with a laptop, switch, router and monitor.

In your case, plugging some multi-USB chargers to the UPS and connecting up the Pi's would give you all the protection you need :)

From around £50 from Amazon.

Peter Scargill

unread,
Jan 5, 2016, 5:27:22 PM1/5/16
to node...@googlegroups.com

Got one sitting opposite me waiting for me to get one of those PC type plugs to go in the back J

--
http://nodered.org
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/U9FSjFuREeU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.

Zenofmud

unread,
Jan 5, 2016, 7:54:39 PM1/5/16
to node...@googlegroups.com
Here is a little flow to backup your flows every time you hit deploy. It consists of 
- an injection node that runs at start
- two file read nodes - one to read the flows json and one to read the flows credentials file
- two file write nodes - one to write the flow file with ‘bkup’ extension and one to write the credentials with a ‘bkup’ extension

[{"id":"ca97aa6f.356858","type":"file in","z":"60a75827.9f58a8","name":"read credentials","filename":"/home/pi/.node-red/flows_test_cred.json","format":"utf8","x":493,"y":311,"wires":[["1c256156.e3da9f"]]},{"id":"1c256156.e3da9f","type":"file","z":"60a75827.9f58a8","name":"backup credentials","filename":"/home/pi/.node-red/flows_test_cred.bkup","appendNewline":true,"createDir":false,"overwriteFile":"true","x":862,"y":312,"wires":[]},{"id":"ef31143a.10cee8","type":"inject","z":"60a75827.9f58a8","name":"Auto backup flows","topic":"","payload":"caat","payloadType":"none","repeat":"","crontab":"","once":true,"x":193,"y":337,"wires":[["ca97aa6f.356858","9146fb80.6eb908"]]},{"id":"9146fb80.6eb908","type":"file in","z":"60a75827.9f58a8","name":"read flows","filename":"/home/pi/.node-red/flows_test.json","format":"utf8","x":473,"y":375,"wires":[["9d39915.f62c67"]]},{"id":"9d39915.f62c67","type":"file","z":"60a75827.9f58a8","name":"backup flows","filename":"/home/pi/.node-red/flows_test.bkup","appendNewline":true,"createDir":false,"overwriteFile":"true","x":855,"y":377,"wires":[]}]

Paul
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Nicholas O'Leary

unread,
Jan 5, 2016, 8:01:31 PM1/5/16
to node...@googlegroups.com

Paul, we you aware we already create backups of these files whenever you hit deploy?

Nick

Zenofmud

unread,
Jan 5, 2016, 8:42:34 PM1/5/16
to node...@googlegroups.com
Nick, 
Where? I know on the pi the flows is in the /home/pi/.node-red folder, but when I deploy I don’t see anything else there. 
Jessie -lite
npm v2.14.12
node v4.2.4
node-red v0.12.4

Zenofmud

unread,
Jan 5, 2016, 8:58:28 PM1/5/16
to node...@googlegroups.com
Ahhh they are hidden files in the .node-red folder…..

Well, if someone wants to automatically send the flow and credential somewhere, they could use this idea…(trying to grab some face - grin)

Peter Scargill

unread,
Jan 6, 2016, 1:13:57 AM1/6/16
to node...@googlegroups.com

No need to save face… it is great that Node-Red does a backup whenever you deploy – of course you could deploy the wrong thing twice and mess up – hence all is not lost… if you modified your script to do  SEQUENTIALLY NUMBERED backups, then it would still have a use for saving SNAPSHOTS of the state of things – rather handy for experimenting with various stuff in Node-Red – which is what I am doing right now.. You up for that Zenofmud?

Edward Vielmetti

unread,
Jan 6, 2016, 1:53:21 AM1/6/16
to node...@googlegroups.com
Even better, if the script checked every edit into your favorite source code control system, now you're cooking

Zenofmud

unread,
Jan 6, 2016, 3:27:06 PM1/6/16
to node...@googlegroups.com
Ok Peter,
Here you go - this flow will copy the flow and cred file and give them a timestamp and extension of ‘bkup’. I’ve tested it on my pi and OSX. You must edit your 'settings.js' file and find the section:

 functionGlobalContext: {
        // os:require('os'),
        // bonescript:require('bonescript'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false})

and uncomment the 'os:require('os'), line so you have:

 functionGlobalContext: {
           os:require('os'),
        // bonescript:require('bonescript'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false})

The flow grabs the current time and path to your home directory and your hostname and builds the filenames:

‘homedir'/.node_red/flows_’hostname’.json
‘homedir'/.node_red/flows_’hostname’_cred.json

passes both to a read file node that passes to a function node that test the filename for ‘cred’ and builds a new filename

‘homedir'/.node_red/flows_’hostname’_'curtime’.bkup
‘homedir'/.node_red/flows_’hostname’_cred_'curtime’.bkup

For example if your home dir was ‘/home/pi/ and your hostname was ‘test’, you would have: 

/home/pi/.node_red/flows_test.json
/home/pi/.node_red/flows_test_cred.json

which would become:

/home/pi/.node_red/flows_test_1452109745060.bkup
/home/pi/.node_red/flows_test_cred_1452109745060.bkup

on my mac I ended up with:

flows_Pauls-mini.local_1452110824626.bkup
flows_Pauls-mini.local_cred_1452110824626.bkup

There is no limit on the number of files you will create so remember if you do lots of deploys, you will have lots of files.
Paul

[{"id":"c705c608.38fa38","type":"inject","z":"60a75827.9f58a8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":113,"y":449,"wires":[["a7d498c6.582b68"]]},{"id":"a7d498c6.582b68","type":"function","z":"60a75827.9f58a8","name":"Build filenames","func":"// You need to have edited your settings.js file and uncommented the line\n//   //      os:require('os'),\n// in the 'functionGlobalContext: {'' section\ncontext.global.curtime = msg.payload;\nvar hostname = context.global.os.hostname();\nvar homedir = context.global.os.homedir();\nvar flow_path = homedir + '/.node-red/';\nvar flowfile = flow_path + 'flows_' + hostname +'.json';\nvar credfile = flow_path + 'flows_' + hostname +'_cred.json';\ncontext.global.bkupflowfile = flow_path + 'flows_' + hostname +'_'+ context.global.curtime+ '.bkup';\ncontext.global.bkupcredfile = flow_path + 'flows_' + hostname +'_cred_'+ context.global.curtime+ '.bkup';\n\nvar msg1 ={ filename: flowfile };\nvar msg2 ={ filename: credfile };\nreturn [msg1, msg2];\n","outputs":"2","noerr":0,"x":268,"y":449,"wires":[["2645a55c.d9ba5a"],["2645a55c.d9ba5a"]]},{"id":"2645a55c.d9ba5a","type":"file in","z":"60a75827.9f58a8","name":"read flows","filename":"","format":"utf8","x":431,"y":449,"wires":[["1034647d.efcb9c"]]},{"id":"a7676ec6.58989","type":"file","z":"60a75827.9f58a8","name":"backup flows","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"true","x":821,"y":448,"wires":[]},{"id":"1034647d.efcb9c","type":"function","z":"60a75827.9f58a8","name":"choose backup file name","func":"// test the file name to see if it is the flow or credentials file and use the appropriate one\nif (msg.filename.search(\"cred\") > 0) {\n    msg.filename = context.global.bkupcredfile;\n} else {\n    msg.filename = context.global.bkupflowfile;\n}\nreturn msg;","outputs":1,"noerr":0,"x":622,"y":449,"wires":[["a7676ec6.58989"]]},{"id":"ee87d5ee.117828","type":"comment","z":"60a75827.9f58a8","name":"Automatic backup of flow/credential files with a timestamp each time you DEPLOY","info":"This flow will backup your flow and credential json files each time you press 'Deploy'. \nNOTE: it will only work if you are using the defaults for the name of the file containing the flows.\n\nYou must edit your 'settings.js' file and find the section:\n\n functionGlobalContext: {\n        // os:require('os'),\n        // bonescript:require('bonescript'),\n        // jfive:require(\"johnny-five\"),\n        // j5board:require(\"johnny-five\").Board({repl:false})\n\nand uncomment the 'os:require('os'), line so you have:\n\n functionGlobalContext: {\n           os:require('os'),\n        // bonescript:require('bonescript'),\n        // jfive:require(\"johnny-five\"),\n        // j5board:require(\"johnny-five\").Board({repl:false})\n\nthis will allow this flow to grab the file paths to make the backups.","x":313,"y":405,"wires":[]}]

Peter Scargill

unread,
Jan 6, 2016, 3:52:37 PM1/6/16
to node...@googlegroups.com

I’m going to try this and THANK YOU for the effort - I’m aware of that section of the file as I’ve added “moment” in there so I can use moment…

 

Seems to me that a human readable date might be more useful than a timestamp (“oh, yes, messed that up this morning – lets go back to last night’s version”).

 

Tested, works a treat!

Peter Scargill

unread,
Jan 6, 2016, 3:55:58 PM1/6/16
to node...@googlegroups.com

Erm… no. I checked to see where you were getting the time from – and I see it is from startup…

 

You’re assuming (forgive me if I’m wrong) that DEPLOY is always used in full… I never use it in full – I have so much stuff (which is why I’m keen on backups) that it would take an age. I use partial deploy – only nodes that have changed – and this does not get triggered. Good idea though J

Nicholas O'Leary

unread,
Jan 6, 2016, 3:57:51 PM1/6/16
to Node-RED Mailing List
You could use the Watch node to spot when the flow file has been written to trigger a backup.... but I'll leave it as an exercise to the reader.

Nick

Peter Scargill

unread,
Jan 6, 2016, 4:01:38 PM1/6/16
to node...@googlegroups.com

Yes, well spotted Nicholas – use the watch node to watch for the Node-Red automatic flow backup – right – I’m onto it.

Peter Scargill

unread,
Jan 6, 2016, 4:23:20 PM1/6/16
to node...@googlegroups.com

Ok, here it is.. this works on any Deploy – even partial ones – and puts in a usable date and time.

 

Thanks guys – another useful tool.


Pete.

 

 

[{"id":"9a71729d.658e9","type":"watch","z":"55620bb2.aa9df4","name":"Watch Node-Red flow files","files":"/home/pi/.node-red","x":130,"y":510,"wires":[["bf412c5b.40bed"]]},{"id":"d822a643.27dd58","type":"function","z":"55620bb2.aa9df4","name":"Build filenames","func":"// You need to have edited your settings.js file and uncommented the line\n//   //      os:require('os'),\n// in the 'functionGlobalContext: {'' section\ncontext.global.curtime = msg.payload;\nvar hostname = context.global.os.hostname();\nvar homedir = context.global.os.homedir();\nvar flow_path = homedir + '/.node-red/';\nvar flowfile = flow_path + 'flows_' + hostname +'.json';\nvar credfile = flow_path + 'flows_' + hostname +'_cred.json';\ncontext.global.bkupflowfile = flow_path + 'flows_' + hostname +'_'+ context.global.curtime+ '.bkup';\ncontext.global.bkupcredfile = flow_path + 'flows_' + hostname +'_cred_'+ context.global.curtime+ '.bkup';\n\nvar msg1 ={ filename: flowfile };\nvar msg2 ={ filename: credfile };\nreturn [msg1, msg2];\n","outputs":"2","noerr":0,"x":158,"y":607,"wires":[["5e044d22.a1fbb4"],["5e044d22.a1fbb4"]]},{"id":"5e044d22.a1fbb4","type":"file in","z":"55620bb2.aa9df4","name":"read flows","filename":"","format":"utf8","x":333,"y":607,"wires":[["3fa1589f.c05ea8"]]},{"id":"b92e20bc.46d1e","type":"file","z":"55620bb2.aa9df4","name":"backup flows","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"true","x":396,"y":663,"wires":[]},{"id":"3fa1589f.c05ea8","type":"function","z":"55620bb2.aa9df4","name":"choose backup file name","func":"// test the file name to see if it is the flow or credentials file and use the appropriate one\nif (msg.filename.search(\"cred\") > 0) {\n    msg.filename = context.global.bkupcredfile;\n} else {\n    msg.filename = context.global.bkupflowfile;\n}\nreturn msg;","outputs":1,"noerr":0,"x":187,"y":663,"wires":[["b92e20bc.46d1e"]]},{"id":"9020dbae.6fdf28","type":"comment","z":"55620bb2.aa9df4","name":"Automatic backup of flow/credential files with a timestamp each time you DEPLOY","info":"This flow will backup your flow and credential json files each time you press 'Deploy'. \nNOTE: it will only work if you are using the defaults for the name of the file containing the flows.\n\nYou must edit your 'settings.js' file and find the section:\n\n functionGlobalContext: {\n        // os:require('os'),\n        // bonescript:require('bonescript'),\n        // jfive:require(\"johnny-five\"),\n        // j5board:require(\"johnny-five\").Board({repl:false})\n\nand uncomment the 'os:require('os'), line so you have:\n\n functionGlobalContext: {\n           os:require('os'),\n        // bonescript:require('bonescript'),\n        // jfive:require(\"johnny-five\"),\n        // j5board:require(\"johnny-five\").Board({repl:false})\n\nthis will allow this flow to grab the file paths to make the backups.","x":303,"y":465,"wires":[]},{"id":"bf412c5b.40bed","type":"function","z":"55620bb2.aa9df4","name":"Check for json file change - insert time string","func":"\nif (msg.payload.indexOf(\".json\") > -1) \n   { msg.payload=new Date().toISOString().replace(/\\..+/, '');  \n     return msg;\n   }","outputs":1,"noerr":0,"x":252,"y":560,"wires":[["d822a643.27dd58"]]}]

 

From: node...@googlegroups.com [mailto:node...@googlegroups.com] On Behalf Of Nicholas O'Leary


Sent: 06 January 2016 20:58

Peter Scargill

unread,
Jan 6, 2016, 4:25:49 PM1/6/16
to node...@googlegroups.com

Shame we don’t have the input equivalent of the DEBUG on/off button (sending 1 or 0) – could have a PAUSE facility on this!!

Dave C-J

unread,
Jan 6, 2016, 4:30:27 PM1/6/16
to node...@googlegroups.com

What... Pause on the backups ? You then know exactly when it will crash  .... About an hour after you hit pause  and do a load of changes :-)

Zenofmud

unread,
Jan 6, 2016, 4:31:51 PM1/6/16
to node...@googlegroups.com
And too bad we can't grab the flow path directly - with this version using the watch, you have to hard code the path to the .node-red. Now if only you could pass the file path to the watch node...

I like the date formatting. Being a noob to javascript, I couldn’t figure out how to get the date formatted.
Paul

peters...@googlemail.com

unread,
Jan 6, 2016, 5:01:02 PM1/6/16
to node...@googlegroups.com, Dave C-J

Haaaaah

On 6 January 2016 21:30:30 Dave C-J <dce...@gmail.com> wrote:

What... Pause on the backups ? You then know exactly when it will crash  .... About an hour after you hit pause  and do a load of changes :-)

--

peters...@googlemail.com

unread,
Jan 6, 2016, 5:01:36 PM1/6/16
to node...@googlegroups.com, Zenofmud

My friend Google helped me :-)

Message has been deleted

Colin Law

unread,
Jul 16, 2017, 5:05:09 AM7/16/17
to node...@googlegroups.com
How are you making the changes and how are you saving them? If you
make the changes in the node-red GUI in the browser then they should
be automatically saved in the flows file in the .node-red folder when
you click deploy.

Colin

On 16 July 2017 at 09:56, Bobo <bulloc...@gmail.com> wrote:
> I am having trouble with the changes I have made to the original flow that
> uses the timestamp node (which by the way appears to work ok). I made some
> changes in Build Filenames (namely different date and time stamp, and
> different location for the backup files which I have saved to USB stick
> hanging off the RPi).
>
> The problem I am finding is that the saves are very intermittent. First off
> I thought the backup files were being saved every second deploy, but the
> saves are actually far more erratic than that. While I can use the original
> flow, I am very curious to know what I am doing wrong.
>
> Appreciate any help.
>
> Cheers
>
> [{"id":"78985840.617788","type":"function","z":"c067daa0.5f2e38","name":"Build
> filenames","func":"// You need to have edited your settings.js file and
> uncommented the line\n// // os:require('os'),\n// in the
> 'functionGlobalContext: {'' section\nvar d = new
> Date();\ncontext.global.curtime = d.toDateString() + '_' +
> d.toTimeString();\nvar hostname = context.global.os.hostname();\nvar homedir
> = context.global.os.homedir();\nvar flow_path = homedir +
> '/.node-red/';\nvar flowfile = flow_path + 'flows_' + hostname
> +'.json';\nvar credfile = flow_path + 'flows_' + hostname
> +'_cred.json';\ncontext.global.bkupflowfile = '/mnt/usb1/backups/'+'flows_'+
> context.global.curtime+ '.bak';\ncontext.global.bkupcredfile =
> '/mnt/usb1/backups/'+'flows_'+'_cred_'+ context.global.curtime+
> '.bak';\n\nvar msg1 ={ filename: flowfile };\nvar msg2 ={ filename: credfile
> };\nreturn [msg1,
> msg2];\n","outputs":"2","noerr":0,"x":327,"y":355,"wires":[["482c443c.902d8c"],["482c443c.902d8c"]]},{"id":"482c443c.902d8c","type":"file
> in","z":"c067daa0.5f2e38","name":"read
> flows","filename":"","format":"utf8","sendError":true,"x":530,"y":350,"wires":[["a7301e12.f9b3d"]]},{"id":"e507f7f0.b43f58","type":"file","z":"c067daa0.5f2e38","name":"backup
> flows","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"true","x":980,"y":351,"wires":[]},{"id":"a7301e12.f9b3d","type":"function","z":"c067daa0.5f2e38","name":"choose
> backup file name","func":"// test the file name to see if it is the flow or
> credentials file and use the appropriate one\nif
> (msg.filename.search(\"cred\") > 0) {\n msg.filename =
> context.global.bkupcredfile;\n} else {\n msg.filename =
> context.global.bkupflowfile;\n}\nreturn
> msg;","outputs":1,"noerr":0,"x":754,"y":355,"wires":[["e507f7f0.b43f58"]]},{"id":"4d634ae7.c2a574","type":"watch","z":"c067daa0.5f2e38","name":"","files":"/home/pi/.node-red/","recursive":"","x":109,"y":358,"wires":[["78985840.617788"]]}]
>
>> You could use the Watch node to spot when the flow file has been written
>> to trigger a backup.... but I'll leave it as an exercise to the reader.
>
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/86b6900b-a115-4f63-a7f5-5780f013f068%40googlegroups.com.

Bobo

unread,
Jul 16, 2017, 6:25:19 AM7/16/17
to Node-RED
I am using the flow described earlier in this thread. I changed the directory so they are saved to a usb stick. The issue appears to occur when I use the watch node (added by Mr Scargill) instead of the timestamp node to trigger a save.


[{"id":"78985840.617788","type":"function","z":"c067daa0.5f2e38","name":"Build filenames","func":"// You need to have edited your settings.js file and uncommented the line\n//   //      os:require('os'),\n// in the 'functionGlobalContext: {'' section\nvar d = new Date();\ncontext.global.curtime = d.toDateString() + '_' + d.toTimeString();\nvar hostname = context.global.os.hostname();\nvar homedir = context.global.os.homedir();\nvar flow_path = homedir + '/.node-red/';\nvar flowfile = flow_path + 'flows_' + hostname +'.json';\nvar credfile = flow_path + 'flows_' + hostname +'_cred.json';\ncontext.global.bkupflowfile = '/mnt/usb1/backups/'+'flows_'+ context.global.curtime+ '.bak';\ncontext.global.bkupcredfile = '/mnt/usb1/backups/'+'flows_'+'_cred_'+ context.global.curtime+ '.bak';\n\nvar msg1 ={ filename: flowfile };\nvar msg2 ={ filename: credfile };\nreturn [msg1, msg2];\n","outputs":"2","noerr":0,"x":327,"y":355,"wires":[["482c443c.902d8c"],["482c443c.902d8c"]]},{"id":"482c443c.902d8c","type":"file in","z":"c067daa0.5f2e38","name":"read flows","filename":"","format":"utf8","sendError":true,"x":530,"y":350,"wires":[["a7301e12.f9b3d"]]},{"id":"e507f7f0.b43f58","type":"file","z":"c067daa0.5f2e38","name":"backup flows","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"true","x":980,"y":351,"wires":[]},{"id":"a7301e12.f9b3d","type":"function","z":"c067daa0.5f2e38","name":"choose backup file name","func":"// test the file name to see if it is the flow or credentials file and use the appropriate one\nif (msg.filename.search(\"cred\") > 0) {\n    msg.filename = context.global.bkupcredfile;\n} else {\n    msg.filename = context.global.bkupflowfile;\n}\nreturn msg;","outputs":1,"noerr":0,"x":754,"y":355,"wires":[["e507f7f0.b43f58"]]},{"id":"4d634ae7.c2a574","type":"watch","z":"c067daa0.5f2e38","name":"","files":"/home/pi/.node-red/","recursive":"","x":109,"y":358,"wires":[["78985840.617788"]]}]

Colin Law

unread,
Jul 16, 2017, 7:27:02 AM7/16/17
to node...@googlegroups.com
Ah, sorry, I misunderstood.
Put some debug nodes in to find out where it is failing. For example a
debug on the watch node will show you whether that is seeing the
changed files. I wonder whether the problem is that the change node
only sees changes that happen while it is running, so if you do a full
deploy, which restarts the change node, it does not see the change
(which happens after the change node is stopped, but before it is
started again. Or alternatively the change node may see it before it
is stopped but the re-deploy chucks away any active messages so the
change message gets lost before it writes the new backup.

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/93466348-75a2-4de6-9cf2-e571f697e01d%40googlegroups.com.

Zenofmud

unread,
Jul 16, 2017, 8:28:45 AM7/16/17
to node...@googlegroups.com
might part of the problem be the file name you are creating? When I ran your flow and add a debug node, I see the filename to backup to as:

    filename"/mnt/usb1/backups/flows_Sun Jul 16 2017_08:19:33 GMT-0400 (EDT).bak”

Note the spaces in the name?

Paul

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Bobo

unread,
Jul 16, 2017, 9:29:44 AM7/16/17
to Node-RED
I stripped out any reference to date/time to remove the spaces, and that seemed to fix things.

But after about 5 deploys it once again started to fail to save. Perhaps it is as Colin suspects. Odd that it sometimes works and sometimes doesn't, unless it is some sort of timing issue.

Cheers

Colin Law

unread,
Jul 16, 2017, 9:51:07 AM7/16/17
to node...@googlegroups.com
I would be surprised if taking the spaces out fixed an intermittent issue.

Have you put a debug on the change node so you can see if it is that
which is failing? If it isn't that then put debugs at each point and
see where it gets lost.

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/141c5670-d88c-487f-804c-ef10a2bf55a1%40googlegroups.com.

Bobo

unread,
Jul 16, 2017, 12:34:44 PM7/16/17
to Node-RED
Yes, the problem does indeed seem to be with the watch node. Nothing gets generated when it does not work.

Bobo

unread,
Jul 16, 2017, 12:38:14 PM7/16/17
to Node-RED
My previous reply was a bit ambiguous. I meant to say that when I put a debug node on the change node, there is no output being generated.

Bobo

unread,
Jul 17, 2017, 2:48:30 AM7/17/17
to Node-RED
But now I shall contradict my previous observation by saying that I just had an occurrence where the correct filename was displayed from the watch node after a deploy. But the backup files were not produced in this instance. So there may be two separate issues.

Colin Law

unread,
Jul 17, 2017, 4:12:05 AM7/17/17
to node...@googlegroups.com
Imagine: click deploy, file gets written, watch node generates message, node red stops flow, message get discarded before it gets to file node. I suspect your approach will not work.
Colin

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Bobo

unread,
Jul 17, 2017, 5:49:11 AM7/17/17
to Node-RED
Same approach as detailed earlier in the thread so that's why I thought it would work, and it does, intermittently. So a timing issue I guess.

Anyhow, interesting exercise, and thanks for taking the time to respond.

Cheers


On Monday, 17 July 2017 16:12:05 UTC+8, Colin Law wrote:
Imagine: click deploy, file gets written, watch node generates message, node red stops flow, message get discarded before it gets to file node. I suspect your approach will not work.
Colin
On 17 Jul 2017 7:48 a.m., "Bobo" <bulloc...@gmail.com> wrote:
But now I shall contradict my previous observation by saying that I just had an occurrence where the correct filename was displayed from the watch node after a deploy. But the backup files were not produced in this instance. So there may be two separate issues.


On Monday, 17 July 2017 00:38:14 UTC+8, Bobo wrote:
My previous reply was a bit ambiguous. I meant to say that when I put a debug node on the change node, there is no output being generated.

On Monday, 17 July 2017 00:34:44 UTC+8, Bobo wrote:
Yes, the problem does indeed seem to be with the watch node. Nothing gets generated when it does not work.

On Sunday, 16 July 2017 21:51:07 UTC+8, Colin Law wrote:
I would be surprised if taking the spaces out fixed an intermittent issue.

Have you put a debug on the change node so you can see if it is that
which is failing? If it isn't that then put debugs at each point and
see where it gets lost.

Colin


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Colin Law

unread,
Jul 17, 2017, 11:48:06 AM7/17/17
to node...@googlegroups.com
Instead I suggest storing the update timestamp of the flows file in
persistent storage (MQTT, a file, sqlite, whatever you fancy), then on
node red startup check the flows file timestamp against that stored.
You would still have a problem if you did a partial deploy though, so
perhaps would have to poll the flows file. In fact possibly better to
take this out of node-red and just have a script or cron task to watch
the file and make the backups. In fact incron [1] is designed for
exactly this sort of task I think.

[1] https://www.howtoforge.com/tutorial/trigger-commands-on-file-or-directory-changes-with-incron/

Colin
> https://groups.google.com/d/msgid/node-red/848c632f-a788-4c18-956c-1d858e48eec7%40googlegroups.com.

Bobo

unread,
Jul 17, 2017, 12:26:20 PM7/17/17
to Node-RED
Thanks. I shall look into that.

Cheers

David Caparrós

unread,
Jul 17, 2017, 7:17:21 PM7/17/17
to Node-RED

Hello Bobo

I don't know if could help you, I have a raspberry pi and copy the flows on every deploy or once a day at 00:00 automatically on /.node-red folder and also on a USB pendrive.

I made a small script with nano at /usr/local/bin called "backupflows"  that I gave execution permissions for execution with sudo chmod +777 .

It copy the actual flow file and copy it with hour+minute+day+month+year  apend at the end.  As example:

flows_raspberrypi.json.backup.010618072017
flows_raspberrypi_cred.json.backup.010618072017

Frankly speaking I copy those 2 original files as I had being doing always like this however I'm not sure if booth are required.

On the script I wrote:

#!/bin/bash



 sudo cp ~/.node-red/flows_raspberrypi.json         /media/pi/E8BE-34D94/flows_raspberrypi.json.bac$
 sudo cp ~/.node-red/flows_raspberrypi_cred.json    /media/pi/E8BE-34D94/flows_raspberrypi_cred.jso$
 sudo cp ~/.node-red/flows_raspberrypi.json         ~/.node-red/flows_raspberrypi.json.backup.`date$
 sudo cp ~/.node-red/flows_raspberrypi_cred.json    ~/.node-red/flows_raspberrypi_cred.json.backup.$


then at anymoment writting on console "backupflows" the backup is done automatically on booth folders (pendrive and node red).

Then I wrote a simple flow that execute this comand at deploy/start or every day at 00:00.

[{"id":"21e750f1.70f79","type":"inject","z":"2f7fb3d3.985d9c","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"00 00 * * *","once":false,"x":150,"y":640,"wires":[["b7556f6d.707c7"]]},{"id":"b7556f6d.707c7","type":"exec","z":"2f7fb3d3.985d9c","command":"backupflows","addpay":false,"append":"","useSpawn":"","timer":"","oldrc":false,"name":"flows backup","x":330,"y":640,"wires":[[],[],[]]},{"id":"12d02c8a.2e8263","type":"inject","z":"2f7fb3d3.985d9c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":150,"y":600,"wires":[["b7556f6d.707c7"]]}]



I don't know if this could make you live easier.

Regards

Reply all
Reply to author
Forward
0 new messages