scripts_NAS4Free
scripts_NAS4Free copied to clipboard
scrubPool.sh: scrub only one pool
Sometimes it is useful to scrub pools separately since multiple scrubs can lead to a huge resource consumption. It would be a good idea to schedule scrubbing different pools at different times.
I added a new script scrubPool.sh for scrubbing only one pool which is specified as a command line argument:
scrubPool.sh my_pool_name
I just took the original scrubPools.sh and added POOL_NAME for each zpool invocation and made some cleanups.
See the difference:
--- scrubPools.sh Sun May 04 21:46:17 2025
+++ scrubPool.sh Sun Oct 12 10:18:16 2025
@@ -25,6 +25,9 @@
readonly LOGFILE="$CFG_LOG_FOLDER/$SCRIPT_NAME.log"
readonly TMPFILE_ARGS="$CFG_TMP_FOLDER/$SCRIPT_NAME.$$.args.tmp"
+# Pool name
+POOL_NAME=""
+
# Set variables corresponding to the input parameters
ARGUMENTS="$@"
@@ -53,11 +56,13 @@
# Check if the number of mandatory parameters
# provided is as expected
- if [ "$#" -ne "0" ]; then
- echo "No mandatory arguments should be provided"
+ if [ "$#" -ne "1" ]; then
+ echo "Exactly one mandatory argument should be provided"
return 1
fi
+ POOL_NAME="$1"
+
return 0
}
@@ -67,7 +72,7 @@
# 1 otherwise
##################################
scrubInProgress() {
- if $BIN_ZPOOL status | grep "scrub in progress">/dev/null; then
+ if $BIN_ZPOOL status $POOL_NAME | grep "scrub in progress">/dev/null; then
return 0
else
return 1
@@ -82,22 +87,19 @@
main() {
# Starting scrubbing
- log_info "$LOGFILE" "Starting scrubbing"
- $BIN_ZPOOL list -H -o name | while read pool; do
- $BIN_ZPOOL scrub $pool
- log_info "$LOGFILE" "Starting scrubbing of pool: $pool"
- done
+ log_info "$LOGFILE" "Starting scrubbing of pool: $POOL_NAME"
+ $BIN_ZPOOL scrub $POOL_NAME
# Waiting for the end of the scrubbing
while scrubInProgress; do sleep 10; done;
- log_info "$LOGFILE" "Scrub finished for all pools"
+ log_info "$LOGFILE" "Scrub finished for pool: $POOL_NAME"
- # Check if the pools are healthy
- if ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE=1 $BIN_ZPOOL status -x | grep "all pools are healthy">/dev/null; then
- ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE=1 $BIN_ZPOOL status -x | log_info "$LOGFILE"
+ # Check if the pool is healthy
+ if ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE=1 $BIN_ZPOOL status -x $POOL_NAME | grep "is healthy">/dev/null; then
+ ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE=1 $BIN_ZPOOL status -x $POOL_NAME | log_info "$LOGFILE"
return 0
else
- $BIN_ZPOOL status -v | log_error "$LOGFILE"
+ $BIN_ZPOOL status -v $POOL_NAME | log_error "$LOGFILE"
return 1
fi
}