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

81 lines
3.9 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.
# Полный бэкап флешки: все файлы (включая ISO и Linux), без MBR/VBR.
$ErrorActionPreference = 'Stop'
$dest = 'C:\PF\flash-backup-2026-10-30-3'
if (Get-Process -Name vmware-vmx -ErrorAction SilentlyContinue) { throw 'VM запущена — выключите' }
if (Test-Path $dest) {
$n = (Get-ChildItem $dest -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object).Count
if ($n -gt 0) { throw "Каталог $dest уже существует и не пуст ($n файлов)." }
} else {
New-Item -ItemType Directory -Force $dest | Out-Null
}
$common = @('/E','/R:3','/W:3','/NP','/NFL','/NDL','/COPY:DAT','/DCOPY:T',
'/XD','System Volume Information','$RECYCLE.BIN','/XJ')
function Copy-Volume {
param([string]$src,[string]$dstName,[string]$label)
$dst = Join-Path $dest $dstName
New-Item -ItemType Directory -Force $dst | Out-Null
$log = Join-Path $dest ("_robocopy-" + $dstName + ".log")
$argv = @($src,$dst) + $common + @('/LOG+:' + $log)
$t = Get-Date
"--- $label $src -> $dst"
$out = & robocopy @argv 2>&1
$code = $LASTEXITCODE
if ($code -ge 8) { $out | Select-Object -Last 20; throw "robocopy ${label}: код $code" }
$s = Get-ChildItem $dst -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object -Sum Length
# Корень NTFS-тома имеет атрибуты Hidden+System, и robocopy (/COPY:DAT) их копирует.
# Снимаем сразу, иначе скопированный раздел «пропадает» из обычных списков.
& attrib.exe -h -s $dst | Out-Null
" robocopy код {0}, {1:N0} файлов, {2:N2} ГБ, {3:mm\:ss}" -f $code,$s.Count,($s.Sum/1GB),((Get-Date)-$t)
}
$t0 = Get-Date
Copy-Volume 'F:\' '01-PARAVIS-F' 'раздел 1 (F: PARAVIS)'
Copy-Volume 'G:\' '02-VTOYEFI-G' 'раздел 2 (G: VTOYEFI)'
Copy-Volume 'H:\' '03-DATA-H' 'раздел 3 (H: DATA)'
$readme = @(
'Полный бэкап флешки PARAVIS FLASH (диск 2)',
('Создан: ' + (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')),
'',
'Состав:',
' 01-PARAVIS-F — раздел 1, FAT32, метка PARAVIS (F:)',
' 02-VTOYEFI-G — раздел 2, FAT, метка VTOYEFI (G:)',
' 03-DATA-H — раздел 3, NTFS, метка DATA (H:), включая ISO',
' manifest-sha256.txt — контрольные суммы всех файлов',
'',
'Включено всё содержимое разделов (в том числе ISO-образы и efi\Paravis\Linux).',
'НЕ входит:',
' * MBR и загрузочные сектора (VBR) — по решению владельца',
' * System Volume Information, $RECYCLE.BIN (служебные)',
'',
'Состояние: KRD 24 в efi\Paravis\KRD (ia32 без Kaspersky), Ventoy вместо GFM',
'в g4d и bootmgr, Super GRUB2 с default=detect, картинки Xorboot обновлены.'
)
$readme | Out-File -Encoding utf8 (Join-Path $dest 'README.txt')
'--- SHA-256 (может занять пару минут) ...'
$manifest = Join-Path $dest 'manifest-sha256.txt'
$lines = New-Object System.Collections.Generic.List[string]
Get-ChildItem $dest -Recurse -File -Force |
Where-Object { $_.FullName -ne $manifest } |
Sort-Object FullName |
ForEach-Object {
$rel = $_.FullName.Substring($dest.Length + 1)
$h = (Get-FileHash $_.FullName -Algorithm SHA256).Hash
$lines.Add(('{0} {1,13} {2}' -f $h, $_.Length, $rel))
}
$lines | Out-File -Encoding utf8 $manifest
$el = (Get-Date) - $t0
$tot = Get-ChildItem $dest -Recurse -File -Force | Measure-Object -Sum Length
''
'=== ИТОГО'
' файлов: {0:N0}' -f $tot.Count
' объём: {0:N2} ГБ' -f ($tot.Sum/1GB)
' время: {0:hh\:mm\:ss}' -f $el
' каталог: {0}' -f $dest