better check to input and resilvers

This commit is contained in:
2026-10-10 17:18:12 +02:00
parent 9e698ca02a
commit 781e133477

View File

@@ -27,6 +27,10 @@ while [ "$#" -gt 0 ]; do
shift 2 shift 2
;; ;;
--label) --label)
if [ "$#" -lt 2 ] || [ -z "$2" ]; then
echo "Error: --label requires a non-empty argument" >&2
exit 1
fi
opt_label="$2" opt_label="$2"
shift 2 shift 2
;; ;;
@@ -42,6 +46,10 @@ while [ "$#" -gt 0 ]; do
shift 2 shift 2
;; ;;
--prefix) --prefix)
if [ "$#" -lt 2 ] || [ -z "$2" ]; then
echo "Error: --prefix requires a non-empty argument" >&2
exit 1
fi
opt_prefix="$2" opt_prefix="$2"
shift 2 shift 2
;; ;;
@@ -60,11 +68,11 @@ done
ZPOOL_STATUS=$(env LC_ALL=C zpool status 2>&1) ZPOOL_STATUS=$(env LC_ALL=C zpool status 2>&1)
# Identify pools that should NOT receive snapshots: # Identify pools that should NOT receive snapshots:
# - Pools currently running a scrub (to avoid additional I/O load). # - Pools currently running a scrub or resilver (to avoid additional I/O load).
# - Pools in unhealthy states (anything other than ONLINE or DEGRADED). # - Pools in unhealthy states (anything other than ONLINE or DEGRADED).
ZPOOLS_EXCLUDED=$(echo "$ZPOOL_STATUS" | awk -F ': ' ' ZPOOLS_EXCLUDED=$(echo "$ZPOOL_STATUS" | awk -F ': ' '
$1 ~ /^ *pool$/ { pool = $2 } $1 ~ /^ *pool$/ { pool = $2 }
$1 ~ /^ *scan$/ && $2 ~ /scrub in progress/ { print pool } $1 ~ /^ *scan$/ && $2 ~ /(scrub|resilver) in progress/ { print pool }
$1 ~ /^ *state$/ && $2 !~ /ONLINE|DEGRADED/ { print pool } $1 ~ /^ *state$/ && $2 !~ /ONLINE|DEGRADED/ { print pool }
' | sort -u) ' | sort -u)