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

88 lines
4.1 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.
# Бэкап флешки по разделам (без MBR/VBR).
# Исключения: H:\ISO\*.iso, содержимое F:\efi\Paravis\Linux, System Volume Information, $RECYCLE.BIN.
$ErrorActionPreference = 'Stop'
$dest = 'C:\PF\flash-backup-2026-10-30-2'
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:2','/NP','/NFL','/NDL','/COPY:DAT','/DCOPY:T',
'/XD','System Volume Information','$RECYCLE.BIN','/XJ')
function Copy-Volume {
param([string]$src,[string]$dstName,[string[]]$extra=@(),[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 + $extra + @('/LOG+:' + $log)
"--- $label $src -> $dst"
$out = & robocopy @argv 2>&1
$code = $LASTEXITCODE
if ($code -ge 8) { $out | Select-Object -Last 30; throw "robocopy ${label}: код $code" }
" robocopy код: $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
" скопировано: {0:N0} файлов, {1:N2} ГБ" -f $s.Count,($s.Sum/1GB)
}
$t0 = Get-Date
Copy-Volume 'F:\' '01-PARAVIS-F' @('/XD','F:\efi\Paravis\Linux') 'раздел 1 (F: PARAVIS)'
foreach ($d in 'x64','x86') {
New-Item -ItemType Directory -Force (Join-Path $dest "01-PARAVIS-F\efi\Paravis\Linux\$d") | Out-Null
}
'N:' | Out-File -Encoding utf8 (Join-Path $dest '01-PARAVIS-F\efi\Paravis\Linux\_СОДЕРЖИМОЕ_НЕ_ВХОДИТ_В_БЭКАП.txt')
Copy-Volume 'G:\' '02-VTOYEFI-G' @() 'раздел 2 (G: VTOYEFI)'
Copy-Volume 'H:\' '03-DATA-H' @('/XF','*.iso') 'раздел 3 (H: DATA)'
$readme = @(
'Бэкап флешки PARAVIS FLASH (диск 2) — версия 2, без MBR/VBR',
('Создан: ' + (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:)',
' manifest-sha256.txt — контрольные суммы файлов бэкапа',
'',
'НЕ входит в бэкап:',
' * ISO-файлы в корне H:\ISO',
' * содержимое F:\efi\Paravis\Linux (папка сохранена пустой)',
' * System Volume Information, $RECYCLE.BIN',
' * MBR и загрузочные сектора (в отличие от бэкапа flash-backup-2026-10-30)',
'',
'Состояние на момент бэкапа: KRD 24 (efi\Paravis\KRD\live), Ventoy вместо GFM',
'в меню g4d и bootmgr, KRD 24 в legacy (g4d\antiv), Super GRUB2 с default=detect.'
)
$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,12} {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:mm\:ss}' -f $el
' каталог: {0}' -f $dest