Context Data Export

Hiya All!!

Pray tell.... Is context data able to be exported?

Currently, every so often (Read that as about every week or two), I export all of my flows on my home auto system to a local download file and keep them as a backup...

Every less so often, I do a full SD copy of the little pi and rotate it out with a security backup in case the pawpaw really hits the fan...

But..... Context data.... I take it that this is NOT backed up with a flow export... With the time taken to do a full SD backup (About 30 to 45min), what would be the procedure to backup the context data to save a bit, no, a lot of time in the long run?

TIA
Ed

PS - Is there an option in Node-Magnificent-Red to perhaps do this already?

Context nodes store there data depending on how you have defined them in your settings.js file. However, they are not part of a flows export.

If you configure them in settings.js to use the 'localfilesystem'

     	contextStorage: {
			default    : { module: "localfilesystem" },
 			memory     : { module: "memory" }
     	},

Then they will exist in your .node-red folder in a folder called context. So you would have to back that up and restore it.

Hi Ed , this is what I use to save this kind of data.
You need to have modified the settings.js for example as shown in Paul subject.

Here is my settings.js

     contextStorage: {
         default: {
               module:"localfilesystem",
                              config: {
                  "dir":"/home/pi/global-variables"
               }
         }
     },

You just have to modify the flow to do what you want with it.
Mine proposes you to save the data from the dashboard via HTTP.
I hope this is what you are looking for.

Here is my flow:

[{"id":"975f4b21178ba596","type":"tab","label":"Download global-variables","disabled":false,"info":"Permet de sauvegarder les paramètres généraux définis par l'utilisateur. "},{"id":"019e917643c6b1ac","type":"group","z":"975f4b21178ba596","name":"Création du point d'accès WEB pour pouvoir télécharger le fichier ZIP","style":{"stroke":"#ffC000","fill":"#ffffbf","fill-opacity":"0.56","label":true,"label-position":"ne","color":"#001f60"},"nodes":["616400b59b8d3a41","4ee9b1103a6b3009","236c16ee4343247f","782a67a73c678948","e68760dc0cb71bd5","b543f73f3b5be94f","10f90f8115c5fccd","fcf6a904f6f5dced","4e2e1d944a8c42ac"],"x":34,"y":519,"w":692,"h":262},{"id":"041be8cb1b733975","type":"group","z":"975f4b21178ba596","name":"Backup des variables définies dans les paramètres généraux sur le PC du client","style":{"stroke":"#ffC000","fill":"#ffffbf","fill-opacity":"0.56","label":true,"label-position":"ne","color":"#001f60"},"nodes":["ca85328ab58f181f","c2a2246f17af9237","dbbb785dd7fec6da","2c15e2f8359a5f1d","bcef11b5973b4ee4","ec820f12ad3b4c9a","d75054f870a32ec6","ac1f597fcfbff841","daab9cd00643db7f","16e2e1bdf00ea08d","dd37011beea973ce","4e886683c38c21c4","33897f2f7cf5a7ce","4c4eede290641db9","03b06e5f3aa3b5d0","83dff58b7a0fb8da"],"x":34,"y":19,"w":1192,"h":402},{"id":"ca85328ab58f181f","type":"exec","z":"975f4b21178ba596","g":"041be8cb1b733975","command":"zip -r /home/pi/Documents/global-variables/global-variables.zip /home/pi/global-variables/context/global","addpay":false,"append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"ZIP global-variables","x":400,"y":280,"wires":[[],[],["c2a2246f17af9237"]]},{"id":"c2a2246f17af9237","type":"switch","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"OK ? ","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":610,"y":280,"wires":[["dd37011beea973ce","83dff58b7a0fb8da"],[]]},{"id":"dbbb785dd7fec6da","type":"exec","z":"975f4b21178ba596","g":"041be8cb1b733975","command":"rm -f /home/pi/Documents/global-variables/*.*","addpay":false,"append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"Remove temporary folder & files","x":430,"y":200,"wires":[["ec820f12ad3b4c9a","ca85328ab58f181f"],[],[]]},{"id":"2c15e2f8359a5f1d","type":"comment","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"Backup de global-variables et download sur le PC (/home/pi/Documents/global-variables/global-variables_xxxxx.tar.gz","info":"","x":460,"y":60,"wires":[]},{"id":"bcef11b5973b4ee4","type":"inject","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"20","topic":"","payloadType":"date","x":146,"y":200,"wires":[["dbbb785dd7fec6da"]]},{"id":"ec820f12ad3b4c9a","type":"function","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"Start Saving","func":"msg.topic=\"INFO\";\nmsg.highlight='red';\nmsg.payload = \"Démarrage de sauvegarde\" + \"<br><br>\" + \"Veuillez attendre l'étape suivante S.V.P\" + \"<br><br>\" + \"Cela peut prendre du temps \";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":930,"y":200,"wires":[["d75054f870a32ec6"]]},{"id":"d75054f870a32ec6","type":"ui_toast","z":"975f4b21178ba596","g":"041be8cb1b733975","position":"top right","displayTime":"180","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"Cancel","raw":true,"topic":"","name":"","x":1120,"y":200,"wires":[]},{"id":"ac1f597fcfbff841","type":"function","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"Download Link","func":"msg.topic=\"INFO\";\nmsg.highlight='green';\nvar ip4 = global.get(\"ip4\");\nip4 = ip4.replace(/[\\r\\n]/g, \"\");\nvar file = \"<a href=http://\" + ip4 + \":1880/filesg/global-variables.zip>Fichier Zip des paramètres généraux</a>\";\nmsg.payload = \"Fichier prêt !\" + \"<br><br>\" + \"cliquer sur ce lien:  \" + file + \"<br><br>\" + \"Cela va télécharger la sauvegarde sur votre disque (répertoire Téléchargement ou Download).\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":940,"y":340,"wires":[["daab9cd00643db7f","33897f2f7cf5a7ce"]]},{"id":"daab9cd00643db7f","type":"ui_toast","z":"975f4b21178ba596","g":"041be8cb1b733975","position":"dialog","displayTime":"180","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":true,"topic":"","name":"","x":1110,"y":340,"wires":[[]]},{"id":"16e2e1bdf00ea08d","type":"ui_button","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"","group":"05c7c1fda0a37d5e","order":5,"width":7,"height":1,"passthru":false,"label":"Sauvegarde des paramètres généraux","tooltip":"Créer un fichier ZIP des paramètres généraux téléchargeable sur votre PC","color":"","bgcolor":"#6b665e","icon":"fa-table","payload":"","payloadType":"date","topic":"topic","topicType":"msg","x":210,"y":120,"wires":[["dbbb785dd7fec6da"]]},{"id":"dd37011beea973ce","type":"change","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"clear popup","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":280,"wires":[["4e886683c38c21c4"]]},{"id":"4e886683c38c21c4","type":"ui_toast","z":"975f4b21178ba596","g":"041be8cb1b733975","position":"top right","displayTime":"","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"Cancel","raw":true,"topic":"","name":"","x":1120,"y":280,"wires":[]},{"id":"33897f2f7cf5a7ce","type":"debug","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"link","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":380,"wires":[]},{"id":"4c4eede290641db9","type":"file","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"Create directory if not exist","filename":"/home/pi/Documents/global-variables/flag.txt","appendNewline":true,"createDir":true,"overwriteFile":"true","encoding":"none","x":980,"y":120,"wires":[[]]},{"id":"03b06e5f3aa3b5d0","type":"inject","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"20","topic":"","payloadType":"date","x":750,"y":120,"wires":[["4c4eede290641db9"]]},{"id":"616400b59b8d3a41","type":"function","z":"975f4b21178ba596","g":"019e917643c6b1ac","name":"Set base path","func":"//restrict to /home/pi/Documents/global-variables\nvar basePath = \"/home/pi/Documents/global-variables/\";\nvar filename = msg.req.params.fn;\n\n\nif(filename.includes(\"..\\\\\")){\n    msg.payload = \"Illegal file path\";\n    msg.statusCode = 405;//not allowed\n    return [null, msg];//fire output 2\n} else if(filename.includes(\"../\")){\n    msg.payload = \"Illegal file path\";\n    msg.statusCode = 405;//not allowed\n    return [null, msg];//fire output 2\n} \n//TODO: add more checks\n\nmsg.filename = basePath + filename;\nreturn [msg, null];//fire output 1\n\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":620,"wires":[["236c16ee4343247f"],["4ee9b1103a6b3009"]]},{"id":"4ee9b1103a6b3009","type":"http response","z":"975f4b21178ba596","g":"019e917643c6b1ac","name":"","statusCode":"","headers":{},"x":650,"y":660,"wires":[]},{"id":"236c16ee4343247f","type":"file in","z":"975f4b21178ba596","g":"019e917643c6b1ac","name":"","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":490,"y":600,"wires":[["4ee9b1103a6b3009"]]},{"id":"782a67a73c678948","type":"catch","z":"975f4b21178ba596","g":"019e917643c6b1ac","name":"","scope":null,"uncaught":false,"x":120,"y":700,"wires":[["e68760dc0cb71bd5","b543f73f3b5be94f"]]},{"id":"e68760dc0cb71bd5","type":"function","z":"975f4b21178ba596","g":"019e917643c6b1ac","name":"Set 404","func":"msg.payload = msg.error;\nmsg.statusCode = 404;//resource not found\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":700,"wires":[["4ee9b1103a6b3009"]]},{"id":"b543f73f3b5be94f","type":"debug","z":"975f4b21178ba596","g":"019e917643c6b1ac","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":290,"y":740,"wires":[]},{"id":"10f90f8115c5fccd","type":"comment","z":"975f4b21178ba596","g":"019e917643c6b1ac","name":"Create http endpoint <nodered>/files/xxx  where xxx is the file name to download","info":"","x":340,"y":560,"wires":[]},{"id":"fcf6a904f6f5dced","type":"http in","z":"975f4b21178ba596","g":"019e917643c6b1ac","name":"","url":"/filesg/:fn","method":"get","upload":false,"swaggerDoc":"","x":130,"y":620,"wires":[["616400b59b8d3a41","4e2e1d944a8c42ac"]]},{"id":"83dff58b7a0fb8da","type":"delay","z":"975f4b21178ba596","g":"041be8cb1b733975","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":780,"y":340,"wires":[["ac1f597fcfbff841"]]},{"id":"4e2e1d944a8c42ac","type":"debug","z":"975f4b21178ba596","g":"019e917643c6b1ac","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":270,"y":660,"wires":[]},{"id":"05c7c1fda0a37d5e","type":"ui_group","name":"▼ Sauvegarde des données","tab":"d2a61e034a94880a","order":1,"disp":true,"width":"9","collapse":false},{"id":"d2a61e034a94880a","type":"ui_tab","name":"Sauvegarde & Restauration","icon":"fa-download","order":22,"disabled":false,"hidden":false}]

Typo - should be a folder caller 'context'

@Paul-Reed Fudge! My only excuse is I was putting my granddaughter down for a nap (ok maybe I was going to take one too) and was on my phone. Thanks for spotting it!

Thanx JL!!

Spot on!!

Fantastic!!

Regds
Ed

PS: thanks @zenofmud and @Paul-Reed - Good info to have!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.