feat(backup): add v2 backup system refactor plan document#12659
Draft
GeorgeDong32 wants to merge 3 commits intov2from
Draft
feat(backup): add v2 backup system refactor plan document#12659GeorgeDong32 wants to merge 3 commits intov2from
GeorgeDong32 wants to merge 3 commits intov2from
Conversation
Add GroupsExporter and PreferencesExporter to the backup service.
- Implement GroupsExporter to stream group rows into a JSONL file.
- Count groups, create domain directory, write groups ordered by
createdAt (desc), compute file checksum and sizes, and return export
metadata.
- Use a streaming JsonlStringifier piped to a write stream to avoid
buffering all data in memory and update export progress as rows are
processed.
- Implement PreferencesExporter skeleton with filtering rules.
- Fetch preferences and filter out sensitive and machine-specific
keys using regex patterns and a key whitelist to avoid writing
secrets (tokens, passwords, API keys, credentials, auth).
- Prepare grouped preference data structure and set domain progress.
- Ensure preferences are exported in a structured JSON format (file
creation and finalization handled in exporter flow).
Rationale: add domain-specific backup exporters to persist groups and
non-sensitive preferences reliably and efficiently, with progress
reporting and integrity checks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry Studio 备份系统重构设计文档 v2.0
目录
背景与目标
现有备份系统(V1)存在以下问题:
JSON.stringify整体序列化,数据量超过 512MB 时触发 V8 内存限制导致崩溃;BackupManager和文件复制机制,不兼容 V2 的 SQLite 架构;新版系统要实现:
DataApiService和 Drizzle ORM,与新架构无缝集成;核心原则
内存友好
事务原子性
向后兼容
VersionMigrator) 自动升级数据结构。架构分层
关键实现
1. 导出格式 (ZIP + JSONL)
采用混合格式:
manifest.json: 元数据与统计信息topics/messages/chunk_*.jsonl: 消息数据分片(流式写入)files/blobs/{hash}.bin: 附件文件(去重存储)tree_refs.jsonl: 轻量级树结构引用,用于快速重建与冲突检测2. 流式序列化
3. Base64 图片分离
files/blobs/-> JSON 中替换为{"image_ref": "hash"}image_ref-> 从 ZIP 中查找二进制文件 -> 还原4. 增量备份
基于
updatedAt时间戳:updatedAt > lastBackupTime的记录;changes/目录)。数据流
导出流程
BackupOrchestrator初始化,写入manifest.json(pending 状态);archiverZIP 流;Exporter:TopicExporter: 流式读取 DB -> 写入messages.jsonl-> 提取图片 ->FileExporter;manifest.json(stats, checksum),finalize ZIP;BackupEncryptor进行加密。导入流程
BackupValidator校验文件完整性 (xxHash);SAVEPOINT;VersionMigrator检查并适配版本;Importer:Preference->Assistant->Topic(处理 ID 冲突) ->File;迁移与兼容性
LegacyImporter专门处理 V1 格式 (JSON dump),将其转换为 V2 内存对象后通过 V2 写入逻辑入库。SKIP,OVERWRITE,RENAME策略,RENAME模式下自动维护ID Map更新引用。执行计划