Automate Flow Backup

Is there a way to automate the flow backup? I see we can export all flows but it would be good to have a nightly process to back this up.

Something we can schedule in a cron using CLI or even better, create a backup flow that will backup all of the tabs?

Node-RED logs the name of the flow file when it starts up. You can setup whatever process you want to copy that and the accompanying credentials file (same as your flow file, but with _creds added) to wherever you want.

There is also the Projects feature that allows you to have version control integrated with the editor.

To answer your question:
You might take a look at
https://flows.nodered.org/flow/add50316d37a2d2559feaca4e8c8f087
or
https://flows.nodered.org/flow/bc200a0dc255b129cdca40a619a93764
both by the same author. They seem similar, the second having more features and requirements. I used the first for while but stopped because I was getting lots of time-stamped backups with no easy way to tell what was in them.

To answer your problem:
I agree with @knolleary that the NR Projects feature might be the best answer to, for example, recovering from your mistakes. If you want protection from SD card corruption or other hardware failures, that's a different problem.

1 Like

I also use NR Projects, but as I quite often forget to commit and push changes :tired_face: so I also use a NR flow which I wrote to automatically backup NR (as well as emoncms data files) to a .tar.gz archive file, and then upload it to Dropbox - https://gist.github.com/Paul-Reed/c29cfa755fed666805956eb6da42a0d0

Once set up, it keeps up to 30 days worth of backups, and the older ones are automatically weeded off, so it's 'fit & forget'.

If you only want to backup node-red, just delete out the lines relating to emoncms, from within the 'Generate Commands' function node & renumber the execution order, as per the example below;

var path = '/home/pi/.temp_nodered/';
// Don't change this
var tmp_path = '/tmp/NR_backup/';

//Generate days to add to archive title
var d = new Date();
var day = new Array(7);
day[0]=  "Sun";
day[1] = "Mon";
day[2] = "Tue";
day[3] = "Wed";
day[4] = "Thu";
day[5] = "Fri";
day[6] = "Sat";

//Create directory structure
var m1={payload: "rm -rf "+[path]};
var m2={payload: "mkdir "+[path]};
var m3={payload: "mkdir "+[tmp_path]};

// ************************************************************************* //
// *** The below commands will archive the entire node-red user directory,
// *** To add further commands, use the same format, and add the
// ***  corresponding msg id to the 'return' statement.
// ************************************************************************* //
//---NODE-RED---//
  //Create ~/.node-red archive
  var m4={payload: "tar -czvf "+[path]+(day[d.getDay()])+"_nodered"+".tar.gz /home/pi/.node-red"};
  var m10={payload: "rm -rf "+[tmp_path]}; //delete old tmp directory from RAM
// ****************************************************** //
// Output the commands for execution
return [ [ m1, m2, m3, m4, m10 ] ];
4 Likes

I think the NR projects is one of the best way how to do it. I already did a test , also with an existing remote repo. Works great.

Because of forget push/comit: Is there any idea/solition to autmatic the push/commit?

Well, given the flexibility of Node-RED, there are lots of ways to achieve that.

A simple way would be a flow on a timer that uses the exec node to run a script or directly call git commands. Set it to run at midnight every day for example and you know that you will get at least one commit per day. You could then run it manually to do intermediate commits/pushes.

Agree, this could be also a very simple solution.

But it is also possible the existing 'projects/git' enviroment in NR?

I use the dsm node for the flow backup, including the context files.
It builds a zip file yyy-mm-ddThhmmss_nr.zip, which is sent to dropbox.

1 Like

Yes, certainly. All you need to do is make sure that you are in the correct folder before issuing the git commands via the exec node. Likely to be easiest to do that via a script which you can also put into the same folder. Mark it as executable then call it from an exec node. All you need in the script is something to make sure that the current working directory is correct then a git commit followed by a git push.

You will need to add an upstream master to the git repository for the project if you want it backed up to, lets say, GitHub. But that is a one-off job.