Recommended way to backup/restore OH2 configurations and things?

Yeah - In the name of community publish your recover script here :slight_smile:

Hi,

I have two questions regarding the OpenHab2 backup script
/usr/share/openhab2/runtime/bin/backup

(I hope asking this in this thread is correct, otherwise pelase tell me and I will open a new one).

Q1: the copy command for the /userdata folder uses the “-R” option, as a result of this all copied files will have a timestamp of the copy operation. This way you cannot see the date&time of the underlying original file and therefore it is harder to see which files might have changed in the configuration compared to the backup.

Why wasn’t the “-a” copy option used?

find “${OPENHAB_USERDATA:?}/”* -prune -not -path “${OPENHAB_BACKUPS:?}” | xargs -I % cp -R % “$TempDir/userdata”

Q2: is it necessary to stop the openhab2.service before executing the backup script?

1 Like

No.

Good to know, thank you!

The script is very good and work fine.
Can you provide the script for the restore?
Thank you.

I use the following shell script to backup to an network share and it works like a charme:

#!/bin/bash
#Mount network share
mount -t cifs -o user=USERNAME,password=PASSWORD,domain=DOMAIN,rw,file_mode=0777,dir_mode=0777 //192.168.1.1/Backup /mnt/backup
#Variables
BACKUP_PATH="/mnt/backup/Openhab/onflow"
BACKUP_COUNT="15"
BACKUP_NAME="Backup"
#Create Backup
openhab-cli backup ${BACKUP_PATH}/${BACKUP_NAME}-$(date +%Y%m%d).zip
#Delete old backup files
pushd ${BACKUP_PATH}; ls -tr ${BACKUP_PATH}/${BACKUP_NAME}* | head -n -${BACKUP_COUNT} | xargs rm; popd
#unmount
umount /mnt/backup
2 Likes

Can you post the restore script please?

-deleted-

Hey! some time ago I made an update to v3 and for my own reason rolled back to v2.
everything works well except for the backup script.
openhab-cli now looks for /usr/share/openhab instead of /usr/share/openhab2
where can i fix this?
Im want to go to v3, but a little later

/usr/bin/openhab-cli: 88: /usr/bin/openhab-cli: /usr/share/openhab/runtime/bin/backup: not found

that is nothing to fix… It is intended to have different directories for OH2 vs. OH3.
Depending on the bindings that you use there are incompatibilities / breaking changes between the versions. So I think things may get worse in case you restore OH3 configuration into OH2.

In case you want to go that route have a look into openhab-cli resp. backup resp. restore script which are called from openhab-cli. You can find the paths that are used inside of the scripts.

i’ve developed this script to backup openhab3, grafana and influxdb: https://github.com/oliranks/openHAB3-full_backup_and_restore
let me know how it works for you

To reiterate statements made here and on various threads, the recommended way to backup (and restore, eventually) an OH config is the openhab-cli script which is part of the UNIX distribution package(s).
To backup anything beyond pure OH config such as homegrown scripts, mosquitto setup etc the recommendation is to install openHABian and use the Amanda backup system it comes with.

Remember anyone will benefit from going with a common solution.