feat(library): 恢复验证成为可页面发起的真实作业
build / build (push) Successful in 1m40s

根因:生产可恢复性只有 PRODUCTION_BACKUP_RESTORE_VERIFIED 这个手填 env 开关,
页面没有任何入口去真跑一次恢复;CLI(librarydrill)又不是 worker 能复用的实现,
所以"已验证"既证明不了跑过、也证明不了跑的是当前目标。

改动:
- 共享实现 internal/libraryverify(维护隔离→捕获→基线校验→canary→恢复→复核→关窗口),
  cmd/librarydrill 改为薄封装,CLI 与 worker 只允许一份执行体。
- verify 成为独立业务作业:kind + VerifyStages(capture/verify/canary/restore/finalize),
  与 sync/restore/baseline 共用同一把写互斥;迁移 79 加 kind 约束、重建部分唯一索引、
  新建 library_restore_verifications(按 target_id 绑定,换库/索引/桶旧证据自动失效,
  同 target+scope+job 幂等)。
- worker:admitLibraryJob + runOwnedLibraryAttempt 之后调用共享实现,阶段实时写
  library_job_stages,结束后写真实终态;通过写 passed 证据,失败写 failed+原因(不伪成功);
  中断接管按同一作业 id 收掉维护窗口。
- API:POST/GET /api/v1/library/verifications(管理员;闸口关闭/维护中拒绝;返回完整
  整库目标、最近证据、失败原因),OpenAPI 同步。
- 闸口:同步/恢复/续作的证据判断改为读当前目标证据;历史 env 仅在证据缺失时兜底,
  证据存在时以证据为准。
- 页面:生产保护与恢复面板加「恢复验证」块(完整 KB/索引/桶、状态、最近证据、失败原因、
  管理员按钮、5s 轮询),作业类型补 verify 文案。

测试:make verify 16/16 全绿(go 1387 例 + web 454 例 + 契约/迁移/密钥/依赖锁定);
新增用例覆盖证据四条件、闸口证据优先、页面无证据/失败/通过三种呈现与管理员可见性。
This commit is contained in:
姚章浩
2026-11-03 10:14:08 +08:00
parent 4421dd38ce
commit 5e1482e349
47 changed files with 2502 additions and 353 deletions
+16 -5
View File
@@ -91,6 +91,12 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
: schedule.host_reachable
? `${schedule.host_target} · 已连接`
: `${schedule.host_target} · 连接失败`
// 只有真的连上并读回主机状态时,才能说脚本在不在;连不上是"未知"。
const scriptLine = !schedule.host_reachable
? '未知(未连上主机,未执行主机侧脚本)'
: schedule.host_script_present
? '存在'
: '缺失'
return (
<section className="settings-panel wide storage-settings-panel" id="settings-storage">
@@ -115,11 +121,12 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
<dl>
<dt>目标主机</dt>
<dd>{hostLine}</dd>
<dt>拨号地址</dt>
<dd>{schedule.host_endpoint || '—'}</dd>
<dt>备份脚本</dt>
<dd>{scriptLine}</dd>
<dt>主机 cron</dt>
<dd>
{schedule.host_cron_service ? `服务 ${schedule.host_cron_service}` : '—'}
{schedule.host_script_present ? '' : ' · 备份脚本缺失'}
</dd>
<dd>{schedule.host_cron_service ? `服务 ${schedule.host_cron_service}` : '—'}</dd>
<dt>最近一次备份</dt>
<dd>
{schedule.last_run_stamp || '—'}
@@ -213,8 +220,12 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
{busy === 'apply' ? '正在下发…' : '重新下发当前设置'}
</button>
<button onClick={onRunNow} disabled={busy !== null || !schedule.host_configured || schedule.running}>
{schedule.running ? '备份进行中…' : '立即备份一次'}
{schedule.running ? '备份进行中…' : '立即备份一次(全库,不是 scope 快照)'}
</button>
<p className="hint">
「立即备份一次」执行的是主机上的整库逻辑备份(该主机上全部业务库的 pg_dump 目录),
<strong>不是</strong>本次对内/对外 scope 的整库快照;scope 快照在「发布管理 → 整库版本」里封存。
</p>
{message ? (
<p className="success-message" role="status">
{message}