feat: zentrales rollback.ps1 — stellt Stand vor Update wieder her
This commit is contained in:
@@ -0,0 +1,102 @@
|
|||||||
|
# StatusQuo_Updates/scripts/rollback.ps1
|
||||||
|
# Stellt den Stand vor dem letzten Update wieder her.
|
||||||
|
# Erwartet im aufrufenden Scope (wie update.ps1):
|
||||||
|
# $root - Installationspfad
|
||||||
|
# $stopBat - (optional) Stop-Skript-Dateiname oder ''
|
||||||
|
# $startBat - (optional) Start-Skript-Dateiname
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
$_stopName = if ($null -ne $stopBat) { $stopBat } else { 'stop.bat' }
|
||||||
|
$_startName = if ($null -ne $startBat) { $startBat } else { 'dgl.bat' }
|
||||||
|
|
||||||
|
# Verfügbare Backups suchen
|
||||||
|
$_backupBase = Join-Path $root '.backup'
|
||||||
|
if (-not (Test-Path -LiteralPath $_backupBase)) {
|
||||||
|
Write-Host "FEHLER: Kein Backup-Verzeichnis gefunden!" -ForegroundColor Red
|
||||||
|
Write-Host " Gesucht: $_backupBase"
|
||||||
|
Write-Host " Backups werden automatisch beim nächsten Update angelegt."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$_backups = Get-ChildItem -LiteralPath $_backupBase -Directory |
|
||||||
|
Where-Object { $_.Name -match '^\d{8}-\d{6}$' } | Sort-Object Name -Descending
|
||||||
|
|
||||||
|
if ($_backups.Count -eq 0) {
|
||||||
|
Write-Host "FEHLER: Keine Backups vorhanden." -ForegroundColor Red
|
||||||
|
Write-Host " Backups werden automatisch beim nächsten Update angelegt."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Verfügbare Backups:" -ForegroundColor Cyan
|
||||||
|
$_i = 0
|
||||||
|
foreach ($bk in $_backups) {
|
||||||
|
$suffix = if ($_i -eq 0) { " ← neuestes" } else { "" }
|
||||||
|
Write-Host (" [{0}] {1}{2}" -f $_i, $bk.Name, $suffix)
|
||||||
|
$_i++
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
$_choice = Read-Host "Backup-Nummer wählen (Enter = neuestes [0])"
|
||||||
|
if ($_choice -eq '') { $_choice = '0' }
|
||||||
|
if ($_choice -notmatch '^\d+$' -or [int]$_choice -ge $_backups.Count) {
|
||||||
|
Write-Host "Ungültige Auswahl. Abgebrochen." -ForegroundColor Yellow
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$_selected = $_backups[[int]$_choice]
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Stelle wieder her: $($_selected.Name)" -ForegroundColor Yellow
|
||||||
|
|
||||||
|
$yn = Read-Host "Rollback durchführen? Aktuelle Dateien werden überschrieben! [j/N]"
|
||||||
|
if ($yn -notin 'j','J','y','Y') { Write-Host "Abgebrochen."; return }
|
||||||
|
|
||||||
|
# Server stoppen
|
||||||
|
Write-Host "Stoppe Server ..."
|
||||||
|
if ($_stopName -ne '') {
|
||||||
|
$_stopPath = Join-Path $root $_stopName
|
||||||
|
if (Test-Path -LiteralPath $_stopPath) {
|
||||||
|
& cmd /c "`"$_stopPath`""
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
} else {
|
||||||
|
Write-Host " (Stop-Skript '$_stopName' nicht gefunden — übersprungen)" -ForegroundColor DarkYellow
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host " (Kein Stop-Skript konfiguriert — übersprungen)" -ForegroundColor DarkYellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# Nutzerdaten wiederherstellen
|
||||||
|
$_dataBackup = Join-Path $_selected.FullName 'data'
|
||||||
|
if (Test-Path -LiteralPath $_dataBackup) {
|
||||||
|
$dataTarget = Join-Path $root 'data'
|
||||||
|
if (Test-Path -LiteralPath $dataTarget) {
|
||||||
|
# Aktuellen data/-Ordner vor Überschreiben sichern
|
||||||
|
$safeName = "data_vor_rollback_$(Get-Date -Format 'yyyyMMdd-HHmmss')"
|
||||||
|
Rename-Item -LiteralPath $dataTarget -NewName $safeName -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
Copy-Item -Path $_dataBackup -Destination $dataTarget -Recurse -Force
|
||||||
|
$dataCount = (Get-ChildItem -LiteralPath $dataTarget -Recurse -File -ErrorAction SilentlyContinue).Count
|
||||||
|
Write-Host "Nutzerdaten wiederhergestellt ($dataCount Dateien)." -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host " (Kein Nutzerdaten-Backup in diesem Stand)" -ForegroundColor DarkYellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# Code-Dateien wiederherstellen
|
||||||
|
$_codeFiles = Get-ChildItem -LiteralPath $_selected.FullName -File -ErrorAction SilentlyContinue
|
||||||
|
foreach ($f in $_codeFiles) {
|
||||||
|
Copy-Item -Path $f.FullName -Destination (Join-Path $root $f.Name) -Force
|
||||||
|
}
|
||||||
|
Write-Host "Code-Dateien wiederhergestellt ($($_codeFiles.Count) Dateien)." -ForegroundColor Green
|
||||||
|
|
||||||
|
# Server neu starten
|
||||||
|
$_startPath = Join-Path $root $_startName
|
||||||
|
if (Test-Path -LiteralPath $_startPath) {
|
||||||
|
Start-Process -FilePath 'cmd.exe' -ArgumentList "/c `"$_startPath`"" -WindowStyle Hidden
|
||||||
|
Write-Host "Server gestartet." -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "Start-Skript '$_startName' nicht gefunden — bitte Server manuell starten." -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "=== Rollback abgeschlossen ===" -ForegroundColor Green
|
||||||
|
Write-Host " Wiederhergestellt: $($_selected.Name)" -ForegroundColor Cyan
|
||||||
Reference in New Issue
Block a user