117 lines
4.6 KiB
PowerShell
117 lines
4.6 KiB
PowerShell
# Auslagerung alter AzA-Kopien -> E:\AzA\NEUER BACKUP JUNI 2026
|
|
# Nur die explizit genannten 31 Ordner. Aktiver Ordner "AzA march 2026" wird NICHT angefasst.
|
|
$ErrorActionPreference = "Stop"
|
|
$srcRoot = "C:\Users\surov\Documents\AZA_GIT\aza"
|
|
$destRoot = "E:\AzA\NEUER BACKUP JUNI 2026"
|
|
$logDir = Join-Path $destRoot "_MOVE_LOGS"
|
|
$activeFolder = Join-Path $srcRoot "AzA march 2026"
|
|
$ts = Get-Date -Format "yyyyMMdd_HHmmss"
|
|
$docPath = Join-Path $destRoot "MOVED_FROM_AZA_GIT_$ts.txt"
|
|
|
|
$folderNames = @("AzA march 2026 - Kopie") + (2..29 | ForEach-Object { "AzA march 2026 - Kopie ($($_))" }) + @(
|
|
"backup backup backup backup",
|
|
"Hetzner_Backups"
|
|
)
|
|
|
|
function Get-FolderStats {
|
|
param([string]$Path)
|
|
$files = @(Get-ChildItem -LiteralPath $Path -Recurse -File -Force -ErrorAction SilentlyContinue)
|
|
$dirs = @(Get-ChildItem -LiteralPath $Path -Recurse -Directory -Force -ErrorAction SilentlyContinue)
|
|
$bytes = [int64](($files | Measure-Object -Property Length -Sum).Sum)
|
|
if ($null -eq $bytes) { $bytes = 0 }
|
|
return @{
|
|
Files = $files.Count
|
|
Dirs = $dirs.Count
|
|
Bytes = $bytes
|
|
}
|
|
}
|
|
|
|
function Write-DocLine([string]$Line) {
|
|
Add-Content -LiteralPath $docPath -Value $Line -Encoding UTF8
|
|
}
|
|
|
|
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
|
|
Write-DocLine "MOVED FROM AZA_GIT - Dokumentation"
|
|
Write-DocLine "Datum/Uhrzeit: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
|
|
Write-DocLine "Quellordner: $srcRoot"
|
|
Write-DocLine "Zielordner: $destRoot"
|
|
Write-DocLine "Grund: Auslagerung wegen Git-Fehler Filename too long"
|
|
Write-DocLine "Aktiver Projektordner NICHT verschoben: $activeFolder"
|
|
Write-DocLine ""
|
|
Write-DocLine "=== ORDNER ==="
|
|
|
|
$moved = @()
|
|
$failed = @()
|
|
|
|
foreach ($name in $folderNames) {
|
|
if ($name -eq "AzA march 2026") {
|
|
throw "STOPP: Aktiver Ordner in Verschiebeliste!"
|
|
}
|
|
$src = Join-Path $srcRoot $name
|
|
$dst = Join-Path $destRoot $name
|
|
if (-not (Test-Path -LiteralPath $src)) {
|
|
Write-DocLine "FEHLEND (uebersprungen): $src"
|
|
$failed += $name
|
|
continue
|
|
}
|
|
if (Test-Path -LiteralPath $dst) {
|
|
Write-DocLine "STOPP Namenskonflikt am Ziel: $dst"
|
|
throw "Namenskonflikt: $dst existiert bereits"
|
|
}
|
|
|
|
$pre = Get-FolderStats -Path $src
|
|
$safeName = ($name -replace '[\\/:*?"<>|]', '_')
|
|
$logFile = Join-Path $logDir "robocopy_${safeName}_$ts.log"
|
|
|
|
Write-Host "[COPY] $name ..."
|
|
$rc = 0
|
|
& robocopy $src $dst /E /COPY:DAT /DCOPY:DAT /R:2 /W:3 /NP /NFL /NDL /LOG:$logFile /TEE | Out-Null
|
|
$rc = $LASTEXITCODE
|
|
if ($rc -ge 8) {
|
|
Write-DocLine "ROBOCOPY FEHLER rc=$rc : $name -> Log: $logFile"
|
|
$failed += $name
|
|
throw "Robocopy Fehler rc=$rc fuer $name"
|
|
}
|
|
|
|
$post = Get-FolderStats -Path $dst
|
|
$ok = ($pre.Files -eq $post.Files) -and ($pre.Dirs -eq $post.Dirs) -and ($pre.Bytes -eq $post.Bytes)
|
|
if (-not $ok) {
|
|
Write-DocLine "VERIFIKATION FEHLGESCHLAGEN: $name"
|
|
Write-DocLine " Quelle: Files=$($pre.Files) Dirs=$($pre.Dirs) Bytes=$($pre.Bytes)"
|
|
Write-DocLine " Ziel: Files=$($post.Files) Dirs=$($post.Dirs) Bytes=$($post.Bytes)"
|
|
$failed += $name
|
|
throw "Verifikation fehlgeschlagen: $name"
|
|
}
|
|
|
|
# ZIP SHA256 Stichprobe
|
|
$srcZips = Get-ChildItem -LiteralPath $src -Recurse -File -Filter *.zip -Force -ErrorAction SilentlyContinue
|
|
foreach ($z in $srcZips) {
|
|
$rel = $z.FullName.Substring($src.Length).TrimStart('\')
|
|
$dz = Join-Path $dst $rel
|
|
if (-not (Test-Path -LiteralPath $dz)) { throw "ZIP fehlt am Ziel: $rel" }
|
|
$h1 = (Get-FileHash -LiteralPath $z.FullName -Algorithm SHA256).Hash
|
|
$h2 = (Get-FileHash -LiteralPath $dz -Algorithm SHA256).Hash
|
|
if ($h1 -ne $h2) { throw "ZIP SHA256 mismatch: $rel" }
|
|
}
|
|
|
|
Write-DocLine "OK: $name"
|
|
Write-DocLine " Quelle: $src"
|
|
Write-DocLine " Ziel: $dst"
|
|
Write-DocLine " Files=$($pre.Files) Dirs=$($pre.Dirs) Bytes=$($pre.Bytes) GB=$([math]::Round($pre.Bytes/1GB,3))"
|
|
Write-DocLine " Robocopy rc=$rc Log=$logFile"
|
|
Write-DocLine " Verifikation: PASS (Dateianzahl, Unterordner, Groesse, ZIP-SHA256)"
|
|
|
|
Remove-Item -LiteralPath $src -Recurse -Force
|
|
if (Test-Path -LiteralPath $src) { throw "Quelle konnte nicht entfernt werden: $src" }
|
|
if (-not (Test-Path -LiteralPath $dst)) { throw "Ziel fehlt nach Entfernen der Quelle: $dst" }
|
|
Write-DocLine " Quelle entfernt: JA"
|
|
Write-DocLine ""
|
|
$moved += $name
|
|
Write-Host "[DONE] $name"
|
|
}
|
|
|
|
Write-DocLine "=== ZUSAMMENFASSUNG ==="
|
|
Write-DocLine "Verschoben: $($moved.Count) von $($folderNames.Count)"
|
|
Write-DocLine "Fehlgeschlagen: $($failed.Count)"
|
|
Write-Host "FERTIG. Dokumentation: $docPath"
|