Correct Shutdown on Rpi with ZRAM (and possibly) Amanda

Hello,
I’m running Openhab 3.3.0 on Openhabian and a Rasspberry Pi4 on SD-Card with activated ZRAM, rrjd as persistence service. Also I would like to use Amanda as well.

After the last blackout, I learned the hard way, that my setup is not resilient to it, loosing the persisted data since the last power-up (over 1 month in this case). This is the expected result as I figured out now.

So now I’m adding a UPS to the system to shutdown everything correctly.
But now I’m kind of lost. How to turn it off correctly?

I tried using
sudo service openhab stop
but it seems that this does not secure that all data is correctly saved.

Here: ZRAM status it is said under “donts”, ZRAM needs to be shutdown properly, but not how to do so. They say to use Amanda to secure against blackouts.

I couldn’t find a “best practice” solution that was understandable for me.

How to shutdown the system correctly, saving all data and actually writing it to the filesystem?

I think Amanda then is “only” a way of a general backup strategy.

Can you help/guide me to a solution?

  • Platform information:
    • Hardware: Raspberry Pi4
    • OS: Raspbian GNU/Linux 10
    • openHAB version: 3.3.0

Just enter shutdown. That should shutdown zram-config.service which will permanently store all ZRAM files like persistence data.

You can also systemctl stop zram-config.service

Hmmm, seems to work just fine for now.

Is there a difference between shutdown and reboot? I tested myself with reboot, where I had data loss (if I remember correctly)

There’s no difference, as they both call the shutdown command.

sudo reboot = sudo shutdown -r

You would only lose data if power was lost before data was written from ZRAM (as happened with the power outage), which should not happen if you run shutdown or reboot.

Are you using Network UPS Tools? If so, the NUT monitoring client will shut down your RPi and there’s no need to run commands from openHAB.

Yep understood now. When I was testing, I thought I saw data loss even when doing reboot. Thinking I would need more than just that.

Thank you for the help

I dont use amanda, i use only autobackup via sdcard mirroring.

So that means for me that storage zram data to sdcard only works by shutdown/reboot ?
Sd card mirroring (autobackup) doesnt mirror zram data …

Is it in my case common to reboot Raspberry continuiesly for zram data storage ?

thx Stephan

Yes.

No. Go use Amanda.

Yes that’s what I’m now doing.

Everything (exept Amanda…) works fine now!
Shutdown does the right things.