Hi. I’m in a bit of a pickle since last time I tried to upgrade openHab. The OS doesn’t boot anymore, not even to the point where it has a network connection. (The recovery method of placing the backup SD card in did also not work, unfortunately)
My plan is to simply start from scratch with a fresh openhabian install.
Since I cannot log in and create a backup, is there any way I can create the backup from a mounted file system?
And can the same be done with influxDB? (Of course not a question for OH developers, but maybe someone here has tried it)
As long as the SD card is still readable it’s not too hard to get the data.
Either use an USB SD-Card Reader with the Raspberry Pi or use a virtual machine. Both ways are more or less the same:
boot to GNU/Linux shell
create a directory or use an existing empty one (e.g. /mnt/ should be empty)
mount the file system (sudo mount /dev/<name-of-sd-card's-2nd-partition> /mnt)
navigate to the data in question
copy data to wherever you want it.
To use openhab-cli backup, you will have to use chroot to (temporally) make the old file system the root file system. Be aware that this can be a bit tricky, as a one-time-job it’s easier to manually copy the files.
EDIT: everything between < and > won’t be displayed if not marked as code.
Reminder to myself: Always take a look back (i.e. is the Posting displayed the way it should be…)
Great to hear that it’s simple! My only problem is that I don’t know exactly which files that need to be copied.
In the documentation (openHAB on Linux | openHAB) it says a script is used. I guess if I get a hold of that script I could either run it from my laptop och at least look at it to find the list of files.
Where exactly would that script be located on an openhabian install?
I finally got some time to fix this, and I’d like to share the details on how I solved it. Turns out that I could run the backup script from my laptop, just making sure to set environment variables correctly! Also, moving the influxdb persistence data was as simple as replacing the database folder.
My laptop is running Manjaro linux, but almost any linux distribution should work.
Create image from SD-card using dd
Mount rootfs partition of image using:
sudo losetup --partscan --find --show openhabian.img
mount /dev/loop0p2 /mnt/img
Create a shell script with the following content
export OPENHAB_CONF="/mnt/img/etc/openhab"
export OPENHAB_USERDATA="/mnt/img/var/lib/openhab"
export OPENHAB_BACKUPS="<arbitrary path where backup zip file should end up>"
export OPENHAB_RUNTIME="/mnt/img/usr/share/openhab/runtime"
/mnt/img/usr/share/openhab/runtime/bin/backup
Run shell script with sudo
Put a fresh install of openhabian on the SD-card
Put the SD-card in the rpi, start it up and let it install.
Use scp to copy the zip file to the rpi
Restore with the openhab-cli command
Install influxdb and grafana using the openhabian-config tool
Shutdown the rpi and mount the SD-card with card reader to your computer
Rename the folder /var/lib/influxdb on the SD-card to influxdb_bkp as a safety measure
Navigate to the SD-card /var/lib/ folder and copy over the mounted image folder in its place (-p is needed to keep permissions)
sudo cp -pr /mnt/img/var/lib/influxdb .
Done. When you start the rpi next time, all your settings, addons and influxdb persistence data should be in place.