chore: 可是实现从创建补丁,应用补丁,到回滚补丁整个流程的操作

This commit is contained in:
2025-11-18 15:45:39 +08:00
parent abb68003d2
commit 575f44e6ee
4 changed files with 196 additions and 18 deletions

View File

@@ -304,14 +304,38 @@ create_backup() {
mkdir -p "$(dirname "$backup_tar")"
local work_dir="$(pwd)" # 默认是当前工作目录
if tar -czf "$backup_tar" -C "${work_dir}" "${files_to_backup[@]/#\//}"; then
# 创建临时目录用于快速构建压缩包
local temp_dir="/tmp/backup_fast_$$"
mkdir -p "$temp_dir/contents"
# 快速复制文件到临时目录(使用 cp --parents 保持目录结构)
for file in "${files_to_backup[@]}"; do
if [[ -f "$file" ]]; then
cp --parents "$file" "$temp_dir/contents/" 2>/dev/null || \
cp "$file" "$temp_dir/contents/$(basename "$file")"
fi
done
# 复制 changes_file 为 changes.txt
if [[ -f "$changes_file" ]]; then
cp "$changes_file" "$temp_dir/changes.txt"
fi
# 从临时目录打包(最简单可靠)
if tar -czf "$backup_tar" -C "$temp_dir" .; then
local size=$(du -h "$backup_tar" | cut -f1)
info "✅ 备份创建完成: $backup_tar ($size)" >&2
# 清理临时目录
rm -rf "$temp_dir"
echo "$backup_tar"
return 0
else
error "❌ 备份创建失败" >&2
# 清理临时目录
rm -rf "$temp_dir"
return 1
fi
}