Data loss after uncontrolled reboot for several days

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?

Yes

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:

2 Likes

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

1 Like

You can also change hardware platform to some mini PC. With SSD drive it will be a bit more resistant to unexpected shutdowns than PI with SD card and zram.

sadly i have the exactly same problem only with RRD4J (MapDB ,my default percistance, works just fine) and unexpected power loss.All my charts with power and gas consumption,freezers temperatures and others are gone after 5 hours of power loss last night.I have a ups but can last for 3-4 hours.I dont remember having this with openhab 3.xx.I have set to take monthly backups automatic but in that case i lose a full month of my charts.Is there a solution?Will a fresh openhabian install fix that?

Of course. The official docs recommend to setup Amanda, and if you had done that, it would have taken daily backups for you.

A fresh openhabian should do a daily sync of the rrd4j data in ZRAM to SD.
If yours didn’t you could add a cron job to do zram-config sync at intervals.

1 Like

As you now learned the hard way, it would be better to have a ups.
As it’s a Raspberry Pi, there are pretty cheap HATs for that purpose, they do only provide +5 Volt and the “better” models will provide even a watchdog and an rtc.
With the correct setup, when power is lost, the Raspberry Pi will shutdown and save all data.
When power comes back, the Pi will automatically start again and there will be no data loss at all.

scnr; :wink:

2 Likes

As the thread starter I can only recommend not to use a Rasperry Pi or specific hardware for openHAB, better use a virtual machine. I am using Proxmox on a Mini PC (HP Prodesk) with UPS and since then I have no problems at all: Easy backup, easy migration, snapshots before openHAB upgrades.
Amanda is a very complicated backup method compared to that.

1 Like

thx i just ordered one Hat ups with autoshutdown.I also take a conf backup daily to my nas using rsync.

Yepp, love ZFS :sparkling_heart: and zfs-auto-snapshot.