P0-P3 全量重构:退出码 / 解析修复、manifest 与 7z t 校验、干跑、排除规则、日志、测试与计划任务
P0 正确性 - 退出码:改用 .NET Process 直接启动、让子进程继承控制台,不再用 Start-Process -PassThru (在 7.7.0-preview.4 上 ExitCode 恒为 $null,会把成功的压缩判成失败); 7z / RAR / tar 三条解压分支统一走同一个取退出码的封装。 - BackupList 解析:先按第一个 :: 切段再处理引号(整行被一对引号包住的写法不再把排除表 吞进路径);排除表同时接受 , 与 ;(旧实现只认 ;,导致排除从未生效);支持 :- / :+ / @flag。 - 补回 .ssh 与孤儿归档:.ssh 进清单;孤儿归档在备份端也做审计并点名; 带 -Only / -Skip 时不再把未选中的归档误报成孤儿。 - Resolve-BackupEntry 里 $rootName 在赋值前被引用(会读到外层作用域残留值),已提前赋值。 P1 归档可靠性 - 每个条目写进 manifest.json:源、归档、时间、退出码、校验结果、失败原因, 并区分 warnings(在位归档)与 attemptWarnings(本次尝试)。 - 归档后做 7z t 内容校验,先写 .tmp、校验通过再原子替换(File.Move overwrite)。 - manifest.roots 记录归档内**真实**的顶层条目名(原先记的是软件名,Edge 实际是 "User Data")。 P2 可用性 - Restore 支持 -WhatIf / -DryRun / -VerifyOnly / -Only / -Skip; 这三种"只看不写"的模式一个字节都不写(原先会写回 manifest.json)。 - Edge 等高缓存条目加排除规则并实测:1781 MB / 27961 项 -> 72 MB / 2294 项; 书签、密码、Cookies、偏好、历史、IndexedDB、Local Storage 全部保留。 普通模式是相对归档根目录锚定的,嵌套的那些(如 OneAuth\WebView2 里的 Crashpad) 改用 ! 组件形式才会命中。 - 日志落盘 logs/<backup|restore>-<时间戳>.log;退出码按失败数返回。 - tools/Register-BackupTask.ps1 注册每日计划任务;tools/Rename-Archives.ps1 迁移旧归档名。 - root= 标记此前静默失效,现在明确告警(该功能尚未实现)。 P3 测试与验证 - tests/BakNRet.Tests.ps1:Pester 5 套件 62 项(含用子进程跑 Backup.ps1 / Restore.ps1 的端到端与针对上述缺陷的回归)。 - tests/Run-Pester.ps1 + tools/Install-TestDependencies.ps1:把 Pester 装到仓库内 .tools/, 不动机器上的全局模块(系统自带的 3.4.0 缺 Should -Be)。 - tests/Restore-Drill.ps1:真实归档恢复演练,明确区分"源在备份后变过"与"归档/解压有问题"。 - tests/Run-Tests.ps1(49 项,零依赖)与 tests/Run-E2E.ps1(23 项)继续可用;三套共 134 项全通过。 真实机器验证 - 生产归档 22/22 通过 7z t;-VerifyOnly 不再改动 manifest.json(SHA256 前后一致)。 - 真实恢复演练 12/12 通过,27,670 个文件与活源逐字节一致。 - 修复了生产 scoop-persist.7z:原先只有 90 字节(空归档)而源有 1.3 GB, 重打包后 233 MB,恢复演练 26981/26981 全部一致。
This commit is contained in:
1 parent
045d51ac9c
commit
e114cae8c8
13 files changed
+1761
-142
No files matched your search
@@ -89,6 +89,81 @@ Test-Case '@ 标记跟在排除表后面' {
|
||||
Assert-Equal 2 $r.ExcludePatterns.Count
|
||||
Assert-Equal 'encrypt' $r.Flags[0]
|
||||
}
|
||||
Test-Case ':+ 追加目录(可多个、位置无关)' {
|
||||
$r = ConvertFrom-BackupListLine -Line 'MyApp :+ D:\a :+ D:\b'
|
||||
Assert-Equal 'MyApp' $r.Path
|
||||
Assert-Equal 2 $r.AddedPaths.Count
|
||||
Assert-Equal 'D:\a' $r.AddedPaths[0]
|
||||
Assert-Equal 'D:\b' $r.AddedPaths[1]
|
||||
Assert-Equal 0 $r.ExcludePatterns.Count
|
||||
}
|
||||
|
||||
Test-Case ':- 排除,与 :+ 混用且顺序任意' {
|
||||
$r = ConvertFrom-BackupListLine -Line 'MyApp :- logs\ :+ D:\a :- !*Cache'
|
||||
Assert-Equal 'MyApp' $r.Path
|
||||
Assert-Equal 1 $r.AddedPaths.Count
|
||||
Assert-Equal 2 $r.ExcludePatterns.Count
|
||||
Assert-Equal 'logs\' $r.ExcludePatterns[0]
|
||||
Assert-Equal '!*Cache' $r.ExcludePatterns[1]
|
||||
}
|
||||
|
||||
Test-Case ':: 与 :- 等价' {
|
||||
$a = ConvertFrom-BackupListLine -Line 'X :: logs\'
|
||||
$b = ConvertFrom-BackupListLine -Line 'X :- logs\'
|
||||
Assert-Equal $a.ExcludePatterns[0] $b.ExcludePatterns[0]
|
||||
Assert-Equal 'logs\' $b.ExcludePatterns[0]
|
||||
}
|
||||
|
||||
Test-Case ':+ 段里的 @标记也能被摘出' {
|
||||
$r = ConvertFrom-BackupListLine -Line 'MyApp :+ D:\a @encrypt'
|
||||
Assert-Equal 'MyApp' $r.Path
|
||||
Assert-Equal 'D:\a' $r.AddedPaths[0]
|
||||
Assert-Equal 'encrypt' $r.Flags[0]
|
||||
}
|
||||
|
||||
Test-Case '盘符里的单个冒号不被误当分隔符' {
|
||||
$r = ConvertFrom-BackupListLine -Line 'C:\Programs\Foo'
|
||||
Assert-Equal 'C:\Programs\Foo' $r.Path
|
||||
Assert-Equal 0 $r.AddedPaths.Count
|
||||
Assert-Equal 0 $r.ExcludePatterns.Count
|
||||
}
|
||||
|
||||
Test-Case '名录 Dirs 数组:一个软件多个目录' {
|
||||
$dirsSandbox = Join-Path $env:TEMP ("baknret-dirs-" + [guid]::NewGuid().ToString('N').Substring(0, 6))
|
||||
New-Item -ItemType Directory -Path (Join-Path $dirsSandbox 'App') -Force | Out-Null
|
||||
New-Item -ItemType Directory -Path (Join-Path $dirsSandbox 'Config') -Force | Out-Null
|
||||
$catPath = Join-Path $dirsSandbox 'c.psd1'
|
||||
$content = "@{`n MyApp = @{ Dirs = @('$dirsSandbox\App', '$dirsSandbox\Config') }`n}`n"
|
||||
[System.IO.File]::WriteAllText($catPath, $content, [System.Text.UTF8Encoding]::new($false))
|
||||
|
||||
$catalog = Get-SoftwareCatalog -Path $catPath
|
||||
Assert-Equal 'Multi' $catalog['MyApp'].Kind
|
||||
Assert-Equal 2 $catalog['MyApp'].Dirs.Count
|
||||
|
||||
$item = ConvertFrom-BackupListLine -Line 'MyApp'
|
||||
$resolved = Resolve-BackupEntry -Entry $item -CatalogPath $catPath
|
||||
Assert-Equal 'MyApp' $resolved.BaseName
|
||||
Assert-Equal 2 $resolved.Sources.Count '每个目录都该成为一条源'
|
||||
Assert-Equal 'App' $resolved.Sources[0].RelativePaths[0]
|
||||
Assert-Equal 'Config' $resolved.Sources[1].RelativePaths[0]
|
||||
Remove-Item -LiteralPath $dirsSandbox -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
Test-Case '清单 :+ 追加的目录叠加在名录目录之后' {
|
||||
$dirsSandbox = Join-Path $env:TEMP ("baknret-adds-" + [guid]::NewGuid().ToString('N').Substring(0, 6))
|
||||
New-Item -ItemType Directory -Path (Join-Path $dirsSandbox 'App') -Force | Out-Null
|
||||
New-Item -ItemType Directory -Path (Join-Path $dirsSandbox 'Extra') -Force | Out-Null
|
||||
$catPath = Join-Path $dirsSandbox 'c.psd1'
|
||||
$content = "@{`n MyApp = '$dirsSandbox\App'`n}`n"
|
||||
[System.IO.File]::WriteAllText($catPath, $content, [System.Text.UTF8Encoding]::new($false))
|
||||
|
||||
$item = ConvertFrom-BackupListLine -Line "MyApp :+ $dirsSandbox\Extra"
|
||||
$resolved = Resolve-BackupEntry -Entry $item -CatalogPath $catPath
|
||||
Assert-Equal 2 $resolved.Sources.Count '名录 1 个 + 追加 1 个'
|
||||
Assert-Equal 'App' $resolved.Sources[0].RelativePaths[0]
|
||||
Assert-Equal 'Extra' $resolved.Sources[1].RelativePaths[0]
|
||||
Remove-Item -LiteralPath $dirsSandbox -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
Write-Host "`n== 归档命名 ==" -ForegroundColor Cyan
|
||||
|
||||
Reference in new issue
Block a user