Last active
March 2, 2022 13:44
-
-
Save morph027/b86d8bc374a104766dcf 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
Hm...if i pass nothing, i get a list of all my pools...
And you're right, at the moment, a non-existing pool obviously won't get scrubbed ;)
I ported things here.... https://github.com/morph027/zfs-cron-scrub-all-pools-sequentially
Will add these