A flow for backup flows

Introduction

How many times you modify a flow and lost something from the previouse one? never? I don't think so ... it happen to me many times :( especially if I open flows from different computers.

So some months ago I wrote a simple flow for backup all the working flow at every commit of Node-RED.

How it works?

The script simply backup the following file:

/root/.node-red/flows_vps.json /root/.node-red/flows_vps_cred.json cloning in the same directory with a new name with timestamp. In order to make it work from your computer remember to:

  • change the path with the right one for your instance,
  • change the names of the files using the format flowYourHostname.json and flowYourHostname_cred.json

In order to make it work modify the actual URL in file and function nodes checking your enviroment url and filenames.

Both files are timestamped using the opentimestamp protocol (generating other 2 files with suffix ots).

Requested nodes

  • node-red-node-pushover a tool for receive notifications on mobile/tablet/desktop (take care! it's not totally free... but work well - OPTIONAL, if you dont like delete it)
  • node-red-contrib-opentimestamps a collection of Node-RED nodes useful for access the OpenTimestamps services.

Author

Valerio Vaccaro - valeriovaccaro.it

https://github.com/valerio-vaccaro

[
    {
        "id": "b02b6afd.9a03a8",
        "type": "comment",
        "z": "b215c41a.a5a1c8",
        "name": "Backup",
        "info": "",
        "x": 70,
        "y": 40,
        "wires": []
    },
    {
        "id": "96fb78de.022308",
        "type": "file in",
        "z": "b215c41a.a5a1c8",
        "name": "flows_wpc.json",
        "filename": "/root/.node-red/flows_wpc.json",
        "format": "utf8",
        "x": 300,
        "y": 100,
        "wires": [
            [
                "4cd460a7.b0a77"
            ]
        ]
    },
    {
        "id": "b6d83b5b.29eac8",
        "type": "file",
        "z": "b215c41a.a5a1c8",
        "name": "Save file",
        "filename": "",
        "appendNewline": false,
        "createDir": false,
        "overwriteFile": "true",
        "x": 780,
        "y": 100,
        "wires": []
    },
    {
        "id": "dcffbb7e.0c20f8",
        "type": "inject",
        "z": "b215c41a.a5a1c8",
        "name": "",
        "topic": "",
        "payload": "Node-RED: vale.uk.to restarted",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": true,
        "x": 90,
        "y": 100,
        "wires": [
            [
                "96fb78de.022308",
                "50980fba.747a5",
                "192ba28c.46e39d"
            ]
        ]
    },
    {
        "id": "4cd460a7.b0a77",
        "type": "function",
        "z": "b215c41a.a5a1c8",
        "name": "Generate new name",
        "func": "msg.filename = \"/root/.node-red/backup_\"+(new Date().toISOString().replace(':', '_').replace(':', '_').replace(/\\..+/, ''))+\"_flows_wpc.json\";\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 560,
        "y": 100,
        "wires": [
            [
                "b6d83b5b.29eac8",
                "3df5fc77.0197d4"
            ]
        ]
    },
    {
        "id": "50980fba.747a5",
        "type": "pushover",
        "z": "b215c41a.a5a1c8",
        "name": "",
        "device": "",
        "title": "",
        "priority": 0,
        "sound": "bike",
        "url": "",
        "url_title": "",
        "x": 280,
        "y": 40,
        "wires": []
    },
    {
        "id": "192ba28c.46e39d",
        "type": "file in",
        "z": "b215c41a.a5a1c8",
        "name": "flows_wpc_cred.json",
        "filename": "/root/.node-red/flows_wpc_cred.json",
        "format": "utf8",
        "x": 320,
        "y": 240,
        "wires": [
            [
                "77a1371.ffa0cc8"
            ]
        ]
    },
    {
        "id": "ea31afde.91086",
        "type": "file",
        "z": "b215c41a.a5a1c8",
        "name": "Save file",
        "filename": "",
        "appendNewline": false,
        "createDir": false,
        "overwriteFile": "true",
        "x": 780,
        "y": 240,
        "wires": []
    },
    {
        "id": "77a1371.ffa0cc8",
        "type": "function",
        "z": "b215c41a.a5a1c8",
        "name": "Generate new name",
        "func": "msg.filename = \"/root/.node-red/backup_\"+(new Date().toISOString().replace(':', '_').replace(':', '_').replace(/\\..+/, ''))+\"_flows_wpc_cred.json\";\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 560,
        "y": 240,
        "wires": [
            [
                "ea31afde.91086",
                "e043dc66.1cdb6"
            ]
        ]
    },
    {
        "id": "f5fcf744.668218",
        "type": "OTS_Stamp",
        "z": "b215c41a.a5a1c8",
        "name": "OTS_Stamp",
        "x": 1010,
        "y": 160,
        "wires": [
            [
                "92a4c84.49e3938",
                "6c63bc4b.fe8bd4"
            ]
        ]
    },
    {
        "id": "3df5fc77.0197d4",
        "type": "function",
        "z": "b215c41a.a5a1c8",
        "name": "Load data for OTS",
        "func": "msg.fileName = msg.filename;\nmsg.fileArray = new Buffer(msg.payload);\nmsg.otsName = msg.fileName + \".ots\";\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 810,
        "y": 160,
        "wires": [
            [
                "f5fcf744.668218"
            ]
        ]
    },
    {
        "id": "92a4c84.49e3938",
        "type": "function",
        "z": "b215c41a.a5a1c8",
        "name": "Prepare for save OTS",
        "func": "msg.filename = msg.otsName;\nmsg.payload = msg.otsArray;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 1220,
        "y": 160,
        "wires": [
            [
                "2fc84e6e.ba7de2"
            ]
        ]
    },
    {
        "id": "2fc84e6e.ba7de2",
        "type": "file",
        "z": "b215c41a.a5a1c8",
        "name": "Save file",
        "filename": "",
        "appendNewline": false,
        "createDir": false,
        "overwriteFile": "true",
        "x": 1420,
        "y": 160,
        "wires": []
    },
    {
        "id": "a437dcfb.48f4d",
        "type": "OTS_Stamp",
        "z": "b215c41a.a5a1c8",
        "name": "OTS_Stamp",
        "x": 1010,
        "y": 300,
        "wires": [
            [
                "a7b58720.eae958",
                "bdf5eb95.649178"
            ]
        ]
    },
    {
        "id": "e043dc66.1cdb6",
        "type": "function",
        "z": "b215c41a.a5a1c8",
        "name": "Load data for OTS",
        "func": "msg.fileName = msg.filename;\nmsg.fileArray = new Buffer(msg.payload);\nmsg.otsName = msg.fileName + \".ots\";\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 810,
        "y": 300,
        "wires": [
            [
                "a437dcfb.48f4d"
            ]
        ]
    },
    {
        "id": "a7b58720.eae958",
        "type": "function",
        "z": "b215c41a.a5a1c8",
        "name": "Prepare for save OTS",
        "func": "msg.filename = msg.otsName;\nmsg.payload = msg.otsArray;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 1220,
        "y": 300,
        "wires": [
            [
                "1da03aac.561615"
            ]
        ]
    },
    {
        "id": "1da03aac.561615",
        "type": "file",
        "z": "b215c41a.a5a1c8",
        "name": "Save file",
        "filename": "",
        "appendNewline": false,
        "createDir": false,
        "overwriteFile": "true",
        "x": 1420,
        "y": 300,
        "wires": []
    },
    {
        "id": "6c63bc4b.fe8bd4",
        "type": "debug",
        "z": "b215c41a.a5a1c8",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "true",
        "x": 1170,
        "y": 100,
        "wires": []
    },
    {
        "id": "bdf5eb95.649178",
        "type": "debug",
        "z": "b215c41a.a5a1c8",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "true",
        "x": 1170,
        "y": 240,
        "wires": []
    }
]
valerio-vaccaro

Flow Info

created 3 months, 2 weeks ago

Node Types

Core
  • comment (x1)
  • debug (x2)
  • file (x4)
  • file in (x2)
  • function (x6)
  • inject (x1)
Other

Tags

  • backup
  • opentimestamp
  • timestamp
  • blockchain
  • flow
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option