Skip to content

Instantly share code, notes, and snippets.

@poikilotherm
Forked from morph027/scrub-all.sh
Last active April 14, 2017 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save poikilotherm/ca1687e76b9fc8514485 to your computer and use it in GitHub Desktop.
Save poikilotherm/ca1687e76b9fc8514485 to your computer and use it in GitHub Desktop.
scrub all zfs on linux pools sequentially (with option to exclude pools)
#!/bin/bash
##
## --exclude takes one pool or a comma seperated list of pools
##
## Example: scrub-all.sh --exclude rpool
## Example: scrub-all.sh --exclude rpool,tank-foo,tank-bar
##
EMAIL_RECIPIENT="foo@bar.com"
SCRIPT=${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}
ARGS=$(getopt -o e: -l "exclude:" -n "$SCRIPT" -- "$@");
eval set -- "$ARGS";
while true
do
case "$1" in
-e|--exclude)
shift
if [ -n "$1" ]; then
EXCLUDE=$1
shift
fi
;;
--)
shift
break
;;
*)
error "wrong/missing parameters"
exit 1
;;
esac
done
EXCLUDE_LIST="${EXCLUDE/,/\$\\|^}"
ZPOOLS=( $(zpool list -H -o name | sed "/\(^${EXCLUDE_LIST}$\)/d") )
for ZPOOL in ${ZPOOLS[@]}
do
# start scrubbing
zpool scrub $ZPOOL
# wait till scrub is finished
while zpool status $ZPOOL | grep 'scan: *scrub in progress' > /dev/null
do
sleep 10
done
# send a report
zpool status $ZPOOL | mail -s "zpool status: $ZPOOL" $EMAIL_RECIPIENT
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment