diff --git a/bin/backup.sh b/bin/backup.sh index 7dc32a5..eda767b 100755 --- a/bin/backup.sh +++ b/bin/backup.sh @@ -209,8 +209,10 @@ backup_folders() { # 执行打包 log_info "开始打包文件夹..." log_info "排除规则: ${exclude_args}" - # 将 tar 输出重定向到 stderr,避免干扰函数返回值 - if eval "tar -czf '${folders_tar}' ${exclude_args} ${tar_sources}" 2>&1 >&2; then + # 将 tar 的 stdout 和 stderr 都重定向到 stderr,避免干扰函数返回值 + eval "tar -czf '${folders_tar}' ${exclude_args} ${tar_sources}" >&2 2>&1 + + if [[ -f "${folders_tar}" ]]; then local tar_size=$(du -h "${folders_tar}" | cut -f1) log_info "文件夹备份完成: ${folders_tar} (大小: ${tar_size})" echo "${folders_tar}"