The update is broken on Windows since version 4.0.0 + Backup not created correctly during update on Windows

  • Platform information:
    • Hardware: Intel
    • OS: Windows Server 2022 / Windows 10
    • Java Runtime Environment: Azul 17
    • openHAB version: 4.0.3
  • Issue of the topic:

The update is broken on Windows since version 4.0.0
============================================

In update.ps1 you added a call to updatetool.jar and it doesn’t work.
Tested in different configurations (3.x.x to 4.x.x or 4.x.x to 4.x.x or production/clean/debug).
The try/catch block fires when the java -jar “$OHRuntime\bin\upgradetool.jar” is called.

Java home: c:\Program Files\Java\zulu-jdk-17.44.15-ca-jdk17.0.8-win_x64
openjdk version "17.0.8" 2023-07-18 LTS OpenJDK Runtime Environment Zulu17.44+15-CA (build 17.0.8+7-LTS) OpenJDK 64-Bit Server VM Zulu17.44+15-CA (build 17.0.8+7-LTS, mixed mode, sharing)

###########################

openHAB update script

###########################

Checking whether a service exists
Checking the specified openHAB directory
Using D:\servers\openhab\conf as conf folder
Using D:\servers\openhab\userdata as userdata folder
Using D:\servers\openhab\runtime as runtime folder
Using D:\servers\openhab\addons as addons folder
The current version is 3.4.5
Changing location to D:\servers\openhab
Creating temporary update directory C:\Users\OhUsr666\AppData\Local\Temp\openhab
Downloading the openHAB 4.0.1 distribution to C:\Users\OhUsr666\AppData\Local\Temp\openhab\openhab-4.0.1.zip
Downloaded 101593K of 101593K [100%]
Finished Download
Extracting the archive (C:\Users\OhUsr666\AppData\Local\Temp\openhab\openhab-4.0.1.zip) to C:\Users\OhUsr666\AppData\Local\Temp\openhab\update

##########################################################################################################################################

New update.ps1 was found - executing it instead (found in C:\Users\OhUsr666\AppData\Local\Temp\openhab\update\runtime\bin\update.ps1)

##########################################################################################################################################

###########################

openHAB update script

###########################

Checking whether a service exists
Checking the specified openHAB directory
Using D:\servers\openhab\conf as conf folder
Using D:\servers\openhab\userdata as userdata folder
Using D:\servers\openhab\runtime as runtime folder
Using D:\servers\openhab\addons as addons folder
The current version is 3.4.5
Changing location to D:\servers\openhab
Upgrading to version 4.0.1

Making a backup of your distribution to C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5
Creating backup directories in C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5
Copying directory conf, userdata and runtime to C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5\conf
Copying files from D:\servers\openhab to C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5\home

The script will attempt to update openHAB to version 4.0.1
Please read the following notes and warnings

Important notes for version [4.0.0] :
Warning: CORE: core.GenericEventTrigger and core.GenericEventCondition parameters have have changed. See Next-Gen Rules | openHAB.
Warning: CORE: Rules are now triggered by ItemStateUpdatedEvent instead of ItemStateEvent. If you use JSR223 scripting without helper libraries and expect a certain Java type, code changes might be needed.
Warning: CORE: The syntax for an item category/icon in a textual configuration file no longer accepts a value enclosed in quotes. So is valid but not <“temperature”>. Please update the definition of your items if necessary.
Warning: CORE: SCRIPT transformation has been removed and replaced with language-specific transformations: JS, RB, PY, DSL, GROOVY, etc. See Transformations | openHAB
Warning: CORE: UoM has been refactored. Please consult Units Of Measurement | openHAB and Installation Overview | openHAB BEFORE starting openHAB, otherwise your persisted data may be corrupted.
Warning: Airthings Binding: The channels radon_st_avg and radon_lt_avg are now of dimension RadiationSpecificActivity instead of Density. Please update your linked items accordingly.
Warning: Bosch Indego Binding: Due to changes in the cloud services, the authentication method has changed. Please follow the authorization flow described in the documentation. Furthermore, a bridge is now required and must be assigned to the indego thing. Configuration of username and password is no longer required/supported.
Warning: ComfoAir Binding: The channel enthalpy#enthalpyTime now represents the set time (in minutes) instead of the internal number value that is sent to the device (minutes / 12).
Warning: DanfossAirUnit Binding: The deprecated channel ‘manual_fan_speed’ has been removed. Please use channel ‘manual_fan_step’ introduced in 3.2.
Warning: Dark Sky Binding: Due to EOL of their API, this add-on has been removed.
Warning: Generac MobileLink Binding: Due to an API change, existing Generator Things will need to be deleted and added again. Additionally, existing Items will need to be adjusted to reflect the updated Generator Thing channels.
Warning: HomeKit: Add-on wide configuration of mappings for thermostat modes is no longer supported. Please use item-level configuration as described in the README.
Warning: Hue emulation: The uniqueid value has been changed to resolve discovery issues with Alexa. You may need to rediscover “devices” in all services that use the hue emulation (Amazon Echo, Logitech Harmony, etc).
Warning: Hunter Douglas (Luxaflex) PowerView Binding: Deprecated scene channels have been removed. Please use the scene channels introduced in 3.2 (in channel group ‘scenes’).
Warning: JavaScript: JavaScript engines have changed their MIME types: NashornJS is application/javascript:version=ECMAScript-5.1 and GraalJS is application/javascript. Please update your scripts to either make them compatible with GraalJS or change the MIME type to continue to use NashornJS. For Blockly migration, visit the Blockly documentation.
Warning: JavaScript NashornJS: NashornJS has been removed from core and isn’t included by default. If you still need or want to use it, you can install it as an addon.
Warning: JavaScript Scripting Automation: The old “metadata” and “itemchannellink” APIs have been replaced by a new API with extended functionality on the “items” namespace.
Warning: JavaScript Scripting Automation: ItemHistory: historicState, maximumBetween, maximumSince, minimumBetween, minimumSince & previousState now return a HistoricItem instead of just the state. previousStateTimestamp has been removed, the timestamp is available on the HistoricItem.
Warning: KNX Binding: Units of Measurements have been introduced, make sure you use correct units in the state description. Rules may need to be adapted. Several items changed from PercentType to QuantityType, i.e. raw values increase by a factor of 100.
Warning: LuftdatenInfo Binding: The binding was renamed to Sensor.Community Binding to match the new naming of the service. Things need to be recreated.
Warning: Netatmo Binding: Due to API authorization process change scheduled on the 2023/04/17 - refresh Token is no more stored in thing configuration, thus can be removed from things config files. If it remains, it’ll be ignored.
Warning: Netatmo Binding: New scope has been added for the introduction of the Carbon Monoxide Alarm. Authorization process has to be replayed (and former refreshToken can be removed from things config files – see above).
Warning: Windcentrale Binding: The binding has been reworked to support the new API that requires authentication. Delete old ‘mill’ Things, add an ‘account’ Bridge and add new ‘windmill’ Things using the ‘account’ as Bridge. The channel names now follow the naming conventions. Items must be adapted for these changes.
Okay to Continue? [y/N]: y

Execute ‘PRE’ instructions for version 4.0.1
No ‘PRE’ instructions found for version 4.0.1

Deleting current runtime (D:\servers\openhab\runtime)
Deleting current files in userdata that should not persist
Deleted all.policy from D:\servers\openhab\userdata\etc
Deleted branding.properties from D:\servers\openhab\userdata\etc
Deleted branding-ssh.properties from D:\servers\openhab\userdata\etc
Deleted config.properties from D:\servers\openhab\userdata\etc
Deleted custom.properties from D:\servers\openhab\userdata\etc
Deleted custom.system.properties from D:\servers\openhab\userdata\etc
Deleted distribution.info from D:\servers\openhab\userdata\etc
Deleted jmx.acl.org.apache.karaf.bundle.cfg from D:\servers\openhab\userdata\etc
Deleted jmx.acl.org.apache.karaf.config.cfg from D:\servers\openhab\userdata\etc
Deleted jre.properties from D:\servers\openhab\userdata\etc
Deleted org.apache.felix.eventadmin.impl.EventAdmin.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.felix.fileinstall-deploy.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.command.acl.bundle.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.command.acl.config.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.command.acl.feature.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.command.acl.jaas.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.command.acl.kar.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.command.acl.scope_bundle.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.command.acl.shell.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.command.acl.system.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.features.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.features.xml from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.features.repos.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.jaas.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.kar.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.log.cfg from D:\servers\openhab\userdata\etc
Deleted org.apache.karaf.shell.cfg from D:\servers\openhab\userdata\etc
Deleted org.jupnp.cfg from D:\servers\openhab\userdata\etc
Deleted org.ops4j.pax.url.mvn.cfg from D:\servers\openhab\userdata\etc
Deleted overrides.properties from D:\servers\openhab\userdata\etc
Deleted profile.cfg from D:\servers\openhab\userdata\etc
Deleted startup.properties from D:\servers\openhab\userdata\etc
Deleted system.properties from D:\servers\openhab\userdata\etc
Deleted version.properties from D:\servers\openhab\userdata\etc
Removing D:\servers\openhab\userdata\cache
Removing D:\servers\openhab\userdata\tmp
Copying C:\Users\OhUsr666\AppData\Local\Temp\openhab\update to D:\servers\openhab without overwriting existing ones

Execute ‘POST’ instructions for version 4.0.1

Performing post-update tasks for version [4.0.0] :
Replaced string ,javascript to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string javascript, to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string javascript to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string ,cometvisu-php to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string cometvisu-php, to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string cometvisu-php to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string ,innogysmarthome to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string innogysmarthome, to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string innogysmarthome to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string ,imperihome to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string imperihome, to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string imperihome to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string ,darksky to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string darksky, to in file D:\servers\openhab\userdata/config/org/openhab/addons.config
Replaced string darksky to in file D:\servers\openhab\userdata/config/org/openhab/addons.config

Starting JSON database update…
###############################################################################################

Restoring your distribution from C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5

###############################################################################################
Removing existing files in D:\servers\openhab
Copying backup files from C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5\home to D:\servers\openhab
Removing the directory D:\servers\openhab\conf
Copying backup directory C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5\conf to D:\servers\openhab\conf
Restoration was unsuccessful - you may want to restore from C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5 yourself
Update-openHAB : Cannot find path ‘C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5\conf’ because it does not exist.
At D:\servers\openhab\runtime\bin\update.ps1:584 char:22

* ... exit Update-openHAB -OHDirectory $OHDirectory -OHVersion $OHVe ...
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
* FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Update-openHAB

Your prior distribution is in C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5
Should it be deleted? [y/N]: y
Removing temporary distribution backup C:\Users\OhUsr666\AppData\Local\Temp\openhab\backup-3.4.5
Removing temporary directory C:\Users\OhUsr666\AppData\Local\Temp\openhab
Setting location back to D:\servers\openhab\runtime\bin
Press any key to continue . . .

Test run
D:\servers\openhab.scripts>java -jar "d:\servers\openhab\runtime\bin\upgradetool.jar" --dir "d:\servers\openhab\userdata" [main] INFO org.openhab.core.tools.internal.Upgrader - Copying item unit from state description to metadata in database 'd:\servers\openhab\userdata\jsondb\org.openhab.core.items.Item.json' [main] INFO org.openhab.core.tools.internal.Upgrader - Upgrading JS profile configuration in database 'd:\servers\openhab\userdata\jsondb\org.openhab.core.thing.link.ItemChannelLink.json'

Backup not created correctly during update on Windows
==============================================

As far as I understand the logic of the process:

  1. create folder in user temp backup-3.4.5 (current version)
  2. copy folders conf, runtime, userdata to backup-3.4.5 ( backup-3.4.5\conf, backup-3.4.5\runtime, backup-3.4.5\userdata)
  3. copy files from openhab root folder to backup-3.4.5\home folder

You can launch any 3.2.x+ or 4.x.x update script and you get:
On step 2: backup-3.4.5 with content of conf folder + runtime and userdata subfolder

  • runtime
  • userdata
  • automation
  • html
  • icons
  • items
  • persistence
  • rules
  • scripts
  • services
  • sitemaps
  • sounds
  • things
  • transform

On step 3: in folder backup-3.4.5 there will be a home file with the contents of the start.sh file!

$TempBackupDir = "$TempDir\backup-$CurrentVersion"
$TempBackupDirHome = $TempBackupDir + "\home"
$TempBackupDirRuntime = $TempBackupDir + "\runtime"
$TempBackupDirUserData = $TempBackupDir + "\userdata"
$TempBackupDirConf = $TempBackupDir + "\conf"

# Backup the current distribution to those locations
Write-Host ""
Write-Host -ForegroundColor Cyan "Making a backup of your distribution to $TempBackupDir"
try {
    Write-Host -ForegroundColor Cyan "Creating backup directories in $TempBackupDir"
    DeleteIfExists $TempBackupDir $True

    Write-Host -ForegroundColor Cyan "Copying directory conf, userdata and runtime to $TempBackupDirConf"
    Copy-Item -Path $OHConf, $OHUserData, $OHRuntime -Destination $TempBackupDir -Recurse -Force -ErrorAction Stop

    Write-Host -ForegroundColor Cyan "Copying files from $OHDirectory to $TempBackupDirHome"
    Get-ChildItem $OHDirectory -File -ErrorAction Stop | Copy-Item -Destination $TempBackupDirHome -Force -ErrorAction Stop

} catch {
    exit PrintAndReturn "Could not backup existing distribution to $TempBackupDir" $_
}

As a result, update.ps1 cannot return the state from the backup if the update installation fails (cannot find folders in backup 3.4.5).

And since update.ps1 on Windows cannot correctly call updatetools.jar, from version 3.4.5 to version 4.0.0, 4.0.1, 4.0.2 I update manually. The script is completely broken.

What is your current PATH?

I had a similar issue and the cause was that Java 11 was before Java 17 in the PATH.

Try run java -version from a command prompt to see which Java version is picked up.

I could not find details of the error when running upgradetool.jar from the script.

EDIT: I am also on Windows and other than the PATH issue have had no upgrade issues.

Thank you, I figured out what the problem was.
I don’t use system settings for Java. I have several server-side Java services. They all need different versions. I specify environment variables and Java version at startup.

Java runtimes for OpenHab are located in the OpenHab folder and for some reason update.ps1 does not use them during the update. I’ll deal with this later.

Temporarily setting system wide variables (JAVA_HOME and changing PATH) in the Control Panel solved the problem.