Skip to content

Update update.ps1 - #1862

Open
seliSoft wants to merge 1 commit into
openhab:mainfrom
seliSoft:patch-1
Open

Update update.ps1#1862
seliSoft wants to merge 1 commit into
openhab:mainfrom
seliSoft:patch-1

Conversation

@seliSoft

Copy link
Copy Markdown

More robust backup handling
The upgrade failed on Windows 10, because the files are copied to a file named "home" instead of a the directory home. Simmilar thing happend to conf/userdata/runtime
With the changes the process is more robust and with the correct folders it is able to restore the files later.

More robust backup handling

Signed-off-by: seliSoft <seliSoft@users.noreply.github.com>
@seliSoft
seliSoft requested a review from a team as a code owner January 18, 2026 10:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


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 directory conf, userdata and runtime to $TempBackupDir"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the text should be adapted....

@wborn wborn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR was reviewed by AI first, before manual maintainer review.

The change addresses a valid problem: the temporary backup needs predictable conf, userdata, runtime, and home paths because those paths are used by the restore logic, while the source directories can be configured through environment variables.

There is one issue with the current implementation that should be addressed before merging. The code removes $TempBackupDir and then immediately tries to create child directories using that removed directory as the New-Item -Path. It also pre-creates the destinations before copying the source directories, which changes the behavior of Copy-Item and can introduce an additional directory level.

The existing CreateDirectory helper can be used to keep the fix simpler and make the intended backup layout explicit.

Since this backup is also the rollback mechanism when an update fails, it would be useful to manually verify the backup and restore paths with Windows PowerShell 5.1. The current CI build runs on Ubuntu and does not exercise this Windows-specific behavior.

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 directory conf, userdata and runtime to $TempBackupDir"
New-Item -Path $TempBackupDir -Name "conf" -ItemType "Directory"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$TempBackupDir was just removed above, so it does not normally exist when this tries to create conf relative to it.

Pre-creating $TempBackupDirConf also changes the semantics of the following Copy-Item: when the destination directory already exists, copying $OHConf can create another directory level below it.

The existing CreateDirectory helper could keep this simpler:

CreateDirectory $TempBackupDir

Copy-Item -Path $OHConf -Destination $TempBackupDirConf -Recurse -Force -ErrorAction Stop
Copy-Item -Path $OHUserData -Destination $TempBackupDirUserData -Recurse -Force -ErrorAction Stop
Copy-Item -Path $OHRuntime -Destination $TempBackupDirRuntime -Recurse -Force -ErrorAction Stop

CreateDirectory $TempBackupDirHome

This still gives the backup the fixed conf, userdata, and runtime names expected by the restore logic, independent of the configured source directory names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants