Skip to content

Instantly share code, notes, and snippets.

@jrk
Created March 30, 2009 20:42
Show Gist options
  • Save jrk/87879 to your computer and use it in GitHub Desktop.
Save jrk/87879 to your computer and use it in GitHub Desktop.
#
# this script will go through all pools and scrub them one at a time
# Via http://aspiringsysadmin.com/blog/2007/06/07/scrub-your-zfs-file-systems-regularly/
#
[email protected]
ZPOOL=/usr/sbin/zpool
TMPFILE=/tmp/scrub.sh.$$.$RANDOM
scrub_in_progress() {
if $ZPOOL status $1 | grep "scrub in progress" >/dev/null; then
return 0
else
return 1
fi
}
$ZPOOL list | sed 1d | cut -d' ' -f1 | while read pool; do
$ZPOOL scrub $pool
while sleep 60; do
if ! scrub_in_progress $pool; then
break
fi
done
if ! $ZPOOL status $pool | grep "with 0 errors" >/dev/null; then
$ZPOOL status $pool >>$TMPFILE
fi
done
if [ -s $TMPFILE ]; then
cat $TMPFILE | mailx -s "zpool scrub on `hostname` generated errors" $MAILRECIPIENT
fi
rm -f $TMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment