Backup & Restore openHab 2.x on Synology

In order to upgrade from openHab 2.4 to 2.5, I had to backup the configuration of openHab, uninstall the v2.4, install the v2.5 and restore the configuration.

Click to Read More

If you installed OpenHab as explained here, you can copy all the folders under /openHAB in the share /SmartHome of your Synology.

OpenHAB 2.x currently has two different ways of setting up things:

  • Either through textual configuration (in /SmartHome/openHAB/conf folder) or
  • through the user interface which saves to a “jsonDB” database (in /SmartHome/openHAB/userdata folder).

Both the textual configuration files and the database folders must be backuped (See here).

OpenHab 2.x comes now with scripts to backup and restore its configuration and database. They are availabe in the folder /runtime/bin. You can access them via a SSH Console on your Synology, under /var/packages/openHAB/target/runtime/bin/ (equivalent to /volume1/@appstore/openHAB/runtime/bin)

These scripts take care of backuping not only the files that you have manually edited in the folder /conf (items, things, scripts, …), but also everything configured via the paperUI or HABPanel and stored in the folder /userdata (habmin, jsondb,…)

Attention, these scripts do not take care of:

  • backuping the jar files that you have installed manually. Ex.: in /addons
  • backuping the DB you would be using for, e.g., persistence, …
  • adding the openHAB user (‘openhab’) to the dialout and tty groups if you did this previously

First, prepare your Synology

  1. Open a SSH console on your Synology as root (See here)
  2. Install the Synology Gear’s tools, required to have the command pgrep used by the restore script of openHab, typing the command :
    synogear install
  3. Modify the script ‘/runtime/bin/restore’ to replace unzip (not available anymore on Synology) by 7zip. Concretelly, replace:

command -v unzip >/dev/null 2>&1 || {
echo "'unzip' program was not found, please install it first." >&2
exit 1
}

with

command -v 7z >/dev/null 2>&1 || {
echo "'7z' program was not found, please install it first." >&2
exit 1
}

and 

unzip -oq "$InputFile" -d "$TempDir" || {
echo "Unable to unzip $InputFile, Aborting..." >&2
exit 1
}

with

7z x -y -o"$TempDir" "$InputFile" > /dev/null || {
echo "Unable to unzip $InputFile, Aborting..." >&2
exit 1
}

Next, use the following commands to backup your configurations:

  1. sudo -i
  2. cd /var/packages/openHAB/target
  3. synoservice –stop pkgctl-openHAB
  4. ./runtime/bin/backup
  5. synoservice –start pkgctl-openHAB

You should see something like this as output:

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

Using '/volume1/@appstore/openHAB/conf' as conf folder...
Using '/volume1/@appstore/openHAB/userdata' as userdata folder...
Using '/volume1/@appstore/openHAB/runtime' as runtime folder...
Using '/volume1/@appstore/openHAB/backups' as backup folder...
Writing to '/volume1/@appstore/openHAB/backups/openhab2-backup-19_12_25-12_27_33.zip'...
Making Temporary Directory if it is not already there
Using /tmp/openhab2/backup as TempDir
Copying configuration to temporary folder...
Removing unnecessary files...
Zipping folder...
Removing temporary files...
Success! Backup made in /volume1/@appstore/openHAB/backups/openhab2-backup-19_12_25-12_27_33.zip

Before uninstalling openHab, if you intend to install a new version, copy the backup into a safe folder, like the tmp folder :

cp /volume1/@appstore/openHAB/backups/openhab2-backup-19_12_25-12_27_33.zip /tmp/openhab2-backup.zip

Finally, use the following commands to restore your configurations:

  1. sudo -i
  2. cd /var/packages/openHAB/target
  3. synoservice –stop pkgctl-openHAB
  4. ./runtime/bin/restore /tmp/openhab2-backup.zip
  5. synoservice –start pkgctl-openHAB

You should see an output like this:

##########################################
openHAB 2.x.x restore script
##########################################

Using '/volume1/@appstore/openHAB/conf' as conf folder...
Using '/volume1/@appstore/openHAB/userdata' as userdata folder...
Making Temporary Directory
Extracting zip file to temporary folder.

Backup Information:
-------------------
Backup Version | 2.5.0 (You are on 2.4.0)
Backup Timestamp | 19_12_25-12_27_33
Config belongs to user | openhab
from group | users

Your current configuration will become owned by openhab:users.

Any existing files with the same name will be replaced.
Any file without a replacement will be deleted.

Okay to Continue? [y/N]: y
Moving system files in userdata to temporary folder
Deleting old userdata folder...
Restoring system files in userdata...
Deleting old conf folder...
Restoring openHAB with backup configuration...
Deleting temporary files...
Backup successfully restored!

 

If opening openHab weg page immediatly, you will see that it’s restoring the UI:

Please stand by while UIs are being installed. This can take several minutes.

Once done, you will have access to your PaperUI, BasicUI, HabPanel, etc…

Loading


Categories:

,

Tags:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *