Data loss after uncontrolled reboot for several days


I am using openHAB 3.3 with openHABian on a Raspberry Pi 4. ZRAM is activated. RRD4J is the default persistence service, no special settings. When I do a controlled reboot (“sudo reboot”) everything works fine, all persistence values are restored.

Today, however, there was an uncontrolled reboot (my fault) and persistence data was restored up to July 21. The last days were lost. I had, however, a backup from yesterday which I could use.

My question is: I could understand that RRD4J because of ZRAM looses some data (maybe some hours) when there is an uncontrolled reboot, but days? Is there a (ZRAM?) setting which stores the data more regularly on the SD card?

Thanks for any help!

ZRAM prevents write access to the SD-Card. This is done via overlay file system (afaik). ZRAM will write all data to SD-Card if rebooting (or shutting down), but this is a “one big write access”. If cutting power :wink: there is no way to save data from RAM to SD-Card.

When ZRAM was added to openHABian there was a major problem with ZRAM periodically writing out to disk except at controlled reboots. I don’t know if it got fixed in upstream and never adopted by openHABian or if it’s still broken.

thanks for your answers. So there is no way to tell ZRAM “Save data on SD card more often”?

It got fixed and I haven’t seen any reports indicating it wouldn’t work in quite a long time.

No there isn’t.
After a power loss you’ll fall back to the point in time ZRAM was started the last time, usually that’s when the box was (intentionally) booted the last time before.
You can restart ZRAM (and OH) without booting or take daily backups (as recommended).

thanks for your clear answer. As a “layman” I thought that ZRAM does only “spare” write cycles for the SD card, yet writes the data to the SD card from time to time. I did not know that it only writes on reboots.

I’m having the exact same situation as in the OP. ZRAM is active. Data is retained on controlled reboot, but not power loss. I’m running an OH 3.4.0 standard installation on RPi 3B+.

If I’m supposed to restore a system backup after each power loss, then there ought to be an automatic restore of last backup upon boot, because uncontrolled may mean that I am not even at home.

Better would be if ZRAM would persist regularly.

If this isn’t even an issue for most, then I should just turn off ZRAM? Because the potential of months of data loss on an unsupervised system (holiday home) is not viable for me.

No, you should setup an automated daily backup so in case of power outage you can restore anything up to that last checkpoint.

Restoring a backup is a manual task, isn’t it?
Is restarting zram a solution? For example via cron?


No. That’ll restart OH.

So, restarting every night might be a solution then, hmm.

It’s not a solution, it’s against openHAB design principles and best practices and does more harm than good.
And solution for what problem ?

A solution for not losing data because of a power outage.

No, it’s not a solution for that because zram isn’t the only source of lost data during a power outage. As mentioned, the solution is to utilize one of the several backup and recovery strategies built into openHABian or, if you must, devise your own backup strategy.

True, but is there a recommended automated solution?
If not, a daily restart seems the only feasible automatic one, right?

…not using ZRAM and adding a USB-hdd/ssd storage might another more robust solution. Or is even in this setup a high risk to lose data after power outage beyond “normal” unix-like effects?

The openHABian | openHAB section of the docs discusses all of the backup and restore options. Most of them automatically back up. Restore is always going to be manual.

A daily restart is not a backup nor a restore process at all, automatic or otherwise.

It is generally a bad idea to yank the power from any machine. It’s particular dangerous for Unix like machines. It’s exceptionally dangerous for machines running off of flash memory.

The reason zram exists is to prevent writes to the SD card. This actually reduces the likelihood of a catastrophic lots of data caused by corruption of the card which could be bad enough to render the machine unbootable.

Your proposal eliminates one o
problem and increases the likelihood of damage from another.

This is why, the solution for preservation of your data is backup and restore. Anything else is going to be a half measure. A good deal of thought and when has been put into openHABian to provide the best compromise between reliability, ease of configuration, supportability, and configurability.

Any decision from what openHABian offers renders your system unsupportable. That doesn’t mean it won’t work. But it does mean you are on your own for solving most problems.

I agree to make backup and my point is not against backups.
But no one knows, when the next power outage happens. I had one today and lost data since the last reboot. (No mercy needed because it’s only a openhab-test for me.)
And i cannot guarantee having the time for restore when/after this happens. In the meantime OH records data. Will this data lost, when restoring the backup using the openhab(ian) way?

How about a battery backup? I live in south Florida US. (tropical weather) The power goes out all the time. I have a small inexpensive UPS. It is set up to gracefully shut down the box if the outage last long enough to run the battery down.
The box gets rebooted when I reboot it. :roll_eyes:


The solution is to equip your machine with UPS, as also say the docs @rlkoshak already referred you to. More details here.

1 Like