diff --git a/CHANGELOG.md b/CHANGELOG.md index 8968507..9f6c766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 开发快照 0.1.409(存储与备份页面显示口径修正) + +### Fixed + +- 完整快照不再把宿主备份文件系统可写当成部署错误:去掉“挂载可写 / 需改 :ro”提示, + 明确备份盘由备份主机写入,API 只读元数据快照。 +- 容量已实测且完整时磁盘告警为正常,不再出现“缺主机磁盘读数”;配额相关三项仅标注 + 配额字段未接线,摘要区分“磁盘项正常”与“磁盘项无法判定”。 +- 采集时间(宿主快照)与读回时间(API)分列;快照年龄/新鲜度取快照字段; + “重新盘点”明确只重读 `metadata.json`,不会让宿主重新采集。 +- 空间预测注明以上次整批实际占盘为参考,不是接口预测。 +- 小文件不足 0.05 MiB 显示 KiB,避免非零体积被舍成 0.0 MiB。 + ## 开发快照 0.1.408(备份盘点改宿主采集器:权限失败不再产出部分字节) ### Fixed diff --git a/web/src/BackupScheduleSection.test.tsx b/web/src/BackupScheduleSection.test.tsx index 383a8fe..032fa4b 100644 --- a/web/src/BackupScheduleSection.test.tsx +++ b/web/src/BackupScheduleSection.test.tsx @@ -487,6 +487,8 @@ describe('BackupScheduleView', () => { expect(formatBackupBytes(null)).toBe('—') expect(formatBackupBytes(undefined)).toBe('—') expect(formatBackupBytes(1024 * 1024)).toBe('1.0 MiB') + expect(formatBackupBytes(4096)).toBe('4.0 KiB') + expect(formatBackupBytes(720896)).toBe('0.7 MiB') expect(formatBackupBytes(2 * 1024 * 1024 * 1024)).toBe('2.00 GiB') }) }) @@ -566,6 +568,7 @@ describe('整盘占用与告警', () => { expect(alerts.find((item) => item.code === 'disk_low')?.known).toBe(true) expect(alerts.find((item) => item.code === 'disk_low')?.active).toBe(false) expect(alerts.find((item) => item.code === 'quota_low')?.known).toBe(false) + expect(storageAlertSummary(alerts)).toBe('磁盘项正常 · 配额字段未接线') const html = view({}, { inventory }) for (const text of [ '宿主采集器实测', @@ -574,10 +577,21 @@ describe('整盘占用与告警', () => { '可用', '配额内/外 —(无配额字段)', '文件系统已用', - '只读挂载', + '采集时间', + '读回时间', + '(API 读回)', + '备份文件系统必须由备份主机可写', + '空间预测仅以上次整批实际占盘 1.40 GiB', '宿主采集器:/dev/sdb1 挂在 /srv/kb-backups', + '磁盘项正常 · 配额字段未接线', + '0.7 MiB', + '重新盘点(仅重读快照)', ]) expect(html).toContain(text) + expect(html).not.toContain('挂载可写') + expect(html).not.toContain('不是只读') + expect(html).not.toContain('缺主机磁盘读数') + expect(html).not.toContain('0.0 MiB') }) it('不完整快照:容量图与占盘不使用部分字节', () => { @@ -609,11 +623,13 @@ describe('整盘占用与告警', () => { 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(storageAlertSummary(alerts)).toBe('无法判定(缺读数与配额字段)') const html = view({}, { inventory }) expect(html).toContain('占盘未知 · 不使用部分字节') expect(html).toContain('采集快照不完整:所有批次占盘与容量未知') expect(html).toContain('占盘未知(采集不完整)') expect(html).not.toContain('备份实际占盘 1.40 GiB') + expect(html).not.toContain('缺主机磁盘读数') }) it('复制路径:空值与不可用按钮不谎报成功', async () => { diff --git a/web/src/BackupScheduleSection.tsx b/web/src/BackupScheduleSection.tsx index 34554c1..490d00a 100644 --- a/web/src/BackupScheduleSection.tsx +++ b/web/src/BackupScheduleSection.tsx @@ -16,8 +16,12 @@ import './storageBackup.css' 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' + if (bytes < 1024) return `${bytes} B` const mib = bytes / (1024 * 1024) - return mib >= 1024 ? `${(mib / 1024).toFixed(2)} GiB` : `${mib.toFixed(1)} MiB` + if (mib >= 1024) return `${(mib / 1024).toFixed(2)} GiB` + // 小文件不能舍成 0.0 MiB;不足 0.05 MiB 用 KiB,其余保留一位 MiB。 + if (mib < 0.05) return `${(bytes / 1024).toFixed(1)} KiB` + return `${mib.toFixed(1)} MiB` } export const formatBackupMoment = (value: string): string => { @@ -113,10 +117,16 @@ export function storageUsage(observation: StorageDiskObservation): StorageUsage export function storageAlerts(observation: StorageDiskObservation | null): StorageAlert[] { if (!observation) { return [ - { code: 'disk_low', label: '磁盘不足', active: false, known: false, detail: '缺主机磁盘读数' }, + { code: 'disk_low', label: '磁盘不足', active: false, known: false, detail: '尚未读取宿主快照' }, { code: 'quota_low', label: '配额不足', active: false, known: false, detail: '缺备份占用量与配额读数' }, - { code: 'both_low', label: '磁盘与配额同时不足', active: false, known: false, detail: '缺主机磁盘读数' }, - { code: 'quota_over_physical', label: '配额超出物理空闲', active: false, known: false, detail: '缺主机磁盘读数' }, + { code: 'both_low', label: '磁盘与配额同时不足', active: false, known: false, detail: '尚未读取宿主快照' }, + { + code: 'quota_over_physical', + label: '配额超出物理空闲', + active: false, + known: false, + detail: '尚未读取宿主快照', + }, ] } const usage = storageUsage(observation) @@ -193,7 +203,12 @@ const percent = (part: number, total: number): string => (total > 0 ? `${(100 * export const storageAlertSummary = (alerts: StorageAlert[]): string => { const unknown = alerts.filter((item) => !item.known) + const quotaOnly = ['quota_low', 'both_low', 'quota_over_physical'] if (unknown.length === alerts.length) return '无法判定(缺读数与配额字段)' + if (unknown.length && unknown.every((item) => item.code === 'disk_low' || quotaOnly.includes(item.code))) { + const disk = alerts.find((item) => item.code === 'disk_low') + return disk?.known ? '磁盘项正常 · 配额字段未接线' : '磁盘项无法判定 · 配额字段未接线' + } if (unknown.length) return `部分无法判定(${unknown.map((item) => item.label).join('、')})` const active = alerts.filter((item) => item.active) return active.length ? active.map((item) => item.label).join('、') : '四项均正常' @@ -267,7 +282,7 @@ export function inventoryAlerts(inventory: BackupInventory | null): StorageAlert : !inventory.capacity.measured ? inventory.capacity.error || '未读到文件系统容量' : latestBytes === null || latestBytes === undefined - ? '最近批次占盘未知' + ? '容量已读到,但缺最近批次实际占盘;不能判定是否装得下' : `剩余可用 ${formatGib(usage!.free)} GiB,最近一批实际占盘 ${formatGib(latestBytes)} GiB(参考值,不含策略预留)` return [ { @@ -282,21 +297,21 @@ export function inventoryAlerts(inventory: BackupInventory | null): StorageAlert label: '配额不足', active: false, known: false, - detail: '后端没有备份总配额字段,无法判定', + detail: '仅缺备份总配额字段,无法判定', }, { code: 'both_low', label: '磁盘与配额同时不足', active: false, known: false, - detail: '缺配额字段,无法判定', + detail: '仅缺配额字段,无法同时判定', }, { code: 'quota_over_physical', label: '配额超出物理空闲', active: false, known: false, - detail: '缺配额字段,无法判定', + detail: '仅缺配额字段,无法判定', }, ] } @@ -453,7 +468,7 @@ export function BackupScheduleView(props: BackupScheduleViewProps) {
{error ? ( @@ -486,6 +501,16 @@ export function BackupScheduleView(props: BackupScheduleViewProps) { {inventory?.source || `备份执行主机 ${schedule.host_target || '(未配置)'} 本机直连 RDS`} {scopeDatabaseCount ? ` · 最近批次含 ${scopeDatabaseCount} 个数据库` : ' · 数据库清单未读到'} ++ 备份文件系统必须由备份主机可写;API 只读挂载元数据快照,不向该盘写入。空间预测仅以上次整批实际占盘 + {latestBatch?.actual_bytes !== null && latestBatch?.actual_bytes !== undefined + ? ` ${formatBackupBytes(latestBatch.actual_bytes)}` + : '(未读到)'}{' '} + 作参考,不是接口预测,也不含策略预留。 +
> ) : ( <> @@ -707,8 +738,8 @@ export function BackupScheduleView(props: BackupScheduleViewProps) { )}容量与实际占盘来自宿主单项元数据采集器(stat/du 元数据,不读数据库内容);API 不遍历备份目录。 - 快照陈旧、缺失或不完整时,容量图与任何可写预测都不使用部分字节。配额与策略预留仍无后端字段, - 四项告警中只有磁盘项能按完整快照判定。 + 快照陈旧、缺失或不完整时,容量图与任何可写预测都不使用部分字节。配额与策略预留仍无后端字段; + 容量可信时只对磁盘项判定,配额相关三项标注未接线。
{storageAlertSummary(alerts)}