Recommended way to backup/restore OH2 configurations and things?

it should backup everything.
And yes at a fresh install you have to install grafana and influxdb first and then restore.


The two scripts backup and restore the configuration of everything inside openHAB. If you restored the backup on top of a fresh installation then it will reload the configuration exactly as it was. This also means that the bindings you had previously would be reinstalled on the next launch.

In practical terms this means that if you backed up a configuration from openHAB 2.1.0, then restored it on top of a new openHAB 2.2.0 instance. It would load the configuration and install the 2.2.0 version of the bindings.

It will also restore cross platform. The same scripts work for manual or automatic installs on any MacOS or Linux OS. Of course if you do this you’d need to reconfigure which port is used by the zwave dongles etc and the default permissions of the openHAB user.

My recommendation would be to call these openHAB scripts with the scripts for the other programs that @aksnet has posted.

1 Like

I guess I was little lucky:) Openhab was half running, but could not logon through putty (connections refused; even after few restarts). And my previously made backup, which I thought is on flash, apparently was not there. ha :smiley:

Found ext2explore and used to access the sd from pc; Following your backup script, manually copied all the mentioned files to safe location (did not do proper influxdb backup though). And then repeated the same - manual copy following your restore script. had to add few sudo in front of service starts. had to fix permissions at the end (because was copying through win?). had to remember to copy jars from addons. but other than that all up and running. such a good feeling. and no more enhancements before I try full backup-restore process and become sure I have it fixed :smiley:
Thank you!

And will eventually also uprgade to snapshot (again) so I have the built in scripts, too.

Hi all,
I’m very new to OpenHab and I just want to give you my opinion on this discussion.
My background is technical and in a former life I was even a software engineer :slight_smile:

First, the PaperUI helped me to get a jump start and I made first successful experiences. Therefore, I think it is needed for a first introduction.
Second, to understand the entire concept of openhab is really hard. In particular, making the step from PaperUI to the configuration via the eclipse designer was very hard for me. It seemed to me as two different concepts with now relation to each other
Btw, I love text file configuration, but only if I understand it :wink:

Third, backup us a real issue for me, because in my trail phase I sometime crashes my Pi or I want to go back to a previous state.
Now, as I understand the config stuff, I can backup this, but what about the PaperUI detected stuff? Best for me would be a twofold approach. 1. an export/import function for the PaperUI DB (its not important to get it human readable/editable but it must be restore-able) and 2. saving the text files (which is available today).

And last but not least, I really like and appreciate what you guys have done here. Now I need to go back to my system to learn more about it :slight_smile:

Thanks for reading.

1 Like

It’s there, fully automatic :grinning:. You just need to copy it to another drive to be more safe:

Depending on what version of OH you are running, there is a backup and restore script in /usr/share/openhab2/bin (I think that is where it is). If you are running openHABian, there is a full system backup setup and configured for you as well (Amanda is what it is called I think) that you can run from openhabian-config.

You can look at that backup and restore script and see what gets backups and restored. I’m pretty sure that is is the entire contents of /etc/openhab2, /var/lib/openhab2/jsondb, and perhaps /var/lib/openhab2/persistence.

It is all in /var/lib/openhab2/jsondb. Note that this is a human readable file.

From the latest stable version of openHAB (2.2) it would be easier for apt/yum/openHABian user to use the command:

sudo openhab-cli backup

Which places a file in /var/lib/openhab2/backups, which can then be restored using:

sudo openhab-cli restore /var/lib/openhab2/backups/

This backs up both text config from /etc/openhab and PaperUI config from /var/lib/openhab/


Thanks a lot for your immediate responses !
This is what I was looking for.

Since I’m on the latest OH version, I will try “sudo openhab-cli backup” once I finished my current step.

Hi all,

I’m not very familiar to Linux and have various problems to fully understand the Amanda setup therefore I’m looking for a more simple option to manually generate a FULL system backup

Is this command

sudo openhab-cli backup

generating a FULL backup of the entire system incl. all things, items, sitemaps, rules, bindings, and personal settings? can it be be used to restore openHAB on an all new openhabian installation on a new SD card?

If I follow the instructions written in the OH documentation a zip file is generated containing a ‘config’ and a ‘userdata’ folder. is this enough restoring my system on a new openhabian installation?

Up to now I was using:

# backup current installation with settings
TIMESTAMP=`date +%Y%m%d_%H%M%S`;
mkdir  ~/openhab2-backup-$TIMESTAMP
cp -arv /etc/openhab2 ~/openhab2-backup-$TIMESTAMP/conf
cp -arv /var/lib/openhab2 ~/openhab2-backup-$TIMESTAMP/userdata

# restart openhab instance
sudo systemctl start openhab2.service

I’m still not sure if this is enough for a full system restore in case of SD card crash. Maybe you can help me a little understanding what I need to do for getting a working backup solution.

Is there any alternative way to simply clone the entire SD card?

Thanks for your help,

all things, items, sitemaps, rules, bindings, and personal settings

The backup command for openhab will backup all these things EXCEPT manual .jar files that you’ve added yourself (if any). You’d simply need to add these back in afterwards. You may also need to add the openHAB user to the dialout and tty groups if you did this previously.

It won’t backup anything else related to Linux.

sudo openhab-cli restore <filename> can restore that file on a new system as long as it has openHAB (and Java 8) installed.

But I wouldn’t take my word for it. Generate a backup zipfile, get a new SD card and try it, that way if the restore isn’t as sucessful as you’d like, we can help with that. :slight_smile:

Hi Benjy,

Thanks for your reply. I’ll get a new SD card and give it a try within the next days.
I know the Win32 Disk Imager as a clone tool but I’m confused since there are 2 partitions on my openhabian SD card. for that reason I was asking if there is a way to clone the entire SD card including all partitions.

There is a way to clone the whole card with all partitions via linux dd command.
I use it from time to time to have an SD card backup in case the card fails.

sudo dd if=/dev/mmcblk0 of=/media/hd1/image_sd_2018_01_08.img

Backup to image file: (mmcblk0 is the whole SD-card, with both Partitions mmcblk0p1+mmcblk0p2); this results in an image file that has the size of the card.
I have an external HDD mounted at /media/hd1.
This takes 1…1.5h for a 16GB SD card on a RPI3.

I’m pretty sure setting bs to 1M would accelerate the process

sudo dd if=/dev/mmcblk0 of=/media/hd1/image_sd_2018_01_08.img bs=1M

Udo, thanks for the hint, I will try it!

Thanks for your suggestions…

unfortunately I cannot manage to get it work.
I’m using a MacBook Pro. Once I type your suggested command

 sudo dd if=/dev/mmcblk0 of=~/Desktop/BBOxxx.img bs=1m

into I get the response:

dd: /dev/mmcblk0: No such file or directory


diskutil list

I can see that this sample SD Card is described as

/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *15.9 GB    disk2
   1:                  Apple_HFS BBO                     15.9 GB    disk2s1

If I change the command to:

sudo dd if=/dev/disk2 of=~/Desktop/BBOxx.img bs=1m

the file BBOxx.img is generated but whatever content I put onto the SD card the feedback looks always like this

dd: /dev/disk2: Input/output error
2052+0 records in
2052+0 records out
2151677952 bytes transferred in 111.981351 secs (19214610 bytes/sec)

If I try to copy the SD card with the openhabian installation which has 2 partition I can also see

dd: /dev/disk2: Input/output error

Do you have any idea what’s wrong?

Thanks again…

Hi again…

after several hours of trial and error I finally found a way to generate a working clone of the entire openhabian SD card inclusive all partitions and so on.

I mounted an hdd to my Raspberry and entered the following command:

sudo dd if=/dev/mmcblk0 of=/media/usb-backup/openhab_clon_2018_XX_XX.img bs=1M

It took approx. 1 hour but in the end I got a working clone on my hdd. Since the clone is of exact the same size the the SD card I used Pishrink to shrink the size of the clone image.

Hopefully this helps other openhabian users who want to generate an exact clone of their SD card for backup reasons.


I used this approach successfully to backup and restore. My only concern is Grafana and InfluxDB. Both of them are not included with “sudo openhab-cli backup”, right?

That’s correct, unfortunately the scripts distributed with openHAB will only look at the openHAB side. You’ll need to backup data attached to other services along side it.

I’m using raspiBackup for a long time, backs up everything (either via dd, tar, rsync or whatever …) You may backup to any media, sd, usb, nas, …
And the most important thing: restore works too :+1:


@aksnet, thanks for your scripts, very interesting. Just one question : why didn’t you consider using amanda as a basis for your backups?
I did set Amanda up, have it running and yes, what I see is that it is not backing up influxdb & grafana stuff but I was thinking that might be possible to add it to the amanda config file and yet you did choose another way, so I thought I’d ask the question :slight_smile: