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 # Import the local pool if needed and option was given to do so, else error out
27 zpool list -H "$i" >/dev/null 2>&1
29 if [[ $import_export_backup_pool == 1 ]]; then
32 echo "-E- unable to import the pool $i"
36 echo "-E- The local pool, '$i' doesn't seem to exist."
41 # Check to see if any zfs filesystem has a scrub being performed on it now.
42 # If it does, we cannot perform more than one scrub operation at a time.
44 zpool status | grep scan: | grep "in progress" > /dev/null 2>&1
46 # Another zpool scrub operation is already running
47 # Wait until it is done before continuing
48 ransleep=$(($RANDOM % $maxsleeptime))
51 # Another zpool scrub operation is not running
57 echo "$date: Scrub started for zfs pool $i"
60 # Wait until the scrub completes, and check for any errors
62 zpool status $i | grep scan: | grep "in progress" > /dev/null 2>&1
64 # Our zpool scrub operation is still running
65 # Wait until it is done before continuing
66 ransleep=$(($RANDOM % $maxsleeptime))
69 # Our scrub operation has completed
75 echo "$date: Scrub completed for zfs pool $i"
77 # Check for any scrub errors
78 zpool status $i | grep scan: | grep "with 0 errors" > /dev/null 2>&1
80 # The scrub found errors
81 zpool status $i | $mailx -s "zpool scrub $i found errors" $mailto
84 # Export the local pool if told to do so
85 if [[ $import_export_backup_pool == 1 ]]; then
88 fatal_and_exit "-E- unable to export the local pool $i"
93 filesystems=`zfs list -t filesystem | grep "^$i" | grep -v "$i/$i" | grep -v "^$i " | awk '{ print $1 }' | tr '\n' ' '`
94 zfs set sharenfs=on $filesystems