In my OpenHabian 4.0.3 system, I have a number of numeric variables that revert to NULL when my raspberry pi is restarted after a power failure. I am trying to use the UI to setup MapDB as a persistence service to maintain the values on restarting.
I have installed MapDB from the Addons page and opened the configuration dialogue.
The fact that the switch is OFF is interesting. If expect it to be NULL unless it’s linked to a Channel. In that case, the binding is always going to override the restored value with the actual state of the device anyway to restoring that Item probably isn’t doing anything for you.
Using the API Explorer you can query MapDB and see if it’s actually saved values for those Items. If not there must be something up with your config. I don’t have a lot of experience configuring Persistence through the UI so all I can say on that front is it looks right.
The values for the three variables are correct and change when I alter then in the UI. So far so good, the value of the 3 three variables are being saved in the database.
Unplug the raspberry pie and restart. The Get / Persistance / items just shows [ ] with no values, so the database is being erased when the power is cut, hence the values are set NULL and OFF. Changing the values in the UI, correctly saves the new values in the database.
Seems as if the database is being held in memory, rather than being written to the SD card. If this is the case, how do I fix it?
No I did not properly shut down the Pi as I am trying to guard against a power failure, not an orderly shut down. I do have a battery backup supply for the Pi which will see me over a hour or so, but If I am away from the house or on vacation, the supply will fail.
If the MapDB is written to zram by default as you suggest, is there any way to force it to write to the SD card at the same time?
It looks as if the Zram and database issue has been addressed here
I already have a spare 500GB SSD so I have ordered a neat Argon One M.2 Case for the Pi which includes M.2 mounting board. Once I have this working, I may need to come back for help if I cannot figure out the UNIX commands to migrate the database files.
proper shutdown is required as during the shutdown ZRAM will be stopped and content will be writen to the underlying filesystem.
If its failing it will not help against a power failure. A low battery needs to trigger a normal shutdown.
If the battery fails and the power causes an immediate shutdown of the Pi your SD card is at risk of getting a corrupted filesystem.