Recommended way to backup/restore OH2 configurations and things?

Thanks, Rich.

Can i still install whole openhab2 into one single folder like the manual install on OH1?

So i can only copy the whole folder to my backup-drive and all will be good. Now with OH2 storing the installation into many folders in different directorys, i have to backup many folders manually.

But it think the apt-get update/upgrade will only work, if i use OH2 with the given installation folders on many different places? If i use OH1 all-in-one folder i will have to update OH2 manually by simply copy the new files to the install-place and overwrite the old files?

That shouldn’t be a problem. That’s how every Linux software works. Backup is as simple as this.
I’d recommend the package repository based installation in general as a few things are managed for you, makes it easier for the end user.

It is a really funny thread, can someone not create an add-ons which create a portable zip file with all stuff hidden from user?

A download button, and upload button is more than enough (copying files in background like here http://docs.openhab.org/installation/linux.html#backup-and-restore)

regards

5 Likes

I made a backup (most of my config was done through the paper ui) as per http://docs.openhab.org/installation/linux.html#backup-and-restore and the resulting files were over 90MB compressed. lulz – that’s just embarrassing. I certainly hope there’s a better solution on the way. I strongly believe having the UIs store data in something human-editable would be a big improvement, for configuration purposes. These binary databases can’t be diffed, can’t be meaningfully stashed into version control, can’t be manipulated outside the UI… and it’s the recommended method for new users. Having the system r/w text files, or json files, or xml files, or… really just about anything else seems like it’d be a big improvement. I worry that OH2 is overengineered at every turn, like many enterprise java apps these days. Forcing a one-time upgrade and edit of OH1 text files into OH2 files (probably via some kind of tool, if needed) seems easy enough, but I’m sure this was debated already long before I started trying OH2. Oh well.

But seriously – 100MB of “configuration data” in a backup? It seems like the vast majority is in the ‘cache’ dir. Can that be omitted? What about ‘tmp’? Maybe update the backup script? Or will things go poorly if ‘cache’ isn’t restored properly, for example?

That has already been done month ago:

You may safely delete it.

All your installed bindings are stored in tmp. That directory will be created again after upgrading, so can be deleted, too.

I might need to add that I’ve written down the backup and restore steps months ago to have a “minimal set” of commands to go with. A discussion to improve this set was already under way here but lost traction: https://github.com/openhab/openhab-docs/issues/176#issuecomment-272684145

If you agree with the mentioned two additional lines, I can add these to the documentation asap.

that would be nice, something in a gui that backed up the openhab2 and zwave, so if failed, could just quickly reinstall and then restore

Has been finished a while ago, look for “Amanda”

https://community.openhab.org/t/openhabian-hassle-free-openhab-setup/13379/999

this is a gui in openhabian? I must of missed it, will take a look

ok, found it in the openhabian-config, installed it, set the location to /mnt/usb

see new dirs created /mnt/usb/backup/slots/slot1 ect…

is there a web link to this I need to use to access the gui?

Amanda is CLI only. There’s a brief usage guide in docs/openhabian-amanda.md.

thanks, I will take a look

but what I was saying would be nice is just a simple web gui that easily backed up to a file and restored from same file the control and the zwave, ect… :0)

Hi, i just found this thread and wanted to share my backup solution.
I have an USB Stick attached to my PI and run this script every day.
It covers:

  • OpenHab
  • Influxdb
  • Grafana
#!/bin/bash
# stop openhab instance (here: systemd service)
echo "+-+-+-+-+-+-+ Stopping service...+-+-+-+-+-+-+-+"
sudo systemctl stop openhab2.service

# backup current installation with settings
echo "+-+-+-+-+-+-+ timestamp and folder setup +-+-+-+-+-+-+-+-+";
TIMESTAMP="`date +%Y%m%d_%H%M%S`";
sudo mkdir  "/media/usb/openhab2-backup-$TIMESTAMP";
sudo mkdir  "/media/usb/openhab2-backup-$TIMESTAMP/influxdb";
sudo mkdir  "/media/usb/openhab2-backup-$TIMESTAMP/grafana";
#bakdir="$HOME/openhab2-backup/$TIMESTAMP";
#mkdir -p "${bakdir}"

echo "+-+-+-+-+-+-+ OH backup +-+-+-+-+-+-+-+-+-+-+"
#cp -arv /etc/openhab2 "${bakdir}/conf"
#cp -arv /var/lib/openhab2 "${bakdir}/userdata"
#find /var/lib/openhab2 \( -path /var/lib/openhab2/tmp -prune -o -path /var/lib/openhab2/cache -prune \) -o -name '*' -exec cp -arv {} "${bakdir}/userdata"  \;
sudo cp -arv "/etc/openhab2" "/media/usb/openhab2-backup-$TIMESTAMP/conf";
sudo cp -arv "/var/lib/openhab2" "/media/usb/openhab2-backup-$TIMESTAMP/userdata";

echo "+-+-+-+-+-+-+ Clear cache and tmp folder +-+-+-+-+-+-+-+-+"
sudo rm -rf "/media/usb/openhab2-backup-$TIMESTAMP/userdata/cache"
sudo rm -rf "/media/usb/openhab2-backup-$TIMESTAMP/userdata/tmp"

echo "+-+-+-+-+-+-+ Grafana backup +-+-+-+-+-+-+-+-+"
sudo systemctl stop grafana-server
sudo cp -arv "/etc/grafana/grafana.ini" "/media/usb/openhab2-backup-$TIMESTAMP/grafana/grafana.ini";
sudo cp -arv "/var/lib/grafana/grafana.db" "/media/usb/openhab2-backup-$TIMESTAMP/grafana/grafana.db";

echo "+-+-+-+-+-+-+ Influxdb backup +-+-+-+-+-+-+-+"
sudo cp -arv "/etc/influxdb/influxdb.conf" "/media/usb/openhab2-backup-$TIMESTAMP/influxdb/influxdb.conf"
sudo influxd backup "/media/usb/openhab2-backup-$TIMESTAMP/influxdb/metastore/"
sudo influxd backup -database openhab_db "/media/usb/openhab2-backup-$TIMESTAMP/influxdb/db/"

# restart openhab instance
echo "+-+-+-+-+-+-+ Starting service...+-+-+-+-+-+-+-+-+"
sudo systemctl start openhab2.service
sudo systemctl start grafana-server

# Folder size
# sudo ls -1d */ | sudo xargs -I{} du {} -sh && sudo du -sh
sudo df -h /media/usb/; sudo du -sh -- /media/usb/*

1 Like

Keep an eye on that thumb drive. While not as bad as SD cards, thumb drives will wear it with writes. And when it starts to go bad it isn’t always obvious.

For these reasons I do not recommend thumb drives as a reliable backup solution. But you’re scrips will work with any storage type so should work just fine with USB hdd or sdd.

1 Like

Hi Rich,

you are absolute right, these tiny thumb drives are not a very good reliable backup medium, but they are not worse than the sd card :slight_smile:

So the usb stick has the advantage that i easily can exchange file between my 2 PIs running OH for testing.

As final Backup Medium i put the Backup files on my Synology NAS, but this is still yet all manual, so i need to find a way to save, lets say, always the last 2 backup files on the usb stick automatically to my syno nas. It is on my ToDo list :wink:

Very nice script, I like it.
If you want to save some time and work, take a look for a fully automated backup to any backup medium:

https://www.linux-tips-and-tricks.de/en/backup

Are your Pis not on the same network as your NAS? If they are you can just NFS/CIFS or whatever mount a backup folder in your Synology NAS to the Pis and copy straight to that and bypass the thumb drive.

My biggest concern with the thumb drive is not how quickly it wears out or that you are using it as the final destination for the backups but the fact that you won’t necessarily know that it has failed unless you are somehow validating the files you copied off of the drive with the source files every time (in which case that means you can see your Pis from you NAS and have no need for the thumb drive in the first place).

You can happily be making backups for months only to discover one day when you need to restore that your thumb drive failed and all of your backups are corrupted or stuck back at a distant point in time, or more likely a combination of the two. It isn’t always obvious when these drives fail. Just look around at some of the strange behaviors people have seen when their SD cards fail. I myself discovered my SD card failed only because logrotate stopped working. It would delete the old files and rotate them only to have the old files reappear the next day. You don’t always get errors or flashing red lights. Sometimes it acts like everything is working just fine but that file you thought you wrote just disappears without a warning and without a trace.

tl;dr - even using the thumb drive to copy the backups from one machine to another is a bad idea

Hi Rich,

my PIs and NAS share the same Network. I just had not the passion yet to learn how to map my NAS drive :). I guess Linux will not become my best friend, so every new thing i have to look it up how to do it and sometimes things are different by the distros.
But the Forum here already helped a lot and your thoughts made change my mind and i will see how to map the drive manually and perform backups on the NAS then.
I think MOUNT will be the one command i need to look closer at, cause my nas is not running 24/7 and will be WOLed whenever i need it i have to map and unmap the share for backups.

Thanks
Andi

Hi all, I wanted to direct people that were interested in a PR for openHAB that contains a backup and restore script for Linux and MacOS to be included in future versions of openHAB. It hasn’t been merged yet as it needs people to test it.

The scripts should work with the snapshot versions.

2 Likes