diff --git a/bin/backup.sh b/bin/backup.sh index 8e2b544..38e3933 100755 --- a/bin/backup.sh +++ b/bin/backup.sh @@ -33,7 +33,8 @@ log() { local message="$@" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') - echo -e "[${timestamp}] [${level}] ${message}" + # 输出到 stderr,避免干扰函数返回值 + echo -e "[${timestamp}] [${level}] ${message}" >&2 # 如果配置了日志文件,同时写入文件 if [[ -n "${LOG_FILE}" ]] && [[ "${LOGGING_ENABLED}" == "true" ]]; then @@ -207,11 +208,7 @@ backup_folders() { # 执行打包 log_info "开始打包文件夹..." - eval "tar -czf '${folders_tar}' ${exclude_args} ${tar_sources}" 2>&1 | while read line; do - log_info "$line" - done - - if [[ -f "${folders_tar}" ]]; then + if eval "tar -czf '${folders_tar}' ${exclude_args} ${tar_sources}" 2>&1; then log_info "文件夹备份完成: ${folders_tar}" echo "${folders_tar}" else diff --git a/bin/cleanup.sh b/bin/cleanup.sh index e6c0c3a..c4a1876 100755 --- a/bin/cleanup.sh +++ b/bin/cleanup.sh @@ -25,15 +25,15 @@ NC='\033[0m' ############################################################################### log_info() { - echo -e "${GREEN}[INFO]${NC} $@" + echo -e "${GREEN}[INFO]${NC} $@" >&2 } log_warn() { - echo -e "${YELLOW}[WARN]${NC} $@" + echo -e "${YELLOW}[WARN]${NC} $@" >&2 } log_error() { - echo -e "${RED}[ERROR]${NC} $@" + echo -e "${RED}[ERROR]${NC} $@" >&2 } ###############################################################################