-
-
Save poikilotherm/ca1687e76b9fc8514485 to your computer and use it in GitHub Desktop.
scrub all zfs on linux pools sequentially (with option to exclude pools)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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="[email protected]" | |
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