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
Fixed synopsis
Moved $TempDir creation up, added default user and group of openHAB to
backup.properties

Signed-off-by: Brian Leedy <awsnap@gmail.com>
  • Loading branch information
bdleedy committed Dec 13, 2017
1 parent 29d0b21 commit 342bc9d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions distributions/openhab/src/main/resources/bin/backup.ps1
Expand Up @@ -14,8 +14,8 @@
Backup an openHAB instance to a zip file
Backup-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
Backup the openHAB distribution in the C:\openHAB2 directory to c:\openHAB2-backup\backup.zip
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 All @@ -67,18 +69,19 @@
Write-Host -ForegroundColor Yellow "Using $OHUserdata as userdata folder"
Write-Host -ForegroundColor Yellow "Using $OHBackups as backups folder"

$TempDir=([Environment]::GetEnvironmentVariable("TEMP", "Machine"))+"\openhab"
New-Item $TempDir -Type directory -Force | Out-Null

$VersionLine = Get-Content "$OHDirectory\userdata\etc\version.properties" | Where-Object { $_.Contains("openhab-distro")}
$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=openHAB" | Add-Content "$TempDir\backup.properties"
Write-Output "group=openHAB" | Add-Content "$TempDir\backup.properties"

Write-Host -ForegroundColor Cyan "Copying userdata and conf folder contents to temp directory"
$TempDir=([Environment]::GetEnvironmentVariable("TEMP", "Machine"))+"\openhab"
New-Item $TempDir -Type directory -Force | Out-Null
mkdir "$TempDir\userdata" | Out-Null
Copy-Item $OHUserdata $TempDir -Recurse -Force
mkdir "$TempDir\conf" | Out-Null
Expand All @@ -105,12 +108,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 342bc9d

Please sign in to comment.