RPi3 / scheduled backup of sd card / stop openhab service?

Hi guys,

I’d like to do a scheduled backup of my OH1 installation on an RPi3 (with Raspian) using cron and dd. IMG file will be stored on a NAS (or USB stick, doesn’t matter). Does someone has knowledge in this? How do I have to handle the running openhab environment? Do I have to stop the openhab service? If so, is a “systemctl stop openhab” sufficient (and after the backup a systemctl start openhab) or do I have to stop also other OH-related services?

I’d prefer to not stop anything during the backup, but I don’t know if this leads to a proper image of my sd card, which is usable in case of a sd card failure.


I’m doing it manually with stopping the service and starting it again afterwards.
You can’t update a running (in other words actually used) instance of any software while it is running, so openhab has to be stopped.

Yes you can.

Simply give it a try, something like
dd bs=4M if=/dev/mmcblk0 |gzip > /mnt/image.gz

Then, for a test, burn that image to SD, restart your Pi from it. If you want the hardcore testing version, don’t stop OH but just switch off the Pi.
I’ve actually attached a SD card writer to my Pi and write right there, so the ‘backup card’ is always ready for prime time and even someone other than me can put it to use.

Thanks Jürgen. But I’m not quite sure what you mean with “update a running instance”. I am talking about a backup of a sd card, not an update process.

Sorry for that, I oversaw the UPDATE part.

If you want a hassle free automated backup use raspiBackup - Raspberry creates backups of itself.
You can also perform rsync backups which is very useful for the countless innovations we do to our items and rules … :grinning:


This also works: raspiBackup will continue backing up, but you will loose some of your log data. If you want to stop openHAB during backup you can do this with raspiBackup parameters.
It works, I had to use the restore function twice, once for testing and once due to a corrupted sd card.

Yeah, I have already seen this tool. Looks promising. But I haven’t really tried it yet.

I can live with that…

I’ve also seen this in the configuration options of raspiBackup. But I’m not so sure if stopping openHAB “regularly” has some negative side effects. For example for the zwave devices. Don’t they have a gray button in HABmin every time after a restart as long as they wake-up again?

Could happen, but they recover quickly (at latest after the wakup time has passed), but because those devices still function properly (mine do that), even when they are grey for a short period of time, I would not care much about that.

I only use my scard for the initial boot partition so the RPi3 runs off a Sandisk usb stick attached.

I have a cron job running every so often which mounts mmcblk0p2, runs rsync to copy the changes to it, then unmounts it again. I also rsync to a NAS for good measure from time to time. I don’t stop any services. If I have a failure (usually because I’ve done something stupid as I tinker too much), I can edit the /boot/cmdline.txt on a PC and change to use the sdcard. It seems to have worked well, Openhab & MYSQL seemed to have coped without issue so far fingers crossed.

Perhaps my approach is interesting, too. I use git to have a the complete Openhab configuration on a safe place. Yes a VCS is not a backup tool, but so I only have to install raspbian plus git and Openhab.

ATM the configuration is fetched every 15 Minutes and I can edit the files on the web or on my Desktop PC with the Openhab Tool. Because of the cronjob the configuration is online after some minutes.

Works well for me. But I have to admit that I don’t have the database or something else on that raspberry. :slight_smile:

1 Like

And what can go wrong if i make a dd copy of the sd without stopping openhab service?

That’s working for me, and I don’t see any reason why it shouldn’t work for you, too.

@mstormi that’s a good point! :slight_smile: Anyway, i’ll test an sd swap to see what happens, and test the procedure.

I installed raspibackup on my Pi without problems.
But how can I force raspibackup to create a dd backup without stopping / starting of services?
When I start raspibackup with /usr/local/bin/raspiBackup.sh /storage/diskstation/ I get an error: “Option -a und -o nicht angegeben.”

Just add -a: -o: to your parameters or use /usr/local/etc/raspiBackup.conf for your parameters:


Thanks a lot … I tried it with -a -o (without “:”) … that was my mistake …

1 Like

Hi Markus,

That looks like a much simpler solution for those of us that are intimidated by an Amanda solution. If there is an SD card failure, you can just swap out the old card and go - ie my kids could do it?


you’re intimidated by a solution where openHABian takes care of the setup ? Puzzles me.
If you did have a closer look at the Amanda manual, one of the first things you’re recommended to do after you’ve set it up is to create a clone SD (by restoring a backup) for the same reason as you mention, i.e. to have a working spare SD ready that anyone can be instructed to exchange in case of emergency.

Markus, as a linux newbie, the tone your readme made me decide to stay away from Amanda.

Ok, I disarmed the wording a little bit. It was written under the impression of some newbie feedback to believe it all point-and-click and failsafe, but that never is the case when free-form UNIX command line is involved.
Note that contents-wise, this is not specific to Amanda but to all Linux (read: give Amanda another chance).