I added this small sub-flow in each of my flows to save the current context into a json file at the very same location and Nodered is expecting to find it on next restart. Runs every 30 seconds too.
So I shouldn't loose anything on next restart.
The change node set the payload with every flow context variable.
Payload is then converted to a JSON string and written into a file located at /data/context/<msg.flow_id>/flow.json
where <msg.flow_id>
has been set in the initial change node.
[{"id":"f24d8a57e205d6f8","type":"comment","z":"1eb7e7266b417749","name":"Save flow context","info":"","x":180,"y":60,"wires":[]},{"id":"f1bf7f8e80347c6d","type":"inject","z":"1eb7e7266b417749","name":"Save flow context","props":[{"p":"payload"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":210,"y":100,"wires":[["496b1eb33d801008"]]},{"id":"496b1eb33d801008","type":"change","z":"1eb7e7266b417749","name":"","rules":[{"t":"set","p":"flow_id","pt":"msg","to":"1eb7e7266b417749","tot":"str"},{"t":"set","p":"payload.last_mission_created","pt":"msg","to":"last_mission_created","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":100,"wires":[["15a05c6094adcfa7"]]},{"id":"8b978ae385275feb","type":"debug","z":"1eb7e7266b417749","name":"flow context file","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":100,"wires":[]},{"id":"1fa109fc41b2a0a4","type":"file","z":"1eb7e7266b417749","name":"","filename":"\"/data/context/\" & msg.flow_id & \"/flow.json\"","filenameType":"jsonata","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":700,"y":100,"wires":[["8b978ae385275feb"]]},{"id":"15a05c6094adcfa7","type":"json","z":"1eb7e7266b417749","name":"","property":"payload","action":"","pretty":false,"x":570,"y":100,"wires":[["1fa109fc41b2a0a4"]]}]