Recommended way to backup/restore OH2 configurations and things?

@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:

Thanks,

@thefathefa, When i started to work on the script i guess amanda was not yet implemented or only in some beta versions already.
So i have never looked into it to be honest.
I just opened the 2 main Amanda pages and will see if a switch might be an option.

BR
Andreas

Sure it is. Just add the directories you want to backup to /etc/amanda/<yourconfig>/disklist .

@mstormi, would it be possible to stop the grafana service as well before the backup via amanda? Or do i have to do this manually before starting amanda?

Andreas

You can write a simple script to do this and run Amanda afterwards.
Then again I don’t think it’s required to stop Grafana, it’s more of a myth. Try to backup a runnning Grafana and to then restore it if to prove this if you feel uncomfortable about this.

I’m using a custom script for backing up openHAB, Grafana and InfluxDB on my Ubuntu machine. The 3 zip files get afterward synced to Google Drive (Grive2). The script get executed automatically with a dedicated Cron job.

#!/usr/bin/env bash

#####################################################
# Date with Timestamp
#####################################################
echo "+-+-+-+-+-+-+ Set Timestamp  +-+-+-+-+-+-+-+-+"
DATE=`date +%Y_%m_%d-%H_%M_%S`

#####################################################
# Backup openHAB
#####################################################
echo "+-+-+-+-+-+-+ openHAB Backup +-+-+-+-+-+-+-+-+"
sudo openhab-cli backup

#####################################################
# Backup Grafana
#####################################################
echo "+-+-+-+-+-+-+ Grafana Backup +-+-+-+-+-+-+-+-+"
#Stop Grafana service
sudo systemctl stop grafana-server
#Backing up ini file
mkdir /var/lib/openhab2/backups/tmp_grafana/
mkdir /var/lib/openhab2/backups/tmp_grafana/$DATE/
sudo cp -arv /etc/grafana/grafana.ini /var/lib/openhab2/backups/tmp_grafana/$DATE/grafana.ini
#Backing up a database
sudo cp -arv /var/lib/grafana/grafana.db /var/lib/openhab2/backups/tmp_grafana/$DATE/grafana.db
#Start Grafana service
sudo systemctl start grafana-server
#Create Zip File
cd /var/lib/openhab2/backups/tmp_grafana/$DATE
sudo zip -r /var/lib/openhab2/backups/grafana-backup-$DATE.zip ./*
#delete tmp folder
rm -rf /var/lib/openhab2/backups/tmp_grafana



#####################################################
# Backup Influxdb
#####################################################
echo "+-+-+-+-+-+-+ Influxdb Backup +-+-+-+-+-+-+-+"

#Backing up the metastore
influxd backup /var/lib/openhab2/backups/tmp_influxdb/$DATE/
#Backing up a database
influxd backup -database openhab_db /var/lib/openhab2/backups/tmp_influxdb/$DATE/
#Backing up conf file
cp -arv /etc/influxdb/influxdb.conf /var/lib/openhab2/backups/tmp_influxdb/$DATE/influxdb.conf
#Create Zip File
cd /var/lib/openhab2/backups/tmp_influxdb/$DATE
zip -r /var/lib/openhab2/backups/influx-backup-$DATE.zip ./*
#delete tmp folder
rm -rf /var/lib/openhab2/backups/tmp_influxdb


############################################
# Sync to Google Drive
############################################
sudo cp -vnpr "/var/lib/openhab2/backups/." "/home/smarty/grive/@Backups/openHAB smarty-nuc"
cd "/home/smarty/grive/"
grive -s "@Backups/openHAB smarty-nuc"

# vim: filetype=sh
5 Likes

Thanks Markus, I think I see it for Grafana, yes, but what about influxdb? If the only way to do backhup is to use influxdb backup then, I’m not sure how Amanda would work?

Well I don’t know where influxdb is placing its data but as can be seen in the script above you can actually run an influx command to create a backup. Place these into a directory and add that to Amanda disklist.

Usually its /var/lib/influxdb.

@mstormi, thanks for this.
I’m trying to have all the backup related stuff in one place and was looking at how to configure a script to be executed before Amanda performs the backup but before I spend time on this I was wondering if any of you are backing up influxdb by just backing up the folder mentioned by @rlkoshak Rich (Usually its /var/lib/influxdb). Something tells me it is probably not a good idea, but I thought I’d check.

As I could not find the public location of the source, I am asking here. My
openhab-cli backup (or /usr/share/openhab2/runtime/bin/backup) does actually not produce a file , I think due to a bug towards the end of the file.

a) is this known?
b) where is the right place to provide a pull req ?

@Benjy, any ideas about a potentail bug in the backup scripts?

I think I see the same thing, but only when naming a file right?

If you found the error already the place for a PR is https://github.com/openhab/openhab-linuxpkg and it would be very much appreciated :smiley:

Sorry @rlkoshak and @alias that was completely the wrong link… Not sure how I screwed that one up… The following is a direct path to the github file…

Hi @alias, I found the bug and submitted a PR, could you confirm that this fixes the issue?

Guys,

I need to move from one VM to another.
The original VM is Debian 32 bit with latest openHABian (OH2), and I would like to move to Debian 64 bit (as Grafana 32 bit is not supported).

Do I need to install java 32 bit? is sudo openhab-cli backup/restore the right way, considering I’ve also a lot of zwave devices (xml files to be moved as well)?

Any suggestion will be appreciated

Thanks
Andrea

Backup and restore scripts will grab everything.

Though if the new VM will be running the same OH version, you can just copy over /etc/openhab2 and /var/lib/openhab2 to the new VM and you will have everything.

Uhh, now while not completely wrong, that’s a somewhat dangerous statement.
A typical openHABian setup consists of more than just plain OH and it’s config files: mosquitto, NGINX, …

1 Like

True, I was only addressing the OH part since that is what Andrea was asking about.

As far as I know, there is no automated or even complete guide for dealing with migrating everything that openHABian can install to a new machine.

1 Like

and what about Oracle Java? still makes sense to use the 32 bit or can I install the 64 bit version?