Files
flash-build/backup-flash-verify.ps1
2026-11-13 07:52:38 +03:00

60 lines
3.4 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Сверка бэкапа с флешкой: имена + размеры, затем SHA-256 по ключевым файлам.
$dest = 'C:\PF\flash-backup-2026-10-30'
function Rel($root, $f) { $f.FullName.Substring($root.Length).TrimStart('\') }
function Compare-Volume {
param($src, $dst, [scriptblock]$filter, [string]$label)
$a = Get-ChildItem $src -Recurse -File -Force -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -notmatch '\\\$RECYCLE\.BIN\\|\\System Volume Information\\' } |
Where-Object { & $filter $_.FullName } |
ForEach-Object { [pscustomobject]@{ rel = (Rel $src $_); size = $_.Length } }
$b = Get-ChildItem $dst -Recurse -File -Force -ErrorAction Stop |
Where-Object { $_.Name -ne '_СОДЕРЖИМОЕ_НЕ_ВХОДИТ_В_БЭКАП.txt' } |
ForEach-Object { [pscustomobject]@{ rel = (Rel $dst $_); size = $_.Length } }
$da = $a | Group-Object rel -AsHashTable -AsString
$db = $b | Group-Object rel -AsHashTable -AsString
$missing = @($a | Where-Object { -not $db.ContainsKey($_.rel) })
$extra = @($b | Where-Object { -not $da.ContainsKey($_.rel) })
$differ = @($a | Where-Object { $db.ContainsKey($_.rel) -and $db[$_.rel].size -ne $_.size })
'{0}: источник {1:N0} файлов / {2:N2} ГБ ; бэкап {3:N0} / {4:N2} ГБ' -f `
$label, $a.Count, (($a | Measure-Object -Sum size).Sum/1GB), $b.Count, (($b | Measure-Object -Sum size).Sum/1GB)
' не скопировано: {0} ; лишних: {1} ; размер не совпал: {2}' -f $missing.Count, $extra.Count, $differ.Count
$missing | Select-Object -First 5 | ForEach-Object { ' нет: ' + $_.rel }
$extra | Select-Object -First 5 | ForEach-Object { ' лишний: ' + $_.rel }
$differ | Select-Object -First 5 | ForEach-Object { ' размер: ' + $_.rel }
return ($missing.Count -eq 0 -and $extra.Count -eq 0 -and $differ.Count -eq 0)
}
$ok = $true
$ok = (Compare-Volume 'F:\' "$dest\01-PARAVIS-F" { param($p) $p -notlike 'F:\efi\Paravis\Linux\*' } 'раздел 1 (F:)') -and $ok
$ok = (Compare-Volume 'G:\' "$dest\02-VTOYEFI-G" { param($p) $true } 'раздел 2 (G:)') -and $ok
$ok = (Compare-Volume 'H:\' "$dest\03-DATA-H" { param($p) $p -notlike '*.iso' } 'раздел 3 (H:)') -and $ok
''
'--- SHA-256 ключевых файлов (флешка vs бэкап):'
$key = @(
'efi\Paravis\Boot\grub2\grub.cfg',
'efi\Paravis\Boot\grub2\menu\utilits.cfg',
'efi\Paravis\Boot\super\x64.efi',
'efi\Paravis\Boot\super\x86.efi',
'efi\Paravis\Boot\super\super.iso',
'efi\Paravis\Boot\loaders\grub2\fbx64.efi',
'efi\Paravis\Utilities\ADD',
'efi\Paravis\Utilities\ABA',
'Change_bootLoader.exe',
'EFI\BOOT\bootx64.efi'
)
foreach ($k in $key) {
$p1 = Join-Path 'F:\' $k
$p2 = Join-Path "$dest\01-PARAVIS-F" $k
if (-not (Test-Path $p1)) { ' {0,-46} нет на флешке' -f $k; continue }
if (-not (Test-Path $p2)) { ' {0,-46} НЕТ В БЭКАПЕ' -f $k; $ok = $false; continue }
$h1 = (Get-FileHash $p1 -Algorithm SHA256).Hash
$h2 = (Get-FileHash $p2 -Algorithm SHA256).Hash
' {0,-46} {1}' -f $k, $(if ($h1 -eq $h2) { 'OK ' + $h1.Substring(0,16) } else { 'РАСХОЖДЕНИЕ' })
if ($h1 -ne $h2) { $ok = $false }
}
''
if ($ok) { '=== СВЕРКА: полностью совпадает' } else { '=== СВЕРКА: есть расхождения (см. выше)' }