mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-03 20:21:51 +08:00
fix(backup): 加固一键备份与恢复安全性及大包流式传输 (#160)
- 导出前拒绝存在未暂停的运行中/排队中任务(409 backup_active_tasks + X-Artex-Error-Code),恢复事务内将未完成非暂停任务强制置为手动暂停,防止迁移后自动继续打目标,并同步更新确认文案与 README - 启动恢复时若文件替换或暂存清理失败,ApplyPendingRestore 返回错误且 main 非零退出,交由守护脚本重试,避免带着新库与半套文件启动业务引擎 - 数据库表导出改为 8 MiB 分片流式写入 tar+zstd 并刷新 HTTP 响应,消除大表落盘临时文件与反代长静默超时;README 补齐 /api/system/backup/ 的 Nginx client_max_body_size 0 与 proxy_request_buffering off 配置 - 暂存新恢复包时先将旧 pending 移走、rename 失败则回滚,避免丢弃已有待恢复包 - 恢复接口返回唯一 restore_id 并写入暂存标记,前端改为精确匹配 restore_id 判断重启恢复完成,消除时钟偏差与旧结果误判 - 补充 Windows->Linux 归档路径改写、活跃任务拦截与恢复自动暂停、多片流式 COPY、文件替换失败快速退出续跑及暂存原子替换测试
This commit is contained in:
1 parent
c6f7c29b71
commit
4d2c327df7
9 files changed
+578
-81
No files matched your search
+6
-6
@@ -168,6 +168,7 @@ export interface BackupStatus {
|
||||
pending: boolean;
|
||||
// 本次启动时执行的恢复结果;未执行恢复时为 null。
|
||||
last_restore: {
|
||||
id?: string;
|
||||
applied: boolean;
|
||||
error?: string;
|
||||
at: string;
|
||||
@@ -439,11 +440,10 @@ export const api = {
|
||||
method: "HEAD",
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
});
|
||||
if (!response.ok)
|
||||
throw new ApiError(
|
||||
`HEAD /system/backup/export: ${response.status}`,
|
||||
response.status === 409 ? "backup_busy" : undefined,
|
||||
);
|
||||
if (!response.ok) {
|
||||
const code = response.headers.get("X-Artex-Error-Code") ?? (response.status === 409 ? "backup_busy" : undefined);
|
||||
throw new ApiError(`HEAD /system/backup/export: ${response.status}`, code);
|
||||
}
|
||||
const a = document.createElement("a");
|
||||
a.href = "/api/system/backup/export";
|
||||
document.body.appendChild(a);
|
||||
@@ -451,7 +451,7 @@ export const api = {
|
||||
a.remove();
|
||||
},
|
||||
restoreBackup: (file: File) =>
|
||||
http<{ ok: boolean; version: string; created_at: string }>("/system/backup/restore", {
|
||||
http<{ ok: boolean; restore_id: string; version: string; created_at: string }>("/system/backup/restore", {
|
||||
method: "POST",
|
||||
body: file,
|
||||
headers: { "Content-Type": "application/octet-stream" },
|
||||
|
||||
Reference in new issue
Block a user