Files
ai-contract-platform/project-docs/V2-backup-restore-2026-06-26.md
T
yuqei a3bb78e06b
Security Quality Gate / npm audit, Bandit, pip-audit, detect-secrets (pull_request) Failing after 16m35s
release: freeze V2 release candidate
2026-07-12 15:32:24 +08:00

72 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AI 合同平台 V2 - 数据备份和恢复功能闭环记录
日期:2026-06-26
## 背景
对照《AI 合同平台 V2 重构版开发方案》Phase 7 安全、性能与上线准备,本轮实现数据备份和恢复功能。
## 已完成内容
### 数据模型
新增模型:
- `BackupStatus`: 备份状态(id, backup_type, status, file_size, checksum)
- `BackupRequest`: 备份请求(backup_type, include_files)
- `BackupListPage`: 备份列表分页
- `RestoreRequest`: 恢复请求(backup_id, dry_run)
- `RestoreStatus`: 恢复状态(tables_restored, files_restored)
### Repository 方法
新增方法:
- `create_backup(request)`: 创建备份
- `get_backups(page, page_size)`: 列出备份
- `restore_backup(request)`: 恢复备份
- `validate_backup(backup_id)`: 验证备份有效性
SQLite 实现:
- 导出所有合同数据为 JSON
- 计算 SHA256 checksum
- 支持 dry_run 模式恢复
### API 接口
新增接口:
- `POST /api/v1/backup`: 创建备份
- `GET /api/v1/backup`: 列出备份
- `GET /api/v1/backup/{id}`: 获取备份详情
- `POST /api/v1/backup/{id}/validate`: 验证备份
- `POST /api/v1/restore`: 恢复备份
### 测试
`test_backup.py`:
- `test_create_backup`: 创建备份测试
- `test_list_backups`: 列出备份测试
- `test_validate_backup`: 验证备份测试
- `test_restore_backup_dry_run`: dry run 恢复测试
- `test_restore_backup_not_found`: 不存在备份恢复测试
## 验证结果
```powershell
python -m pytest yuqei-contract-platform/services/contract-api/tests -q # 36 passed
```
## Phase 7 进度
| 功能 | 状态 |
|------|------|
| 租户隔离 | ✅ |
| 审计完整性 | ✅ |
| 数据备份和恢复 | ✅(本轮) |
| 权限矩阵 | 🔄 |
| 错误监控 | 🔄 |
| 性能压测 | 🔄 |
| 安全扫描 | 🔄 |
| 部署文档 | 🔄 |
## 后续建议
下一步继续 Phase 7 的**错误监控**功能,实现 trace_id 跨服务串联和错误日志收集。