How often to update ubuntu with openhab

Upgrading the distro can be a pain and this is true for all Linux distros. As with the updates, the longer you wait the bigger the changes are between versions. For a recent example, I just did an in place upgrade most of my RPis to Raspbian buster. They are mostly running the same stuff with minor differences, all are headless.

  • 1 I didn’t upgrade because it’s remote and will require a 100 mile drive to fix it if something goes wrong, that one will stay on stretch until I make the drive for other reasons.

  • 2 completed the upgrade without any problems and are now happily running buster

  • 2 failed in the middle of the upgrade and I had to rebuild the SD cards from scratch, which wasn’t that big of a deal because all the set is scripted. I didn’t go this route in the first place because I was too lazy to go and physically remove the SD cards and burn the new OS onto them in the first place.

As you can see, it’s not all that easy of a process.

So you will probably want to make sure you have everything backed up and start fresh with the new distro, installing the OS and then reinstalling the software and restoring the backups of your data. You have a couple years to think about it and maybe start setting up your backups and recovery needed to accomplish this.

I´m not afraid of the backup… Its mainly the time spending, and specially if things goes wrong. Going back to a backup doesnt fix the upgrade process :smiley:

There are two different types of backups. Backing up the whole machine which is what you are talking about and what software like Amanda does, and backing up the data (config files, database entries, anything you’ve or some process has edited or created on the machine) independently from the software. It’s the latter that is required to upgrade the operating system to a new distro safely.

You could try to go from 16.4 to 16.10 to 17.4 to 17.10 to 18.4 to 18.10 to 19.4 to 19.10 to 20.4 (you might only need to go from 16.4 to 18.4 to 20.4, but that’s still a pretty big jump) using sudo do-release-upgrade which should leave all your software and data in place. But the likelihood of something breaking along the way is pretty high, and if it does break, you will have to do the data backup and restore process anyway. Also, keep in mind that each of these release upgrades can take hours to complete.

I actually use both options (not using Amanda though).

  1. Once in a while I make a image copy of the SSD.
  2. t least once a Week I make a copy of all openhab configuration files (anything inside the openhab folder, such as items, sitemaps, rules etc).

The second options will leave out some work for me to do, if/when starting all over on a openhab installation. I will need to install all bindings again, and setup several things, specially since i use manual installed bindings. So I also keep a copy of all the manual installed bindings I´m using. This is/can be quite time spending option.

What I still need to do, is to create a backup of my influxdb database. There is a very easy solution to just run a bash/command once in a while, which do the backup, (its a simple command line to start the backup, and the procedure for restoring is just as simple as well).

But - No matter which option I use, if the kernel/Linux upgrade fail, which I suppose could show either from start or maybe even after installing openhab again, it will mean it takes alot of extra time, and I´ll need to go back again. (this is where the image copy come in hand, except it´s leave me at status quo).

For 2, use sudo openhab-cli backup which will also back up everything needed from /var/lib/openhab2. If all you backup is /etc/openhab2, even if you only use text based configs, you are missing a whole lot of data.

I think this would all be covered by openhab-cli backup. If not, you may need to also include the addons folder in your backups.

But of course this also assumes you are not using any database like InfluxDB, Grafana, Mosquitto, etc. If you are, each of these needs to be backed up individually as well and are not covered by openhab-cli backup.

This is the script I use which I’ve placed in /etc/cron.daily.

#!/bin/bash

echo "Backing up the database"

docker exec -it influxdb influxd backup -portable -database openhab_db -host localhost:8088 /var/lib/influxdb/backups

echo "Packaging up the files"
file=/tmp/influxdb-$(date +%Y-%m-%d_%H%M).tar
echo $file
tar cvf $file /opt/influxdb/data/backups
rm -rf /opt/influxdb/data/backups/*

echo "Copying backup to fafnir"
sudo -u rich scp $file fafnir:/srv/dev-disk-by-label-backups/working-backup

This runs every day and I don’t suppress the output so I get an email when it completes so I know it is backed up every day. Obviously, you would have to customize this as I run InfluxDB in Docker and copy the backup to my NAS so the backup is off the VM.

I have a similar backup script for all of my databases (different services I run use different databases, currently I’m running PostgreSQL, MongoDB, and InfluxDB).

I manually clean up the backups periodically.

I’m not saying you shouldn’t do whole file system backups. I’m just pointing out that that sort of backup is not going to be all that helpful in an upgrade of the Linux distro scenario.

I’ve personally stopped doing whole system backups. I’ve too many machines and it doesn’t take me significantly longer to just rebuild it from scratch than it would to just restore it from a backup. But it takes a lot of discipline to not make any changes to a system without doing it through Ansible.

I know… Thats why I said, is will leave out some work for me to do, (when restoring).
I never actually thought about the openhab-cli backup option. I suspect this require some path pointing to where to backup. For this I need some external path, (my windows server or NAS), which I have yet to figure how to do.

Grafana is installed on my windows server, so I´ve got that one covered.
Influxdb backup is done manually once in a while, and then I manually copy the files. Not a good solution, but better than none. You´re script for backing up Influxdb sure looks interesting.

My point is, if the linux distro fails, it would probably fail as well, after restoring a backup… In this situation the backup is good to have to get back to a working state. But it wont help upgrading the distro :slight_smile:

Same here, Thats why I only once in a while do image backup. Last time I started all over, it took me some hours during a weekend to get it up running again from my manual backup… Ofcouse this is still way too long, if the house is depending on openhab running. If I can get down to just a coupple of hours, it would be acceptable. I believe I can… For each time, I figure how to optimize the procedure :slight_smile:

EDIT -
The sudo openhab-cli backup option… I suppose it´s using a script named “backup”. I just search through the drive for this script, and I ended up with a few of them, and they´re not alike.
Which one to use?

Second - Using sudo openhab-cli backup, where does it place the backup files?
And last - Using sudo openhab-cli backup, how to restore?

I have not looked at any docs about this, as I wasn´t aware of this before you´d mention it. I know there is a backup option inside openhabian-config. I dont know if it´s the same.

There is a default but I’m sure you can provide a path too. If not you can have a two step script, one to run the backup and another to move it where you want it. That is how all my database backups work.

Figure out how to automate it and it will be faster, less error prone, and repeatable. I advocate for Ansible but there are lots of other options.

I think it’s all just built into the cli script but I don’t know. I run in Docker and openhab-cli isn’t available. I’d expect it to go somewhere in /var/lib/openhab2. But I don’t really know.

Yep, it’s in the docs. openHAB on Linux | openHAB

I think that’s just the whole file system backup using Amanda.

Just tried the openhab-cli backup… It was very fast.
As far as I can see, it backup conf and userdata, which is very good.

[15:32:59] openhabian@openHABianPi:~$ sudo openhab-cli backup
[sudo] password for openhabian:


#########################################
       openHAB 2.x.x backup script
#########################################

Using '/etc/openhab2' as conf folder...
Using '/var/lib/openhab2' as userdata folder...
Using '/usr/share/openhab2/runtime' as runtime folder...
Using '/var/lib/openhab2/backups' as backup folder...
Writing to '/var/lib/openhab2/backups/openhab2-backup-19_08_11-15_33_06.zip'...
Making Temporary Directory if it is not already there
Using /tmp/openhab2/backup as TempDir
Copying configuration to temporary folder...
Removing unnecessary files...
Backup Directory is inside userdata, not including in this backup!
Zipping folder...
Removing temporary files...
Success! Backup made in /var/lib/openhab2/backups/openhab2-backup-19_08_11-15_33_06.zip

[15:33:19] openhabian@openHABianPi:~$

This could come in hand for some automation.

I have just examin the zip file as well.
I have to test restoring though, as I have no idea, what exactly is missing, except for the manually installed bindings, (obviously) and then installing bindings from PaperUI as well. It seems like the backup saves the configuration from those bindings installed from PaperUI, which require a config file.

Bindings installed from PaperUI are included. Well I should say that the fact of their installation is included. When you restore, the script will “clear the cache”, restore the configurations that are in userdata, and when OH comes back up it will reinstall those bindings. There is an option you can supply to the script that will backup the PaperUI installed bindings as well.

The whole point of openhab-cli backup/restore is that there should be no work required after the restore. I don’t know if the backup also includes the addons folder, it kind of looks like it might not given the logs above.

According to the help file (option) this is not obvious or clear in anyway, in my opinion.
Doc´s arent clear as well.

[15:35:27] openhabian@openHABianPi:~$ sudo openhab-cli backup -h
[sudo] password for openhabian:


#########################################
       openHAB 2.x.x backup script
#########################################

Usage: backup [--full] [filename]

  e.g. ./backup                     << Makes a file with a timed filename
       ./backup myBackup.zip        << Makes a file called myBackup.zip
       ./backup --full              << Makes a full backup file with a timed filename
       ./backup --full myBackup.zip << Makes a full backup file called myBackup.zip

Use this script to backup your openHAB configuration, you can use the 'restore' script
from any machine to transfer your configuration across to another instance.

A full backup includes the tmp and cache directories that are normally excluded.

Set /var/lib/openhab2/backups to change the default backup directory.
Set  to change the default backup temporary directory.
[18:36:22] openhabian@openHABianPi:~$

The manual installed bindings are not part of the zip archive. So it doesnt backup those.

You know where the link is, at the bottom of the page. We would welcome any suggestions and additions.

I’m not completely sure where the script actually live, I think maybe GitHub - openhab/openhab-distro: The binary distribution of openHAB. An issue filed there would be welcome as well.

I know. But it´s hard to provide info or suggestions (file an issue), when I dont know what it´s suppose to do or whats missing :wink:

It’s actually exceptionally easy to open an issue with that. Filing an issue is just about as good as filing a PR. You don’t have to have the solution to open an issue. Just describe what you don’t understand and that needs to be clarified.

I believe someone already filed an issue regarding the backup and restoring the bindings. https://github.com/openhab/openhab-distro/issues/671

I still miss some more info about the actual backup script. So I´ll probably add another issue.

1 Like