Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fa8e202
feat: 添加数据迁移功能
RC-CHN Dec 18, 2025
70cda9a
test: 添加迁移相关测试
RC-CHN Dec 18, 2025
57bacab
feat: 备份插件及相关持久化目录
RC-CHN Dec 18, 2025
372628a
fix: 修复版本号比较逻辑,添加相关测试
RC-CHN Dec 18, 2025
ce1af61
fix: 清洗文件名,添加相关测试
RC-CHN Dec 18, 2025
0d592af
fix: 修复安全文件名测试用例断言
RC-CHN Dec 18, 2025
39af9ab
refactor: 优化代码,为备份模块提取公用常量
RC-CHN Dec 18, 2025
25cb864
feat: 修改备份版本校验逻辑,允许强制小版本间导入
RC-CHN Dec 18, 2025
40e9cfe
fix: 修复备份创建时间读取,修复备份相关i18n
RC-CHN Dec 18, 2025
4269e02
Merge remote-tracking branch 'origin/master' into data_backup
Soulter Dec 25, 2025
e18c68f
refactor(backup): 使用 astrbot_path 统一管理备份目录路径
RC-CHN Dec 25, 2025
b2df498
fix(backup): 清理备份模块中未使用的导入
RC-CHN Dec 25, 2025
5d63dc5
refactor(backup): 统一备份路径与参数并移除未用附件目录
RC-CHN Dec 25, 2025
7fbe3ea
fix(dashboard): alias mermaid to dist entry for Vite prebundle
RC-CHN Dec 25, 2025
f28f899
fix(backup): 放行start-time接口到白名单以处理备份导入后jwt token变化导致无法自动刷新webui的问题
RC-CHN Dec 25, 2025
15e5209
chore(backup): 统一配置路径以使用动态数据目录
Soulter Dec 26, 2025
cb0c002
refactor(backup): 使用 VersionComparator 替代重复的版本比较函数
RC-CHN Dec 26, 2025
c589b1f
style(backup test): format code
RC-CHN Dec 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions astrbot/core/backup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""AstrBot 备份与恢复模块

提供数据导出和导入功能,支持用户在服务器迁移时一键备份和恢复所有数据。
"""

# 从 constants 模块导入共享常量
from .constants import (
BACKUP_MANIFEST_VERSION,
KB_METADATA_MODELS,
MAIN_DB_MODELS,
get_backup_directories,
)

# 导入导出器和导入器
from .exporter import AstrBotExporter
from .importer import AstrBotImporter, ImportPreCheckResult

__all__ = [
"AstrBotExporter",
"AstrBotImporter",
"ImportPreCheckResult",
"MAIN_DB_MODELS",
"KB_METADATA_MODELS",
"get_backup_directories",
"BACKUP_MANIFEST_VERSION",
]
77 changes: 77 additions & 0 deletions astrbot/core/backup/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""AstrBot 备份模块共享常量

此文件定义了导出器和导入器共享的常量,确保两端配置一致。
"""

from sqlmodel import SQLModel

from astrbot.core.db.po import (
Attachment,
CommandConfig,
CommandConflict,
ConversationV2,
Persona,
PlatformMessageHistory,
PlatformSession,
PlatformStat,
Preference,
)
from astrbot.core.knowledge_base.models import (
KBDocument,
KBMedia,
KnowledgeBase,
)
from astrbot.core.utils.astrbot_path import (
get_astrbot_config_path,
get_astrbot_plugin_data_path,
get_astrbot_plugin_path,
get_astrbot_t2i_templates_path,
get_astrbot_temp_path,
get_astrbot_webchat_path,
)

# ============================================================
# 共享常量 - 确保导出和导入端配置一致
# ============================================================

# 主数据库模型类映射
MAIN_DB_MODELS: dict[str, type[SQLModel]] = {
"platform_stats": PlatformStat,
"conversations": ConversationV2,
"personas": Persona,
"preferences": Preference,
"platform_message_history": PlatformMessageHistory,
"platform_sessions": PlatformSession,
"attachments": Attachment,
"command_configs": CommandConfig,
"command_conflicts": CommandConflict,
}

# 知识库元数据模型类映射
KB_METADATA_MODELS: dict[str, type[SQLModel]] = {
"knowledge_bases": KnowledgeBase,
"kb_documents": KBDocument,
"kb_media": KBMedia,
}


def get_backup_directories() -> dict[str, str]:
"""获取需要备份的目录列表

使用 astrbot_path 模块动态获取路径,支持通过环境变量 ASTRBOT_ROOT 自定义根目录。

Returns:
dict: 键为备份文件中的目录名称,值为目录的绝对路径
"""
return {
"plugins": get_astrbot_plugin_path(), # 插件本体
"plugin_data": get_astrbot_plugin_data_path(), # 插件数据
"config": get_astrbot_config_path(), # 配置目录
"t2i_templates": get_astrbot_t2i_templates_path(), # T2I 模板
"webchat": get_astrbot_webchat_path(), # WebChat 数据
"temp": get_astrbot_temp_path(), # 临时文件
}


# 备份清单版本号
BACKUP_MANIFEST_VERSION = "1.1"
Loading