fix(KRITISCH): Exclude-Array korrekt aufbauen - ForWipe entpackte zu Skalar, Restore haette .backup/Content geloescht
This commit is contained in:
+8
-4
@@ -40,11 +40,15 @@ function Start-Portal {
|
|||||||
# Ausgeschlossene Ordner werden weder gesichert noch beim Rollback verändert.
|
# Ausgeschlossene Ordner werden weder gesichert noch beim Rollback verändert.
|
||||||
function Get-ExcludeNames {
|
function Get-ExcludeNames {
|
||||||
param([switch]$ForWipe)
|
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'
|
$f = Join-Path $root '.backupignore'
|
||||||
if (Test-Path -LiteralPath $f) {
|
if (Test-Path -LiteralPath $f) {
|
||||||
$ex += (Get-Content -LiteralPath $f | ForEach-Object { $_.Trim() } |
|
$extra = @(Get-Content -LiteralPath $f | ForEach-Object { $_.Trim() } |
|
||||||
Where-Object { $_ -ne '' -and -not $_.StartsWith('#') })
|
Where-Object { $_ -ne '' -and -not $_.StartsWith('#') })
|
||||||
|
$ex = $ex + $extra
|
||||||
}
|
}
|
||||||
return $ex
|
return $ex
|
||||||
}
|
}
|
||||||
@@ -57,7 +61,7 @@ function New-Snapshot {
|
|||||||
$bk = Join-Path $root '.backup'
|
$bk = Join-Path $root '.backup'
|
||||||
if (-not (Test-Path -LiteralPath $bk)) { New-Item -ItemType Directory -Path $bk -Force | Out-Null }
|
if (-not (Test-Path -LiteralPath $bk)) { New-Item -ItemType Directory -Path $bk -Force | Out-Null }
|
||||||
$zip = Join-Path $bk "snapshot-$ts.zip"
|
$zip = Join-Path $bk "snapshot-$ts.zip"
|
||||||
$exclude = Get-ExcludeNames
|
$exclude = @(Get-ExcludeNames)
|
||||||
$items = Get-ChildItem -LiteralPath $root -Force | Where-Object { $exclude -notcontains $_.Name }
|
$items = Get-ChildItem -LiteralPath $root -Force | Where-Object { $exclude -notcontains $_.Name }
|
||||||
if (-not $items) { throw "Portal-Wurzel ist leer — nichts zu sichern." }
|
if (-not $items) { throw "Portal-Wurzel ist leer — nichts zu sichern." }
|
||||||
Compress-Archive -Path $items.FullName -DestinationPath $zip -CompressionLevel Optimal -Force
|
Compress-Archive -Path $items.FullName -DestinationPath $zip -CompressionLevel Optimal -Force
|
||||||
@@ -77,7 +81,7 @@ function Restore-Snapshot {
|
|||||||
param([string]$Zip)
|
param([string]$Zip)
|
||||||
# Wurzel leeren (außer .backup + .backupignore-Ordner), dann Snapshot zurückspielen.
|
# Wurzel leeren (außer .backup + .backupignore-Ordner), dann Snapshot zurückspielen.
|
||||||
# Ausgeschlossene Content-Ordner bleiben unangetastet an Ort und Stelle.
|
# 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 } |
|
Get-ChildItem -LiteralPath $root -Force | Where-Object { $ex -notcontains $_.Name } |
|
||||||
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
Expand-Archive -LiteralPath $Zip -DestinationPath $root -Force
|
Expand-Archive -LiteralPath $Zip -DestinationPath $root -Force
|
||||||
|
|||||||
Reference in New Issue
Block a user