fix(KRITISCH): Exclude-Array korrekt aufbauen - ForWipe entpackte zu Skalar, Restore haette .backup/Content geloescht

This commit is contained in:
Rhino
2026-06-20 22:09:12 +02:00
parent 430a1db0a7
commit 86447d49b1
+9 -5
View File
@@ -40,11 +40,15 @@ function Start-Portal {
# Ausgeschlossene Ordner werden weder gesichert noch beim Rollback verändert.
function Get-ExcludeNames {
param([switch]$ForWipe)
$ex = if ($ForWipe) { @('.backup') } else { @('.backup','TempUpdate') }
# WICHTIG: Array strikt als Array aufbauen. 'if (){@(x)}' würde ein
# 1-Element-Array zu einem Skalar entpacken → '+=' verkettet dann Strings.
$ex = @('.backup')
if (-not $ForWipe) { $ex = $ex + 'TempUpdate' }
$f = Join-Path $root '.backupignore'
if (Test-Path -LiteralPath $f) {
$ex += (Get-Content -LiteralPath $f | ForEach-Object { $_.Trim() } |
Where-Object { $_ -ne '' -and -not $_.StartsWith('#') })
$extra = @(Get-Content -LiteralPath $f | ForEach-Object { $_.Trim() } |
Where-Object { $_ -ne '' -and -not $_.StartsWith('#') })
$ex = $ex + $extra
}
return $ex
}
@@ -57,7 +61,7 @@ function New-Snapshot {
$bk = Join-Path $root '.backup'
if (-not (Test-Path -LiteralPath $bk)) { New-Item -ItemType Directory -Path $bk -Force | Out-Null }
$zip = Join-Path $bk "snapshot-$ts.zip"
$exclude = Get-ExcludeNames
$exclude = @(Get-ExcludeNames)
$items = Get-ChildItem -LiteralPath $root -Force | Where-Object { $exclude -notcontains $_.Name }
if (-not $items) { throw "Portal-Wurzel ist leer — nichts zu sichern." }
Compress-Archive -Path $items.FullName -DestinationPath $zip -CompressionLevel Optimal -Force
@@ -77,7 +81,7 @@ function Restore-Snapshot {
param([string]$Zip)
# Wurzel leeren (außer .backup + .backupignore-Ordner), dann Snapshot zurückspielen.
# Ausgeschlossene Content-Ordner bleiben unangetastet an Ort und Stelle.
$ex = Get-ExcludeNames -ForWipe
$ex = @(Get-ExcludeNames -ForWipe)
Get-ChildItem -LiteralPath $root -Force | Where-Object { $ex -notcontains $_.Name } |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Expand-Archive -LiteralPath $Zip -DestinationPath $root -Force