Skip to content

Commit

Permalink
Fix backup.properties
Browse files Browse the repository at this point in the history
Fixed issue with CreateFromDirectory using .\ relative path

Signed-off-by: Brian Leedy <awsnap@gmail.com>
  • Loading branch information
bdleedy committed Dec 13, 2017
1 parent 29d0b21 commit d25870e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions distributions/openhab/src/main/resources/bin/backup.ps1
Expand Up @@ -12,10 +12,10 @@
The name of the zip file to create
.EXAMPLE
Backup an openHAB instance to a zip file
Backup-openHAB
Update-openHAB
.EXAMPLE
Backup the openHAB distribution in the C:\openHAB2 directory to c:\openhab-backup\backup.zip
Backup-openHAB -OHDirectory C:\openHAB2 -OHBackups c:\openHAB-backup -ZipFileOut backup.zip
Update the openHAB distribution in the C:\oh-snapshot directory to the next snapshot version
Backup-openHAB -OHDirectory C:\openHAB2 -OHBackups c:\openHAB2-backup -ZipFileOut backup.zip
#>

[CmdletBinding()]
Expand All @@ -42,6 +42,8 @@
"openHAB directory or specify the -OHDirectory parameter!"
}

if ($OHDirectory -eq '.') {$OHDirectory = pwd }

if ([Environment]::GetEnvironmentVariable("OPENHAB_CONF", "Machine")) {
$OHConf = [Environment]::GetEnvironmentVariable("OPENHAB_CONF", "Machine")
} else {
Expand Down Expand Up @@ -71,10 +73,10 @@
$CurrentVersionIndex = $VersionLine.IndexOf(":")
$CurrentVersion = $VersionLine.Substring($currentVersionIndex + 2)
$timestamp = Get-Date -Format yyyyMMddHHmm
Write-Host -ForegroundColor DarkGray "version=$CurrentVersion" | Add-Content "$TempDir\backup.properties"
Write-Host -ForegroundColor DarkGray "timestamp=$timestamp" | Add-Content "$TempDir\backup.properties"
#Write-Host -ForegroundColor DarkGray "user=$OHUser" | Add-Content "$TempDir\backup.properties"
#Write-Host -ForegroundColor DarkGray "group=$OHGroup" | Add-Content "$TempDir\backup.properties"
Write-Output "version=$CurrentVersion" | Set-Content "$TempDir\backup.properties"
Write-Output "timestamp=$timestamp" | Add-Content "$TempDir\backup.properties"
#Write-Output "user=$OHUser" | Add-Content "$TempDir\backup.properties"
#Write-Output "group=$OHGroup" | Add-Content "$TempDir\backup.properties"

Write-Host -ForegroundColor Cyan "Copying userdata and conf folder contents to temp directory"
$TempDir=([Environment]::GetEnvironmentVariable("TEMP", "Machine"))+"\openhab"
Expand Down Expand Up @@ -105,12 +107,12 @@

Write-Host -ForegroundColor Cyan "Zipping up files..."
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!($ZipFileOut)) {$ZipFileOut = "$OHBackups/openhab2-backup-$timestamp.zip"}
if (!($ZipFileOut)) {$ZipFileOut = "$OHBackups\openhab2-backup-$timestamp.zip"}
[System.IO.Compression.ZipFile]::CreateFromDirectory($TempDir, $ZipFileOut)

Write-Host -ForegroundColor Cyan "Removing temp files..."
Remove-Item $TempDir -Recurse -ErrorAction SilentlyContinue

Write-Host -ForegroundColor Green "Backup created at $OHBackups/openhab2-backup-$timestamp.zip"
Write-Host -ForegroundColor Green "Backup created at $OHBackups\openhab2-backup-$timestamp.zip"
}
}

0 comments on commit d25870e

Please sign in to comment.