feat: 支持Cloudflare R2 数据备份功能,支持加密、定时备份、轮替与下载解密#110
Open
Jimmy-Bots wants to merge 4 commits intobasketikun:mainfrom
Open
feat: 支持Cloudflare R2 数据备份功能,支持加密、定时备份、轮替与下载解密#110Jimmy-Bots wants to merge 4 commits intobasketikun:mainfrom
Jimmy-Bots wants to merge 4 commits intobasketikun:mainfrom
Conversation
Contributor
Author
|
当前未做备份恢复功能,从之前 #103 被close看来可能一些配置的热重载似乎目前不考虑 |
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.
变更说明
本次改动为管理员设置页新增了 Cloudflare R2 备份能力,支持将关键数据按压缩包形式备份到 R2,并提供定时执行、轮替清理、历史查看、手动备份、删除和下载等管理能力。
整体实现尽量沿用现有配置与设置页结构,以增量方式接入,没有重构原有系统配置、存储抽象或管理页框架。
主要改动
1. 新增 Cloudflare R2 备份配置与管理入口
在管理员设置页新增独立的备份管理卡片,支持配置:
同时支持以下管理操作:
2. 新增定时备份与轮替能力
后端新增独立的备份服务,在服务启动后后台运行定时轮询逻辑。
当启用定时备份后,会按配置的时间间隔自动执行备份;备份成功后,如果配置了保留数量限制,会自动删除更旧的远端备份对象,实现简单轮替。
同时支持手动触发备份,与定时备份共用同一套执行逻辑和状态记录。
3. 备份内容改为原始多文件压缩包格式
备份产物为多文件压缩包格式。
当前备份文件格式为:
.tar.gz.tar.gz.enc压缩包内按json原始结构保存数据,例如:
config.jsondata/register.jsondata/cpa_config.jsondata/sub2api_config.jsondata/logs.jsonldata/image_tasks.jsondata/images/...snapshots/accounts.jsonsnapshots/auth_keys.jsonbackup-metadata.json其中:
json、sqlite、postgres还是git,都能进入统一备份包4. 支持可选加密备份
当启用加密后,备份压缩包会在上传到 R2 前使用
openssl进行加密。为了保证容器环境可用,本次也补充了运行时所需依赖,使 Docker 部署下加密备份可以正常工作。
5. 支持备份详情查看
后端新增备份详情解析能力,前端可以查看:
这样可以在不恢复备份的情况下先确认备份内容是否符合预期。
6. 支持下载备份文件
新增备份下载接口,管理员可以直接从设置页下载远端备份对象。
对于未加密备份,会直接下载
.tar.gz文件。对于已加密备份,本次进一步补充了“下载时自动解密”逻辑:
.tar.gz.enc后缀这样用户下载加密备份时,不需要再手动处理
.enc文件。7. 备份状态与配置职责拆分
备份配置保存在系统配置中,而备份运行状态单独保存在独立状态文件中,避免将运行态混入配置本身。
这样可以更清晰地区分:
backup:期望配置backup_state:最近一次执行结果与状态影响范围
验证情况
.enc后缀的问题web/node_modules备注
tar.gz压缩包方案效果展示