diff --git a/opt/05-backups/scripts/health-check-alerting.sh b/opt/05-backups/scripts/health-check-alerting.sh index 5613976..9919208 100755 --- a/opt/05-backups/scripts/health-check-alerting.sh +++ b/opt/05-backups/scripts/health-check-alerting.sh @@ -142,35 +142,37 @@ check_r2_usage() { source /opt/05-backups/restic/.env - # Get R2 stats - local r2_stats=$(restic stats --mode restore-size 2>/dev/null | grep "Total Size") + # Get R2 stats - use raw-data mode to get actual R2 storage usage (with deduplication) + local r2_stats=$(restic stats --mode raw-data 2>/dev/null | grep "Total Size") if [[ -z "$r2_stats" ]]; then add_warning "Unable to get R2 statistics" return fi - local size_gb=$(echo "$r2_stats" | grep -oP '\d+\.\d+' | head -1) + # Extract size in GiB and convert to GB + local size_gib=$(echo "$r2_stats" | grep -oP '\d+\.\d+' | head -1) + local size_gb=$(echo "$size_gib" | awk '{printf "%.2f", $1}') local r2_limit=10 # Cloudflare R2 free tier limit: 10 GB # Check if bc is available for floating point comparison if command -v bc &> /dev/null; then if (( $(echo "$size_gb > $r2_limit" | bc -l) )); then - add_problem "R2 storage EXCEEDED: ${size_gb}GB / ${r2_limit}GB limit" + add_problem "R2 storage EXCEEDED: ${size_gb}GB / ${r2_limit}GB limit (raw storage used)" elif (( $(echo "$size_gb > 8" | bc -l) )); then add_warning "R2 storage high: ${size_gb}GB / ${r2_limit}GB (>80%)" else - log "✅ R2 storage OK: ${size_gb}GB / ${r2_limit}GB" + log "✅ R2 storage OK: ${size_gb}GB / ${r2_limit}GB (raw storage with deduplication)" fi else # Fallback: use integer comparison if bc not available local size_gb_int=$(echo "$size_gb" | cut -d. -f1) if [[ "$size_gb_int" -gt "$r2_limit" ]]; then - add_problem "R2 storage EXCEEDED: ${size_gb}GB / ${r2_limit}GB limit" + add_problem "R2 storage EXCEEDED: ${size_gb}GB / ${r2_limit}GB limit (raw storage used)" elif [[ "$size_gb_int" -gt 8 ]]; then add_warning "R2 storage high: ${size_gb}GB / ${r2_limit}GB (>80%)" else - log "✅ R2 storage OK: ${size_gb}GB / ${r2_limit}GB" + log "✅ R2 storage OK: ${size_gb}GB / ${r2_limit}GB (raw storage with deduplication)" fi fi