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.

@mstormi
Seems someone has seen your issue / feature request to zram-config on github.

with release 1.5.0 (May 2022) there is a “sync” option in zram-config and a predefined .timer and service to do it once a day.

just from testing it, it needs some time to execute and in this time, the UI of openghab 4 seems to be not properly reachable, but the persistence data is there and complete for the time in between.

this timer should be executed well before sdrawcopy.timer and sdrsync.timer / service… Maybe it makes even sense to not even execute that timer, but just exec what the timer would do.
:wink:

@urmono

just a quick fix
if you modify /usr/local/sbin/mirror_sd by adding

/usr/local/zram-config "sync"

before the mirror_SD funcion call

#!/usr/bin/env bash

BASEDIR=/opt/openhabian
CONFIGFILE=/etc/openhabian.conf

source $CONFIGFILE

source ${BASEDIR}/functions/helpers.bash
source ${BASEDIR}/functions/backup.bash

/usr/local/sbin/zram-config "sync"
mirror_SD "$@"

then it will sync right before it does an rsync or dd of the SD Card

(works as soon as used zram-config is version 1.5.0 or higher)

1 Like