fix(backup): 宿主采集器按 du 口径去重硬链接并拒绝清单符号链接
备份目录 root:root 0700,API 不再遍历;宿主采集器只读 stat/du,原子写快照。统计包含目录自身、树内 (dev,ino) 硬链接去重,单库与整批各自独立与 du -sB1 对齐;MANIFEST 仅接受目录内常规非符号链接文件并 O_NOFOLLOW 打开。快照缺失/陈旧/不完整时批次与子库字节为 null,页面不画容量图、不使用部分字节。
This commit is contained in:
@@ -74,17 +74,37 @@ const diskFixture = (overrides: Partial<StorageDiskObservation> = {}): StorageDi
|
||||
const inventoryFixture = (overrides: Partial<BackupInventory> = {}): BackupInventory => {
|
||||
const baseInventory: BackupInventory = {
|
||||
wired: true,
|
||||
root: '/var/lib/knowledge-governance/backup-host/rds-logical',
|
||||
metadata: {
|
||||
configured: true,
|
||||
present: true,
|
||||
valid: true,
|
||||
fresh: true,
|
||||
complete: true,
|
||||
path: '/var/lib/knowledge-governance/backup-host/metadata.json',
|
||||
collected_at: '2026-11-19T03:30:00Z',
|
||||
age_seconds: 10,
|
||||
max_age_seconds: 900,
|
||||
schema_version: 1,
|
||||
generation: '20261119T033000Z-abc123',
|
||||
host: 'weknora-test',
|
||||
collector_version: 'backup-metadata/1',
|
||||
error: '',
|
||||
},
|
||||
root: '/srv/kb-backups/rds-logical',
|
||||
host_root: '/srv/kb-backups/rds-logical',
|
||||
source: 'weknora-test:/srv/kb-backups/rds-logical',
|
||||
observed_at: '2026-11-19T03:30:10Z',
|
||||
error: '',
|
||||
measurement: 'host_collector',
|
||||
mount: {
|
||||
container_root: '/',
|
||||
container_root: '',
|
||||
mount_verified: true,
|
||||
lives_on_container_root: false,
|
||||
read_only: true,
|
||||
evidence: '挂载设备 20 与容器根盘 10 不同:容量按挂载文件系统计量',
|
||||
evidence: '宿主采集器:/dev/sdb1 挂在 /srv/kb-backups(ext4),API 不遍历备份目录',
|
||||
mount_point: '/srv/kb-backups',
|
||||
device: '/dev/sdb1',
|
||||
fs_type: 'ext4',
|
||||
},
|
||||
capacity: {
|
||||
measured: true,
|
||||
@@ -118,7 +138,7 @@ const inventoryFixture = (overrides: Partial<BackupInventory> = {}): BackupInven
|
||||
present: true,
|
||||
failed: false,
|
||||
in_manifest: true,
|
||||
apparent_bytes: 696_320,
|
||||
apparent_bytes: 700_000,
|
||||
actual_bytes: 720_896,
|
||||
file_count: 12,
|
||||
},
|
||||
@@ -175,6 +195,7 @@ const inventoryFixture = (overrides: Partial<BackupInventory> = {}): BackupInven
|
||||
actual_bytes: 1_500_004_096,
|
||||
latest_stamp: '20261118T193001Z',
|
||||
latest_actual_bytes: 1_500_000_000,
|
||||
complete: true,
|
||||
},
|
||||
incomplete_count: 1,
|
||||
skipped: [{ name: 'junk', reason: '不是批次目录' }],
|
||||
@@ -229,7 +250,7 @@ describe('BackupScheduleView', () => {
|
||||
'备份执行主机 weknora-test 本机直连 RDS',
|
||||
'最近批次含 2 个数据库',
|
||||
'weknora-test 本地备份根目录',
|
||||
'备份目录未接线或不可读,不在页面猜测',
|
||||
'元数据快照未接线或不可用,不在页面猜测',
|
||||
'整批 · 2 个数据库(weknora_test、dobotai_prod)',
|
||||
'100.85.111.121:22',
|
||||
'立即备份一次(整批 2 个数据库)',
|
||||
@@ -261,7 +282,7 @@ describe('BackupScheduleView', () => {
|
||||
it('目录/配额/预留没有后端字段:控件禁用并写明原因,不会假装可保存', () => {
|
||||
const html = view()
|
||||
expect(html).toContain('备份主机上的目录')
|
||||
expect(html).toContain('只读盘点未接线')
|
||||
expect(html).toContain('元数据快照未接线')
|
||||
expect(html).toContain('检查目录(不可用)')
|
||||
expect(html).toContain('备份总配额(GiB)')
|
||||
expect(html).toContain('磁盘预留(GiB)')
|
||||
@@ -270,11 +291,11 @@ describe('BackupScheduleView', () => {
|
||||
expect(html).toContain('disabled')
|
||||
})
|
||||
|
||||
it('只读盘点:展示全部批次、MANIFEST 状态、子库完整路径与实际占盘', () => {
|
||||
it('宿主快照:展示全部批次、MANIFEST 状态、子库完整路径与实际占盘', () => {
|
||||
const html = view({}, { inventory: inventoryFixture() })
|
||||
for (const text of [
|
||||
'备份记录',
|
||||
'2 批 · 只读盘点',
|
||||
'2 批 · 元数据快照',
|
||||
'最近批次 20261118T193001Z',
|
||||
'清单完整',
|
||||
'清单损坏',
|
||||
@@ -299,32 +320,41 @@ describe('BackupScheduleView', () => {
|
||||
expect(html).not.toContain('复制目录(不可用)')
|
||||
})
|
||||
|
||||
it('没有只读盘点:不展示任何历史批次或伪造路径', () => {
|
||||
it('没有快照:不展示任何历史批次或伪造路径', () => {
|
||||
const html = view()
|
||||
expect(html).toContain('尚未读取只读盘点')
|
||||
expect(html).toContain('尚未读取宿主元数据快照')
|
||||
expect(html).not.toContain('批次戳')
|
||||
expect(html).not.toContain('/srv/kb-backups/rds-logical')
|
||||
})
|
||||
|
||||
it('盘点未接线:说明与 SSH 计划读回独立,未读到不等于没有备份', () => {
|
||||
it('快照未接线:说明与 SSH 计划读回独立,未读到不等于没有备份', () => {
|
||||
const base = inventoryFixture()
|
||||
const html = view(
|
||||
{},
|
||||
{
|
||||
inventory: inventoryFixture({
|
||||
wired: false,
|
||||
error: '只读盘点未接线(BACKUP_HOST_READONLY_ROOT 未设置)',
|
||||
metadata: {
|
||||
...base.metadata,
|
||||
configured: false,
|
||||
present: false,
|
||||
valid: false,
|
||||
fresh: false,
|
||||
complete: false,
|
||||
error: '元数据快照未接线(BACKUP_HOST_METADATA_PATH 未设置)',
|
||||
},
|
||||
error: '元数据快照未接线(BACKUP_HOST_METADATA_PATH 未设置)',
|
||||
batches: [],
|
||||
capacity: { measured: false, total_bytes: 0, free_bytes: 0, available_bytes: 0, used_bytes: 0 },
|
||||
}),
|
||||
}
|
||||
)
|
||||
expect(html).toContain('只读盘点未接线')
|
||||
expect(html).toContain('元数据快照未接线')
|
||||
expect(html).toContain('未读到批次不等于没有备份')
|
||||
expect(html).toContain('文件盘点未接线')
|
||||
expect(html).not.toContain('/srv/kb-backups/rds-logical/20261118T193001Z')
|
||||
})
|
||||
|
||||
it('挂载可读但没有批次时说明不能据此判断成功/失败', () => {
|
||||
it('快照可读但没有批次时说明不能据此判断成功/失败', () => {
|
||||
const html = view(
|
||||
{
|
||||
last_run_stamp: '',
|
||||
@@ -343,11 +373,12 @@ describe('BackupScheduleView', () => {
|
||||
actual_bytes: 0,
|
||||
latest_stamp: '',
|
||||
latest_actual_bytes: 0,
|
||||
complete: true,
|
||||
},
|
||||
}),
|
||||
}
|
||||
)
|
||||
expect(html).toContain('挂载可读,但没有批次目录')
|
||||
expect(html).toContain('宿主快照可读,但没有批次目录')
|
||||
expect(html).toContain('不能证明备份成功或失败')
|
||||
})
|
||||
|
||||
@@ -402,7 +433,7 @@ describe('BackupScheduleView', () => {
|
||||
expect(html).toContain('weknora-test · 连接失败')
|
||||
expect(html).toContain('120.76.217.51:22')
|
||||
expect(html).toContain('未知(未连上主机,未执行主机侧脚本)')
|
||||
expect(html).not.toContain('缺失')
|
||||
expect(html).not.toContain('<dt>备份脚本</dt><dd>缺失</dd>')
|
||||
expect(html).toContain('主机连不上:以下"主机生效"状态未知')
|
||||
expect(html).toContain('无法比对(主机不可达)')
|
||||
})
|
||||
@@ -451,18 +482,20 @@ describe('BackupScheduleView', () => {
|
||||
expect(runMoment({ last_run_stamp: '20261009T060736Z', last_run_created_at: '2026-10-09T06:07:36Z' })).not.toBe('')
|
||||
})
|
||||
|
||||
it('体积格式化:MiB/GiB', () => {
|
||||
expect(formatBackupBytes(0)).toBe('—')
|
||||
it('体积格式化:未知与零分开', () => {
|
||||
expect(formatBackupBytes(0)).toBe('0 B')
|
||||
expect(formatBackupBytes(null)).toBe('—')
|
||||
expect(formatBackupBytes(undefined)).toBe('—')
|
||||
expect(formatBackupBytes(1024 * 1024)).toBe('1.0 MiB')
|
||||
expect(formatBackupBytes(2 * 1024 * 1024 * 1024)).toBe('2.00 GiB')
|
||||
})
|
||||
})
|
||||
|
||||
describe('整盘占用与告警', () => {
|
||||
it('没有只读盘点时:不显示示例容量,四条告警只报未知原因', () => {
|
||||
it('没有快照时:不显示示例容量,四条告警只报未知原因', () => {
|
||||
const html = view()
|
||||
expect(html).toContain('未接线 · 不显示估算容量')
|
||||
expect(html).toContain('容量来自只读挂载目录的 statfs 实测')
|
||||
expect(html).toContain('占盘未知 · 不使用部分字节')
|
||||
expect(html).toContain('宿主单项元数据采集器')
|
||||
expect(html).toContain('无法判定')
|
||||
expect(html).toContain('整盘总量 / 空闲 / 备份实际占盘:未接线')
|
||||
// 原型里的示例容量不能被当成产品事实带进来。
|
||||
@@ -521,7 +554,7 @@ describe('整盘占用与告警', () => {
|
||||
expect(alerts.filter((item) => !item.known).map((item) => item.code)).toEqual(['disk_low', 'quota_low', 'both_low'])
|
||||
})
|
||||
|
||||
it('真实盘点:整盘色带取 statfs 容量与 st_blocks 实际占盘', () => {
|
||||
it('真实快照:整盘色带取采集器容量与 st_blocks 实际占盘', () => {
|
||||
const inventory = inventoryFixture()
|
||||
const usage = inventoryUsage(inventory)
|
||||
expect(usage).not.toBeNull()
|
||||
@@ -535,35 +568,51 @@ describe('整盘占用与告警', () => {
|
||||
expect(alerts.find((item) => item.code === 'quota_low')?.known).toBe(false)
|
||||
const html = view({}, { inventory })
|
||||
for (const text of [
|
||||
'只读挂载实测',
|
||||
'宿主采集器实测',
|
||||
'系统其他占用',
|
||||
'备份实际占盘',
|
||||
'可用',
|
||||
'配额内/外 —(无配额字段)',
|
||||
'文件系统已用',
|
||||
'挂载为只读',
|
||||
'挂载设备 20 与容器根盘 10 不同',
|
||||
'只读挂载',
|
||||
'宿主采集器:/dev/sdb1 挂在 /srv/kb-backups',
|
||||
])
|
||||
expect(html).toContain(text)
|
||||
})
|
||||
|
||||
it('挂载落在容器根盘:不把容器容量当主机磁盘,磁盘告警保持未知', () => {
|
||||
it('不完整快照:容量图与占盘不使用部分字节', () => {
|
||||
const base = inventoryFixture()
|
||||
const inventory = inventoryFixture({
|
||||
mount: {
|
||||
container_root: '/',
|
||||
mount_verified: false,
|
||||
lives_on_container_root: true,
|
||||
read_only: true,
|
||||
evidence: '挂载设备与容器根盘相同(7):容量不代表备份主机磁盘',
|
||||
metadata: {
|
||||
...base.metadata,
|
||||
complete: false,
|
||||
error: '采集不完整:遍历失败:PermissionError: Permission denied',
|
||||
},
|
||||
capacity: { measured: false, total_bytes: 0, free_bytes: 0, available_bytes: 0, used_bytes: 0 },
|
||||
totals: { ...base.totals, apparent_bytes: null, actual_bytes: null, latest_actual_bytes: null, complete: false },
|
||||
batches: base.batches.map((batch) => ({
|
||||
...batch,
|
||||
apparent_bytes: null,
|
||||
actual_bytes: null,
|
||||
file_count: null,
|
||||
sizes_complete: false,
|
||||
sizes_error: '宿主采集器该项不完整,占盘未知',
|
||||
databases: batch.databases.map((database) => ({
|
||||
...database,
|
||||
apparent_bytes: null,
|
||||
actual_bytes: null,
|
||||
file_count: null,
|
||||
})),
|
||||
})),
|
||||
})
|
||||
expect(inventoryUsage(inventory)).toBeNull()
|
||||
const alerts = inventoryAlerts(inventory)
|
||||
expect(alerts.find((item) => item.code === 'disk_low')?.known).toBe(false)
|
||||
expect(alerts.find((item) => item.code === 'disk_low')?.detail).toContain('容器根盘')
|
||||
expect(alerts.find((item) => item.code === 'disk_low')?.detail).toContain('不完整')
|
||||
const html = view({}, { inventory })
|
||||
expect(html).toContain('容器根盘 · 不代表主机磁盘')
|
||||
expect(html).toContain('不据此判定备份主机磁盘')
|
||||
expect(html).toContain('占盘未知 · 不使用部分字节')
|
||||
expect(html).toContain('采集快照不完整:所有批次占盘与容量未知')
|
||||
expect(html).toContain('占盘未知(采集不完整)')
|
||||
expect(html).not.toContain('备份实际占盘 1.40 GiB')
|
||||
})
|
||||
|
||||
|
||||
@@ -13,8 +13,9 @@ import { fetchBackupInventory } from './backupInventory'
|
||||
import type { BackupInventory, BackupInventoryBatch } from './backupInventory'
|
||||
import './storageBackup.css'
|
||||
|
||||
export const formatBackupBytes = (bytes: number): string => {
|
||||
if (!bytes) return '—'
|
||||
export const formatBackupBytes = (bytes: number | null | undefined): string => {
|
||||
if (bytes === null || bytes === undefined || !Number.isFinite(bytes) || bytes < 0) return '—'
|
||||
if (bytes === 0) return '0 B'
|
||||
const mib = bytes / (1024 * 1024)
|
||||
return mib >= 1024 ? `${(mib / 1024).toFixed(2)} GiB` : `${mib.toFixed(1)} MiB`
|
||||
}
|
||||
@@ -206,18 +207,27 @@ export interface InventoryUsage {
|
||||
system_other: number
|
||||
}
|
||||
|
||||
// 只读挂载 + 实测容量 + 文件系统与容器根盘分离,三者同时成立才画整盘图。
|
||||
// 备份实际占盘取所有批次的 st_blocks 合计,不是 MANIFEST 的表观字节。
|
||||
// 完整新鲜的宿主快照 + 实测容量 + 采集器给出的文件系统,才画整盘图。
|
||||
// 备份实际占盘取快照的总实际分配,不是 MANIFEST 表观字节,也不接受部分字节。
|
||||
export function inventoryUsage(inventory: BackupInventory | null): InventoryUsage | null {
|
||||
if (
|
||||
!inventory ||
|
||||
!inventory.wired ||
|
||||
!inventory.metadata.present ||
|
||||
!inventory.metadata.valid ||
|
||||
!inventory.metadata.fresh ||
|
||||
!inventory.metadata.complete ||
|
||||
!inventory.mount.mount_verified ||
|
||||
!inventory.capacity.measured ||
|
||||
inventory.capacity.total_bytes <= 0
|
||||
inventory.capacity.total_bytes <= 0 ||
|
||||
inventory.totals.actual_bytes === null ||
|
||||
inventory.totals.actual_bytes === undefined
|
||||
) {
|
||||
return null
|
||||
}
|
||||
if (inventory.batches.some((batch) => !batch.sizes_complete || batch.actual_bytes === null)) {
|
||||
return null
|
||||
}
|
||||
const total = inventory.capacity.total_bytes
|
||||
const used = Math.max(0, inventory.capacity.used_bytes)
|
||||
const backup = Math.max(0, inventory.totals.actual_bytes)
|
||||
@@ -236,20 +246,29 @@ export function inventoryAlerts(inventory: BackupInventory | null): StorageAlert
|
||||
const usage = inventoryUsage(inventory)
|
||||
const latest = inventory?.batches[0]
|
||||
const capacityKnown = Boolean(usage)
|
||||
const latestBytes = latest?.actual_bytes ?? 0
|
||||
const diskKnown = capacityKnown && latestBytes > 0
|
||||
const diskActive = diskKnown && latestBytes > usage!.free
|
||||
const latestBytes = latest?.actual_bytes ?? null
|
||||
const diskKnown =
|
||||
capacityKnown && latest !== undefined && latest.sizes_complete && latestBytes !== null && latestBytes !== undefined
|
||||
const diskActive = diskKnown && latestBytes! > usage!.free
|
||||
const diskDetail = !inventory
|
||||
? '尚未读取备份目录'
|
||||
? '尚未读取宿主元数据快照'
|
||||
: !inventory.wired
|
||||
? '只读盘点未接线'
|
||||
: !inventory.mount.mount_verified
|
||||
? '目录位于容器根盘,读数不代表备份主机磁盘'
|
||||
: !inventory.capacity.measured
|
||||
? inventory.capacity.error || '未读到文件系统容量'
|
||||
: latestBytes <= 0
|
||||
? '没有可参考的批次实际占盘'
|
||||
: `剩余可用 ${formatGib(usage!.free)} GiB,最近一批实际占盘 ${formatGib(latestBytes)} GiB(参考值,不含策略预留)`
|
||||
? '元数据快照未接线'
|
||||
: !inventory.metadata.present
|
||||
? '元数据快照缺失'
|
||||
: !inventory.metadata.valid
|
||||
? inventory.metadata.error || '元数据快照无效'
|
||||
: !inventory.metadata.fresh
|
||||
? '元数据快照已陈旧'
|
||||
: !inventory.metadata.complete
|
||||
? '元数据快照不完整:占盘与容量未知'
|
||||
: !inventory.mount.mount_verified
|
||||
? '宿主采集器未给出可用文件系统'
|
||||
: !inventory.capacity.measured
|
||||
? inventory.capacity.error || '未读到文件系统容量'
|
||||
: latestBytes === null || latestBytes === undefined
|
||||
? '最近批次占盘未知'
|
||||
: `剩余可用 ${formatGib(usage!.free)} GiB,最近一批实际占盘 ${formatGib(latestBytes)} GiB(参考值,不含策略预留)`
|
||||
return [
|
||||
{
|
||||
code: 'disk_low',
|
||||
@@ -308,6 +327,9 @@ export async function copyBackupPath(value: string, button?: HTMLButtonElement |
|
||||
const manifestLabel = (batch: BackupInventoryBatch): string =>
|
||||
batch.manifest_state === 'ok' ? '清单完整' : batch.manifest_state === 'missing' ? '清单缺失' : '清单损坏'
|
||||
|
||||
const inventoryMetadataAvailable = (inventory: BackupInventory): boolean =>
|
||||
inventory.metadata.present && inventory.metadata.valid && inventory.metadata.fresh
|
||||
|
||||
// 备份执行主机上的整库逻辑备份(全部业务库一次 pg_dump)。
|
||||
// 页面只展示接口真实给出的读数;目录、配额、预留、子库路径、历史批次与恢复
|
||||
// 验证在后端契约里还没有字段,保留原型位置并写明"未接线"。
|
||||
@@ -407,8 +429,13 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
const alerts = disk ? storageAlerts(disk) : inventoryAlerts(inventory)
|
||||
const latestBatch: BackupInventoryBatch | null = inventory?.batches[0] ?? null
|
||||
const inventoryFigure = inventoryUsage(inventory)
|
||||
const inventoryReady = Boolean(inventory?.wired && !inventory.error)
|
||||
const readyInventory = inventory && inventory.wired && !inventory.error ? inventory : null
|
||||
const inventoryReady = Boolean(
|
||||
inventory?.wired && inventory.metadata.present && inventory.metadata.valid && inventory.metadata.fresh
|
||||
)
|
||||
const readyInventory =
|
||||
inventory && inventory.wired && inventory.metadata.present && inventory.metadata.valid && inventory.metadata.fresh
|
||||
? inventory
|
||||
: null
|
||||
const inventoryDatabases = latestBatch?.databases.map((item) => item.name) ?? []
|
||||
const scopeDatabases = inventoryDatabases.length ? inventoryDatabases : schedule.last_run_databases
|
||||
const scopeDatabaseCount = scopeDatabases.length
|
||||
@@ -443,12 +470,14 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
</span>
|
||||
<span className={`storage-chip ${inventoryReady ? 'ok' : 'off'}`}>
|
||||
{inventoryLoading
|
||||
? '文件盘点读取中'
|
||||
? '元数据读取中'
|
||||
: inventoryReady
|
||||
? '文件盘点已接线'
|
||||
: inventory?.error
|
||||
? '文件盘点不可读'
|
||||
: '文件盘点未接线'}
|
||||
? inventory?.metadata.complete
|
||||
? '元数据快照有效'
|
||||
: '元数据快照不完整'
|
||||
: inventory?.metadata.error
|
||||
? '元数据快照不可用'
|
||||
: '元数据未接线'}
|
||||
</span>
|
||||
</div>
|
||||
<dl className="storage-facts">
|
||||
@@ -461,7 +490,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
<dd>
|
||||
{inventory?.host_root || `${schedule.host_target || '(未配置)'} 本地备份根目录`}
|
||||
<span className="storage-inline-note">
|
||||
{inventoryReady ? '只读挂载盘点;平台没有写路径' : '备份目录未接线或不可读,不在页面猜测'}
|
||||
{inventoryReady ? '宿主采集器快照(只读);平台没有写路径' : '元数据快照未接线或不可用,不在页面猜测'}
|
||||
</span>
|
||||
</dd>
|
||||
<dt>执行范围</dt>
|
||||
@@ -480,7 +509,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
<p className="hint">
|
||||
<code>POST /api/v1/backup-schedule/run</code> 没有单库参数,一次就是该主机全部业务库的整批
|
||||
pg_dump。用单库按钮触发会连整批一起跑,因此本页不开放单库动作;单库恢复请复制「备份记录」里该库的
|
||||
完整子目录(来自只读盘点),不要自己拼路径。
|
||||
完整子目录(来自宿主元数据快照),不要自己拼路径。
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
@@ -496,9 +525,13 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
</div>
|
||||
<p>
|
||||
{latestBatch
|
||||
? `最近一批 ${latestBatch.stamp} · ${formatBackupMoment(latestBatch.created_at)} · ${scopeDatabaseCount} 个数据库 · 表观 ${formatBackupBytes(latestBatch.apparent_bytes)} · 实际占盘 ${formatBackupBytes(latestBatch.actual_bytes)} · ${latestBatch.duration_seconds} 秒`
|
||||
? `最近一批 ${latestBatch.stamp} · ${formatBackupMoment(latestBatch.created_at)} · ${scopeDatabaseCount} 个数据库 · 表观 ${formatBackupBytes(latestBatch.apparent_bytes)} · ${
|
||||
latestBatch.actual_bytes === null
|
||||
? '实际占盘未知(采集不完整)'
|
||||
: `实际占盘 ${formatBackupBytes(latestBatch.actual_bytes)}`
|
||||
} · ${latestBatch.duration_seconds} 秒`
|
||||
: hasLastRun
|
||||
? `SSH 读回最近一次 ${schedule.last_run_stamp} · ${databaseCount} 个数据库 · ${formatBackupBytes(schedule.last_run_total_bytes)}(文件盘点未接线,以下仅 SSH 结果)`
|
||||
? `SSH 读回最近一次 ${schedule.last_run_stamp} · ${databaseCount} 个数据库 · ${formatBackupBytes(schedule.last_run_total_bytes)}(元数据快照未接线,以下仅 SSH 结果)`
|
||||
: '还没有从主机读到任何批次。'}
|
||||
</p>
|
||||
{schedule.running ? (
|
||||
@@ -540,15 +573,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
<div className="storage-block-heading">
|
||||
<h3 id="storage-disk-heading">整盘占用与告警</h3>
|
||||
<span className="storage-chip off">
|
||||
{usage
|
||||
? '已读到主机读数'
|
||||
: inventoryFigure
|
||||
? inventory?.mount.read_only
|
||||
? '只读挂载实测'
|
||||
: '实测(挂载可写)'
|
||||
: inventory?.capacity.measured
|
||||
? '容器根盘(不可作主机容量)'
|
||||
: '未接线'}
|
||||
{usage ? '已读到主机读数' : inventoryFigure ? '宿主采集器实测' : '占盘未知'}
|
||||
</span>
|
||||
</div>
|
||||
{usage && disk ? (
|
||||
@@ -652,33 +677,19 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
)· 文件系统已用 {formatGib(inventoryFigure.used)} GiB · 可用 {formatGib(inventoryFigure.free)} GiB
|
||||
</p>
|
||||
<small>
|
||||
{inventory.mount.evidence} · 挂载点 {inventory.root} · 采集于 {formatBackupMoment(inventory.observed_at)}
|
||||
{inventory.mount.read_only ? ' · 挂载为只读' : ' · 挂载不是只读(部署需改 :ro)'}
|
||||
{inventory.mount.evidence} · 挂载点 {inventory.mount.mount_point || '—'} · 采集于{' '}
|
||||
{formatBackupMoment(inventory.metadata.collected_at || inventory.observed_at)}
|
||||
{inventory.mount.read_only ? ' · 只读挂载' : ' · 挂载可写(采集器只读)'}
|
||||
</small>
|
||||
</>
|
||||
) : inventory?.capacity.measured ? (
|
||||
<>
|
||||
<div
|
||||
className="storage-disk-track storage-disk-track-unknown"
|
||||
role="img"
|
||||
aria-label="目录位于容器根盘,容量不代表备份主机磁盘"
|
||||
>
|
||||
<span>容器根盘 · 不代表主机磁盘</span>
|
||||
</div>
|
||||
<p className="storage-metric">
|
||||
容器根盘实测 {formatGib(inventory.capacity.total_bytes)} GiB,可用{' '}
|
||||
{formatGib(inventory.capacity.available_bytes)} GiB:仅作排障,不据此判定备份主机磁盘。
|
||||
</p>
|
||||
<small>{inventory.mount.evidence}</small>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div
|
||||
className="storage-disk-track storage-disk-track-unknown"
|
||||
role="img"
|
||||
aria-label="整盘占用未接线:没有可读的只读挂载"
|
||||
aria-label="整盘占用未知:没有完整新鲜的宿主快照"
|
||||
>
|
||||
<span>{inventoryLoading ? '正在读取只读挂载…' : '未接线 · 不显示估算容量'}</span>
|
||||
<span>{inventoryLoading ? '正在读取宿主元数据快照…' : '占盘未知 · 不使用部分字节'}</span>
|
||||
</div>
|
||||
<div className="storage-disk-legend">
|
||||
{['系统其他占用', '备份实际占盘', '可用', '配额内/外'].map((label, index) => (
|
||||
@@ -689,14 +700,15 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
))}
|
||||
</div>
|
||||
<p className="storage-metric">
|
||||
整盘总量 / 空闲 / 备份实际占盘:{inventoryError || inventory?.error || '未接线'}
|
||||
整盘总量 / 空闲 / 备份实际占盘:
|
||||
{inventoryError || inventory?.metadata.error || inventory?.error || '未接线'}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<p className="hint">
|
||||
容量来自只读挂载目录的 statfs 实测,并与容器根盘比较设备号;同一设备时不把容器容量当主机容量。 备份占盘按文件
|
||||
st_blocks 统计(实际分配),不是 MANIFEST 的表观字节。配额与策略预留仍无后端字段,
|
||||
四项告警中只有磁盘项能按实测判定。
|
||||
容量与实际占盘来自宿主单项元数据采集器(stat/du 元数据,不读数据库内容);API 不遍历备份目录。
|
||||
快照陈旧、缺失或不完整时,容量图与任何可写预测都不使用部分字节。配额与策略预留仍无后端字段,
|
||||
四项告警中只有磁盘项能按完整快照判定。
|
||||
</p>
|
||||
<p className="storage-alert-summary">{storageAlertSummary(alerts)}</p>
|
||||
<ul className="storage-alerts">
|
||||
@@ -742,7 +754,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
value={inventory?.host_root || ''}
|
||||
readOnly
|
||||
disabled
|
||||
placeholder={inventoryReady ? '' : '只读盘点未接线'}
|
||||
placeholder={inventoryReady ? '' : '元数据快照未接线'}
|
||||
aria-label="备份主机上的目录(只读展示)"
|
||||
/>
|
||||
</label>
|
||||
@@ -752,8 +764,8 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
</button>
|
||||
<span className="hint">
|
||||
{inventoryReady
|
||||
? '目录来自只读挂载来源,只读展示;修改目录需部署变更,平台没有写接口。'
|
||||
: '只读盘点未接线:目录不可证明,不能按设置推定。'}
|
||||
? '目录来自宿主元数据快照,只读展示;修改目录需部署变更,平台没有写接口。'
|
||||
: '元数据快照未接线:目录不可证明,不能按设置推定。'}
|
||||
</span>
|
||||
</div>
|
||||
<label className="storage-checkbox">
|
||||
@@ -858,41 +870,53 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
<h3 id="storage-runs-heading">备份记录</h3>
|
||||
<span className="hint">
|
||||
{readyInventory
|
||||
? `${readyInventory.totals.batch_count} 批 · 只读盘点 · 实际占盘 ${formatBackupBytes(readyInventory.totals.actual_bytes)}`
|
||||
: '只读盘点'}
|
||||
? `${readyInventory.totals.batch_count} 批 · 元数据快照 · 实际占盘 ${formatBackupBytes(readyInventory.totals.actual_bytes)}`
|
||||
: '元数据快照'}
|
||||
</span>
|
||||
<button type="button" onClick={onReloadInventory} disabled={inventoryLoading}>
|
||||
{inventoryLoading ? '盘点中…' : '重新盘点'}
|
||||
{inventoryLoading ? '读取中…' : '重新读取快照'}
|
||||
</button>
|
||||
</div>
|
||||
{inventoryLoading && !inventory ? <p className="hint">正在读取只读挂载与 MANIFEST…</p> : null}
|
||||
{inventoryLoading && !inventory ? <p className="hint">正在读取宿主元数据快照…</p> : null}
|
||||
{inventoryError ? (
|
||||
<p className="error-message" role="alert">
|
||||
盘点请求失败:{inventoryError}。不能用 SSH 的“最近一次”代替历史;请检查 API 到只读挂载的接线。
|
||||
快照请求失败:{inventoryError}。不能用 SSH 的“最近一次”代替历史;请检查 API 到快照挂载的接线。
|
||||
</p>
|
||||
) : null}
|
||||
{inventory && !inventory.wired ? (
|
||||
<p className="hint">
|
||||
只读盘点未接线:{inventory.error}。部署需把备份目录以 <code>:ro</code> 挂进 API (见
|
||||
元数据快照未接线:{inventory.metadata.error}。部署需在备份主机运行单次采集器并把输出目录只读挂进 API(见
|
||||
docs/STORAGE_BACKUP_READONLY_API.md);未读到批次不等于没有备份。
|
||||
</p>
|
||||
) : null}
|
||||
{inventory && inventory.wired && inventory.error ? (
|
||||
{inventory && inventory.wired && !inventoryMetadataAvailable(inventory) ? (
|
||||
<p className="error-message" role="alert">
|
||||
只读目录不可读:{inventory.error}
|
||||
元数据快照不可用:{inventory.metadata.error || inventory.error || '缺失/陈旧/无效'}
|
||||
</p>
|
||||
) : null}
|
||||
{readyInventory ? (
|
||||
<>
|
||||
<p className="hint">
|
||||
最近批次 {readyInventory.totals.latest_stamp || '—'} · 共 {readyInventory.totals.batch_count} 批 /{' '}
|
||||
{readyInventory.totals.database_count} 个子库 · 表观{' '}
|
||||
{formatBackupBytes(readyInventory.totals.apparent_bytes)} · 实际占盘{' '}
|
||||
{formatBackupBytes(readyInventory.totals.actual_bytes)}。批次与路径来自只读目录,不依赖 SSH 计划读回。
|
||||
{readyInventory.totals.database_count} 个子库 ·{' '}
|
||||
{readyInventory.metadata.complete && readyInventory.totals.actual_bytes !== null ? (
|
||||
<>
|
||||
表观 {formatBackupBytes(readyInventory.totals.apparent_bytes)} · 实际占盘{' '}
|
||||
{formatBackupBytes(readyInventory.totals.actual_bytes)}。
|
||||
</>
|
||||
) : (
|
||||
<>采集快照不完整:所有批次占盘与容量未知。</>
|
||||
)}{' '}
|
||||
路径来自宿主快照,不依赖 SSH 计划读回。
|
||||
</p>
|
||||
<p className="hint">
|
||||
采集于 {formatBackupMoment(readyInventory.metadata.collected_at)} · 年龄{' '}
|
||||
{readyInventory.metadata.age_seconds} 秒 / 上限 {readyInventory.metadata.max_age_seconds} 秒 · 宿主{' '}
|
||||
{readyInventory.metadata.host || '—'} · 快照 {readyInventory.metadata.generation || '—'}
|
||||
</p>
|
||||
{readyInventory.batches.length === 0 ? (
|
||||
<p className="hint">
|
||||
挂载可读,但没有批次目录(可能尚未执行,或挂载到了空目录);这不能证明备份成功或失败。
|
||||
宿主快照可读,但没有批次目录(可能尚未执行,或采集到空目录);这不能证明备份成功或失败。
|
||||
</p>
|
||||
) : null}
|
||||
{readyInventory.batches.map((batch, index) => {
|
||||
@@ -907,25 +931,28 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
<strong className={failedDatabases.length || batch.manifest_state !== 'ok' ? 'off' : 'ok'}>
|
||||
{failedDatabases.length
|
||||
? `有失败 ${failedDatabases.length} 个`
|
||||
: `实际占盘 ${formatBackupBytes(batch.actual_bytes)}`}
|
||||
: batch.actual_bytes === null
|
||||
? '占盘未知(采集不完整)'
|
||||
: `实际占盘 ${formatBackupBytes(batch.actual_bytes)}`}
|
||||
</strong>
|
||||
</summary>
|
||||
<p>
|
||||
批次戳 {batch.stamp} · 表观 {formatBackupBytes(batch.apparent_bytes)} · 实际占盘{' '}
|
||||
{formatBackupBytes(batch.actual_bytes)} · {batch.file_count} 个文件
|
||||
{batch.actual_bytes === null ? '未知' : formatBackupBytes(batch.actual_bytes)} ·{' '}
|
||||
{batch.file_count ?? '—'} 个文件
|
||||
{batch.duration_seconds ? ` · 耗时 ${batch.duration_seconds} 秒` : ''}
|
||||
{batch.kind ? ` · ${batch.kind}` : ''}
|
||||
</p>
|
||||
{batch.manifest_state === 'ok' ? null : (
|
||||
<p className="error-message">
|
||||
{batch.manifest_state === 'missing'
|
||||
? '此批次没有 MANIFEST.json:只能按目录统计占盘,无法确认完整性、耗时与库列表。'
|
||||
: `此批次清单损坏:${batch.manifest_error || '无法解析'};只能按目录统计占盘。`}
|
||||
? '此批次没有 MANIFEST.json:完整性、耗时与库列表无法确认;占盘仅在快照完整时可信。'
|
||||
: `此批次清单损坏:${batch.manifest_error || '无法解析'};库列表来自目录名,占盘仅在快照完整时可信。`}
|
||||
</p>
|
||||
)}
|
||||
{!batch.sizes_complete ? (
|
||||
<p className="error-message">
|
||||
实际占盘未扫全:{batch.sizes_error || '文件数超过上限'};显示的是已扫描部分。
|
||||
采集不完整:占盘未知({batch.sizes_error || '宿主采集器未给出完整统计'});不使用部分字节。
|
||||
</p>
|
||||
) : null}
|
||||
<div className="storage-path-row">
|
||||
@@ -934,7 +961,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
<button
|
||||
type="button"
|
||||
disabled={!batch.host_path}
|
||||
title={batch.host_path ? '复制完整主机路径' : '没有主机路径(只读盘点未配置主机根)'}
|
||||
title={batch.host_path ? '复制完整主机路径' : '没有主机路径(快照未配置主机根)'}
|
||||
onClick={(event) => void copyBackupPath(batch.host_path, event.currentTarget)}
|
||||
>
|
||||
复制目录
|
||||
@@ -949,7 +976,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
</span>
|
||||
<small>
|
||||
实际 {formatBackupBytes(database.actual_bytes)} · 表观{' '}
|
||||
{formatBackupBytes(database.apparent_bytes)} · {database.file_count} 个文件
|
||||
{formatBackupBytes(database.apparent_bytes)} · {database.file_count ?? '—'} 个文件
|
||||
{database.in_manifest ? '' : ' · 不在清单库列表'}
|
||||
</small>
|
||||
<div className="storage-path-row storage-sublibrary-path">
|
||||
@@ -983,14 +1010,16 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
{readyInventory.skipped.map((item) => `${item.name}(${item.reason})`).join(';')}
|
||||
</p>
|
||||
) : null}
|
||||
{readyInventory.truncated ? <p className="hint">目录或文件数超过扫描上限,列表与占盘为部分结果。</p> : null}
|
||||
{readyInventory.truncated ? (
|
||||
<p className="hint">快照被截断:批次或文件超过采集上限,占盘未知(不使用部分结果)。</p>
|
||||
) : null}
|
||||
<p className="hint">
|
||||
盘点采集于 {formatBackupMoment(readyInventory.observed_at)} · 挂载点 {readyInventory.root || '—'} · 来源{' '}
|
||||
{readyInventory.source || '—'}
|
||||
快照采集于 {formatBackupMoment(readyInventory.metadata.collected_at)} · 快照文件{' '}
|
||||
{readyInventory.metadata.path || '—'} · 来源 {readyInventory.source || '—'}
|
||||
</p>
|
||||
</>
|
||||
) : null}
|
||||
{!inventory && !inventoryLoading && !inventoryError ? <p className="hint">尚未读取只读盘点。</p> : null}
|
||||
{!inventory && !inventoryLoading && !inventoryError ? <p className="hint">尚未读取宿主元数据快照。</p> : null}
|
||||
</section>
|
||||
|
||||
<section className="storage-block" aria-labelledby="storage-host-heading">
|
||||
@@ -1035,7 +1064,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
|
||||
{schedule.last_run_stamp ? (runFailed ? ' · 有失败/读取错误' : ' · 成功') : ''}
|
||||
</dd>
|
||||
<dt>最近一次成功</dt>
|
||||
<dd>未从主机读取(不能用最近一次运行代替成功;历史批次以「备份记录」的只读盘点为准)</dd>
|
||||
<dd>未从主机读取(不能用最近一次运行代替成功;历史批次以「备份记录」的元数据快照为准)</dd>
|
||||
<dt>备份耗时 / 体积</dt>
|
||||
<dd>
|
||||
{schedule.last_run_stamp
|
||||
@@ -1285,7 +1314,7 @@ export function BackupScheduleSection() {
|
||||
inventoryLoading={inventoryLoading}
|
||||
inventoryError={inventoryError}
|
||||
onReloadInventory={() => void loadInventory()}
|
||||
// disk 不传:生产只认只读挂载盘点;disk 仅测试夹具用于验证告警分支。
|
||||
// disk 不传:生产只认宿主元数据快照;disk 仅测试夹具用于验证告警分支。
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,16 +5,36 @@ import { fetchBackupInventory } from './backupInventory'
|
||||
const payload = {
|
||||
data: {
|
||||
wired: true,
|
||||
root: '/var/lib/knowledge-governance/backup-host/rds-logical',
|
||||
metadata: {
|
||||
configured: true,
|
||||
present: true,
|
||||
valid: true,
|
||||
fresh: true,
|
||||
complete: true,
|
||||
path: '/var/lib/knowledge-governance/backup-host/metadata.json',
|
||||
collected_at: '2026-11-19T03:30:00Z',
|
||||
age_seconds: 10,
|
||||
max_age_seconds: 900,
|
||||
schema_version: 1,
|
||||
generation: '20261119T033000Z-abc123',
|
||||
host: 'weknora-test',
|
||||
collector_version: 'backup-metadata/1',
|
||||
error: '',
|
||||
},
|
||||
root: '/srv/kb-backups/rds-logical',
|
||||
host_root: '/srv/kb-backups/rds-logical',
|
||||
source: 'weknora-test:/srv/kb-backups/rds-logical',
|
||||
observed_at: '2026-11-19T03:30:10Z',
|
||||
measurement: 'host_collector',
|
||||
mount: {
|
||||
container_root: '/',
|
||||
container_root: '',
|
||||
mount_verified: true,
|
||||
lives_on_container_root: false,
|
||||
read_only: true,
|
||||
evidence: '挂载设备 20 与容器根盘 10 不同',
|
||||
evidence: '宿主采集器:/dev/sdb1 挂在 /srv/kb-backups(ext4)',
|
||||
mount_point: '/srv/kb-backups',
|
||||
device: '/dev/sdb1',
|
||||
fs_type: 'ext4',
|
||||
},
|
||||
capacity: {
|
||||
measured: true,
|
||||
@@ -46,7 +66,7 @@ const payload = {
|
||||
present: true,
|
||||
failed: false,
|
||||
in_manifest: true,
|
||||
apparent_bytes: 696320,
|
||||
apparent_bytes: 700000,
|
||||
actual_bytes: 720896,
|
||||
file_count: 12,
|
||||
},
|
||||
@@ -60,6 +80,7 @@ const payload = {
|
||||
actual_bytes: 1500000000,
|
||||
latest_stamp: '20261118T193001Z',
|
||||
latest_actual_bytes: 1500000000,
|
||||
complete: true,
|
||||
},
|
||||
incomplete_count: 1,
|
||||
skipped: [],
|
||||
|
||||
+71
-23
@@ -1,11 +1,32 @@
|
||||
// 「存储与备份 → 备份记录」只读盘点接口。真实字段来自备份主机目录的只读挂载:
|
||||
// 批次目录、每个库的完整子目录、文件系统实测容量;不是 SSH 计划读回的副产物。
|
||||
// 「存储与备份 → 备份记录」只读快照接口。真实字段来自备份主机上的单次元数据
|
||||
// 采集器:批次、子库完整路径、实际占盘、文件系统容量。API 不遍历备份目录,
|
||||
// 快照陈旧/不完整时所有字节字段为 null,页面必须显示未知。
|
||||
export interface BackupInventoryMetadata {
|
||||
configured: boolean
|
||||
present: boolean
|
||||
valid: boolean
|
||||
fresh: boolean
|
||||
complete: boolean
|
||||
path: string
|
||||
collected_at: string
|
||||
age_seconds: number
|
||||
max_age_seconds: number
|
||||
schema_version: number
|
||||
generation: string
|
||||
host: string
|
||||
collector_version: string
|
||||
error: string
|
||||
}
|
||||
|
||||
export interface BackupInventoryMount {
|
||||
container_root: string
|
||||
mount_verified: boolean
|
||||
lives_on_container_root: boolean
|
||||
read_only: boolean
|
||||
evidence: string
|
||||
mount_point: string
|
||||
device: string
|
||||
fs_type: string
|
||||
error?: string
|
||||
}
|
||||
|
||||
@@ -26,9 +47,9 @@ export interface BackupInventoryDatabase {
|
||||
present: boolean
|
||||
failed: boolean
|
||||
in_manifest: boolean
|
||||
apparent_bytes: number
|
||||
actual_bytes: number
|
||||
file_count: number
|
||||
apparent_bytes: number | null
|
||||
actual_bytes: number | null
|
||||
file_count: number | null
|
||||
}
|
||||
|
||||
export type BackupManifestState = 'ok' | 'missing' | 'invalid'
|
||||
@@ -44,10 +65,10 @@ export interface BackupInventoryBatch {
|
||||
created_at: string
|
||||
started_at: string
|
||||
duration_seconds: number
|
||||
manifest_total_bytes: number
|
||||
apparent_bytes: number
|
||||
actual_bytes: number
|
||||
file_count: number
|
||||
manifest_total_bytes: number | null
|
||||
apparent_bytes: number | null
|
||||
actual_bytes: number | null
|
||||
file_count: number | null
|
||||
sizes_complete: boolean
|
||||
sizes_error?: string
|
||||
databases: BackupInventoryDatabase[]
|
||||
@@ -60,21 +81,24 @@ export interface BackupInventorySkipped {
|
||||
|
||||
export interface BackupInventory {
|
||||
wired: boolean
|
||||
metadata: BackupInventoryMetadata
|
||||
root: string
|
||||
host_root: string
|
||||
source: string
|
||||
observed_at: string
|
||||
error?: string
|
||||
measurement: string
|
||||
mount: BackupInventoryMount
|
||||
capacity: BackupInventoryCapacity
|
||||
batches: BackupInventoryBatch[]
|
||||
totals: {
|
||||
batch_count: number
|
||||
database_count: number
|
||||
apparent_bytes: number
|
||||
actual_bytes: number
|
||||
apparent_bytes: number | null
|
||||
actual_bytes: number | null
|
||||
latest_stamp: string
|
||||
latest_actual_bytes: number
|
||||
latest_actual_bytes: number | null
|
||||
complete: boolean
|
||||
}
|
||||
incomplete_count: number
|
||||
skipped: BackupInventorySkipped[]
|
||||
@@ -86,6 +110,8 @@ const record = (value: unknown): value is Record<string, unknown> =>
|
||||
|
||||
const asString = (value: unknown): string => (typeof value === 'string' ? value : '')
|
||||
const asNumber = (value: unknown): number => (typeof value === 'number' && Number.isFinite(value) ? value : 0)
|
||||
const asNumberOrNull = (value: unknown): number | null =>
|
||||
typeof value === 'number' && Number.isFinite(value) ? value : null
|
||||
const asBool = (value: unknown): boolean => value === true
|
||||
const asList = (value: unknown): unknown[] => (Array.isArray(value) ? value : [])
|
||||
|
||||
@@ -102,9 +128,9 @@ function databaseProjection(item: unknown): BackupInventoryDatabase {
|
||||
present: asBool(value.present),
|
||||
failed: asBool(value.failed),
|
||||
in_manifest: asBool(value.in_manifest),
|
||||
apparent_bytes: asNumber(value.apparent_bytes),
|
||||
actual_bytes: asNumber(value.actual_bytes),
|
||||
file_count: asNumber(value.file_count),
|
||||
apparent_bytes: asNumberOrNull(value.apparent_bytes),
|
||||
actual_bytes: asNumberOrNull(value.actual_bytes),
|
||||
file_count: asNumberOrNull(value.file_count),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,10 +147,10 @@ function batchProjection(item: unknown): BackupInventoryBatch {
|
||||
created_at: asString(value.created_at),
|
||||
started_at: asString(value.started_at),
|
||||
duration_seconds: asNumber(value.duration_seconds),
|
||||
manifest_total_bytes: asNumber(value.manifest_total_bytes),
|
||||
apparent_bytes: asNumber(value.apparent_bytes),
|
||||
actual_bytes: asNumber(value.actual_bytes),
|
||||
file_count: asNumber(value.file_count),
|
||||
manifest_total_bytes: asNumberOrNull(value.manifest_total_bytes),
|
||||
apparent_bytes: asNumberOrNull(value.apparent_bytes),
|
||||
actual_bytes: asNumberOrNull(value.actual_bytes),
|
||||
file_count: asNumberOrNull(value.file_count),
|
||||
sizes_complete: asBool(value.sizes_complete),
|
||||
sizes_error: asString(value.sizes_error),
|
||||
databases: asList(value.databases).map(databaseProjection),
|
||||
@@ -136,22 +162,43 @@ function inventoryProjection(value: unknown): BackupInventory {
|
||||
if (!record(value) || typeof value.wired !== 'boolean') {
|
||||
throw new Error('备份盘点响应无效(缺 wired)')
|
||||
}
|
||||
const metadata = record(value.metadata) ? value.metadata : {}
|
||||
const mount = record(value.mount) ? value.mount : {}
|
||||
const capacity = record(value.capacity) ? value.capacity : {}
|
||||
const totals = record(value.totals) ? value.totals : {}
|
||||
return {
|
||||
wired: value.wired,
|
||||
metadata: {
|
||||
configured: asBool(metadata.configured),
|
||||
present: asBool(metadata.present),
|
||||
valid: asBool(metadata.valid),
|
||||
fresh: asBool(metadata.fresh),
|
||||
complete: asBool(metadata.complete),
|
||||
path: asString(metadata.path),
|
||||
collected_at: asString(metadata.collected_at),
|
||||
age_seconds: asNumber(metadata.age_seconds),
|
||||
max_age_seconds: asNumber(metadata.max_age_seconds),
|
||||
schema_version: asNumber(metadata.schema_version),
|
||||
generation: asString(metadata.generation),
|
||||
host: asString(metadata.host),
|
||||
collector_version: asString(metadata.collector_version),
|
||||
error: asString(metadata.error),
|
||||
},
|
||||
root: asString(value.root),
|
||||
host_root: asString(value.host_root),
|
||||
source: asString(value.source),
|
||||
observed_at: asString(value.observed_at),
|
||||
error: asString(value.error),
|
||||
measurement: asString(value.measurement),
|
||||
mount: {
|
||||
container_root: asString(mount.container_root),
|
||||
mount_verified: asBool(mount.mount_verified),
|
||||
lives_on_container_root: asBool(mount.lives_on_container_root),
|
||||
read_only: asBool(mount.read_only),
|
||||
evidence: asString(mount.evidence),
|
||||
mount_point: asString(mount.mount_point),
|
||||
device: asString(mount.device),
|
||||
fs_type: asString(mount.fs_type),
|
||||
error: asString(mount.error),
|
||||
},
|
||||
capacity: {
|
||||
@@ -166,10 +213,11 @@ function inventoryProjection(value: unknown): BackupInventory {
|
||||
totals: {
|
||||
batch_count: asNumber(totals.batch_count),
|
||||
database_count: asNumber(totals.database_count),
|
||||
apparent_bytes: asNumber(totals.apparent_bytes),
|
||||
actual_bytes: asNumber(totals.actual_bytes),
|
||||
apparent_bytes: asNumberOrNull(totals.apparent_bytes),
|
||||
actual_bytes: asNumberOrNull(totals.actual_bytes),
|
||||
latest_stamp: asString(totals.latest_stamp),
|
||||
latest_actual_bytes: asNumber(totals.latest_actual_bytes),
|
||||
latest_actual_bytes: asNumberOrNull(totals.latest_actual_bytes),
|
||||
complete: asBool(totals.complete),
|
||||
},
|
||||
incomplete_count: asNumber(value.incomplete_count),
|
||||
skipped: asList(value.skipped).map((item) => {
|
||||
@@ -186,7 +234,7 @@ export async function fetchBackupInventory(signal?: AbortSignal): Promise<Backup
|
||||
signal,
|
||||
})
|
||||
if (!response.ok) {
|
||||
throw new Error(`读取备份盘点失败(HTTP ${response.status})`)
|
||||
throw new Error(`读取备份元数据失败(HTTP ${response.status})`)
|
||||
}
|
||||
const value = (await response.json().catch(() => null)) as unknown
|
||||
if (!record(value) || !record(value.data)) throw new Error('备份盘点响应无效')
|
||||
|
||||
Reference in New Issue
Block a user