3 # Author: Alan J. Pippin
4 # Description: This script will attempt to scrub a given pool.
5 # This script ensures that only 1 scrub operation is
6 # running at any given time. This serializes the zfs
7 # scrub process for any pool.
9 # source our configuration
10 config="${0%/*}/zfs-scripts.conf"
11 [ -e "${config}.dist" ] && . ${config}.dist
12 [ -e "${config}" ] && . ${config}
14 exec >> $logdir/zfs-scrub.log 2>&1
19 if [ -z "$pools" ]; then
20 echo "-E- Usage: $0 <pools>"
26 # Check to see if any zfs filesystem has a scrub being performed on it now.
27 # If it does, we cannot perform more than one scrub operation at a time.
29 zpool status | grep scan: | grep "in progress" > /dev/null 2>&1
31 # Another zpool scrub operation is already running
32 # Wait until it is done before continuing
33 ransleep=$(($RANDOM % $maxsleeptime))
36 # Another zpool scrub operation is not running
42 echo "$date: Scrub started for zfs pool $i"
45 # Wait until the scrub completes, and check for any errors
47 zpool status $i | grep scan: | grep "in progress" > /dev/null 2>&1
49 # Our zpool scrub operation is still running
50 # Wait until it is done before continuing
51 ransleep=$(($RANDOM % $maxsleeptime))
54 # Our scrub operation has completed
60 echo "$date: Scrub completed for zfs pool $i"
62 # Check for any scrub errors
63 zpool status $i | grep scan: | grep "with 0 errors" > /dev/null 2>&1
65 # The scrub found errors
66 zpool status $i | $mailx -s "zpool scrub $i found errors" $mailto