修复:独立回收中断备份并限制 AI 日志增长

This commit is contained in:
2026-11-10 16:02:46 +08:00
parent dc5b9b76ec
commit cc8832c8e5
15 changed files with 584 additions and 39 deletions
+12 -3
View File
@@ -39,17 +39,26 @@ def snapshot(root, support=None, now=None):
mysql = estimates.get(cfg['mysqlDatabase'], 0)
archive = operations.allocated(root / 'runtimedata/archive'); backups = operations.allocated(root / 'output/backups')
native = operations.allocated(root / '.runtime/nao-users')
logs = sum(p.stat().st_blocks * 512 for p in log_retention.candidates(root, root / '.runtime/operations'))
core = mysql + archive + backups + native + logs
log_paths = log_retention.candidates(root, root / '.runtime/operations')
logs = sum(p.stat().st_blocks * 512 for p in log_paths)
native_logs = sum(p.stat().st_blocks * 512 for p in log_paths if p.is_relative_to(root / '.runtime/nao-users'))
core = mysql + archive + backups + max(0, native - native_logs) + logs
free = min(shutil.disk_usage(root / p).free for p in ('.runtime', 'output/backups', 'output/logs', 'runtimedata/archive'))
return {'at': now, 'mysqlBytes': mysql, 'mysqlMeasurement': 'information_schema_estimate_excludes_system_redo_undo',
'archiveBytes': archive, 'backupBytes': backups, 'logBytes': logs, 'nativeDataBytes': native,
'archiveBytes': archive, 'backupBytes': backups, 'logBytes': logs, 'nativeDataBytes': max(0, native - native_logs),
'registeredTestBytes': registered, 'privateVerifierBytes': private, 'temporaryBytes': registered + private,
'coreBytes': core, 'artifactBytes': 0, 'permanentBytes': core, 'freeBytes': free,
'overdueTestResources': overdue}
def once(role):
# 数据库不可连接时也要能释放中断备份占用,不能放在采样或健康检查之后。
if not (ROOT / '.runtime/retention/paused').exists():
try:
result = br.clean_incomplete(ROOT)
if result['incompleteBackupsRemoved']:
print(json.dumps({'event': 'incomplete-backup-cleanup', **result}), flush=True)
except br.Busy: pass
if role == 'monitor':
operations.snapshot = snapshot
return operations.run(ROOT, support=ROOT / '.runtime/operations', notifier=console_notify)