From 9bb02927c3980c9d5b06b2615590a951c48117dd Mon Sep 17 00:00:00 2001 From: sepehr Date: Sun, 7 Jun 2026 11:16:45 +0200 Subject: [PATCH] fix: redirect logs to stderr and reduce size thresholds in backup/verify scripts --- scripts/backup-to-nas.sh | 10 +++++----- scripts/verify-backups.sh | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/backup-to-nas.sh b/scripts/backup-to-nas.sh index 2162607..e91f0b6 100644 --- a/scripts/backup-to-nas.sh +++ b/scripts/backup-to-nas.sh @@ -77,10 +77,10 @@ YELLOW='\033[1;33m' NC='\033[0m' LOG_PREFIX="[Backup ${TIMESTAMP}]" -log() { echo "${LOG_PREFIX} $1"; } -log_success() { echo -e "${LOG_PREFIX} ${GREEN}✅ $1${NC}"; } -log_error() { echo -e "${LOG_PREFIX} ${RED}❌ ERROR: $1${NC}"; } -log_warning() { echo -e "${LOG_PREFIX} ${YELLOW}⚠️ $1${NC}"; } +log() { echo "${LOG_PREFIX} $1" >&2; } +log_success() { echo -e "${LOG_PREFIX} ${GREEN}✅ $1${NC}" >&2; } +log_error() { echo -e "${LOG_PREFIX} ${RED}❌ ERROR: $1${NC}" >&2; } +log_warning() { echo -e "${LOG_PREFIX} ${YELLOW}⚠️ $1${NC}" >&2; } # ============================================================================== # TELEGRAM @@ -161,7 +161,7 @@ Date : $(date '+%Y-%m-%d %H:%M:%S')" # Vérification taille local size_bytes size_bytes=$(stat -c %s "${dump_file}" 2>/dev/null || stat -f %z "${dump_file}") - local min_bytes=$((1024 * 1024)) # 1MB minimum + local min_bytes=1024 # 1KB minimum (safe for new/small databases) if [ "${size_bytes}" -lt "${min_bytes}" ]; then log_error "Dump trop petit ($(numfmt --to=iec ${size_bytes})) — base de données vide ?" diff --git a/scripts/verify-backups.sh b/scripts/verify-backups.sh index d4f29fe..e87d5d4 100644 --- a/scripts/verify-backups.sh +++ b/scripts/verify-backups.sh @@ -27,10 +27,10 @@ GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' -log() { echo "[Verify ${TIMESTAMP}] $1"; } -log_success() { echo -e "[Verify ${TIMESTAMP}] ${GREEN}✅ $1${NC}"; } -log_warning() { echo -e "[Verify ${TIMESTAMP}] ${YELLOW}⚠️ WARNING: $1${NC}"; } -log_error() { echo -e "[Verify ${TIMESTAMP}] ${RED}❌ ERROR: $1${NC}"; } +log() { echo "[Verify ${TIMESTAMP}] $1" >&2; } +log_success() { echo -e "[Verify ${TIMESTAMP}] ${GREEN}✅ $1${NC}" >&2; } +log_warning() { echo -e "[Verify ${TIMESTAMP}] ${YELLOW}⚠️ WARNING: $1${NC}" >&2; } +log_error() { echo -e "[Verify ${TIMESTAMP}] ${RED}❌ ERROR: $1${NC}" >&2; } # ============================================================================== # 1. LOAD CONFIGURATION @@ -59,7 +59,7 @@ APP_HEALTH_URL="${APP_HEALTH_URL:-http://localhost:8001/health}" # Thresholds MAX_SNAPSHOT_AGE_HOURS=8 -MIN_SNAPSHOT_SIZE_MB=1 +MIN_SNAPSHOT_SIZE_KB=10 # 10KB minimum (safe for new/small databases) MAX_DISK_USAGE_PERCENT=85 # Telegram @@ -136,7 +136,7 @@ check_recent_snapshot() { check_snapshot_size() { local snapshot_path="$1" - log "Check 2/8: Snapshot size > ${MIN_SNAPSHOT_SIZE_MB}MB..." + log "Check 2/8: Snapshot size > ${MIN_SNAPSHOT_SIZE_KB}KB..." if [ -z "${snapshot_path}" ] || [ ! -f "${snapshot_path}" ]; then log_warning "No snapshot to size-check." @@ -145,10 +145,10 @@ check_snapshot_size() { local size_bytes size_bytes=$(stat -c %s "${snapshot_path}" 2>/dev/null || stat -f %z "${snapshot_path}" 2>/dev/null) - local min_bytes=$((MIN_SNAPSHOT_SIZE_MB * 1024 * 1024)) + local min_bytes=$((MIN_SNAPSHOT_SIZE_KB * 1024)) if [ "${size_bytes}" -lt "${min_bytes}" ]; then - log_error "Snapshot size is $(numfmt --to=iec ${size_bytes}) which is below minimum ${MIN_SNAPSHOT_SIZE_MB}MB — likely empty dump!" + log_error "Snapshot size is $(numfmt --to=iec ${size_bytes}) which is below minimum ${MIN_SNAPSHOT_SIZE_KB}KB — likely empty dump!" FAILURES=$((FAILURES + 1)) else log_success "Snapshot size: $(numfmt --to=iec ${size_bytes})"