包含 CodeAgent 前后端源码、SKILLS、MCP、demo 代码与工作区文档。 排除依赖缓存、运行数据、备份与二进制附件,规则见 .gitignore。 Co-Authored-By: Claude Code <[email protected]>
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""
|
|
自动备份 API
|
|
============
|
|
|
|
【功能说明】手动触发备份、查看备份列表、清理旧备份。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from app.schemas.project import ApiResponse
|
|
from app.services.backup_service import backup_now, list_backups
|
|
|
|
logger = logging.getLogger("agent.backup.api")
|
|
|
|
router = APIRouter(prefix="/api/backup", tags=["自动备份"])
|
|
|
|
|
|
@router.post("/now", response_model=ApiResponse[dict], summary="立即备份")
|
|
def backup_now_endpoint() -> ApiResponse[dict]:
|
|
"""立即执行全量备份(SQLite + 配置 + 向量库元数据)。"""
|
|
result = backup_now()
|
|
if not result.get("success"):
|
|
return ApiResponse(code=1, message=result.get("message", "备份失败"), data=result)
|
|
return ApiResponse(code=0, message="备份完成", data=result)
|
|
|
|
|
|
@router.get("/list", response_model=ApiResponse[list[dict]], summary="备份列表")
|
|
def list_backups_endpoint() -> ApiResponse[list[dict]]:
|
|
"""列出所有备份记录(含大小、文件数、时间)。"""
|
|
items = list_backups()
|
|
return ApiResponse(code=0, message=f"共 {len(items)} 个备份", data=items)
|