Not needed for Nexenta
[zfs-nexenta/.git] / zfs-scrub
1 #!/bin/bash
2
3 # Author: Alan J. Pippin
4 # Description: This script will attempt to scrub each zfs pool
5 #              given to it in the for loop. This script ensures
6 #              That only 1 scrub operation is running at any given time.
7 #              This serializes the zfs scrub process for each pool.
8
9 maxsleeptime=360
10 logfile=/var/log/zfs/zfs-scrub.log
11
12 for i in tank storage
13 do
14   # Check to see if this zfs filesystem has a scrub being performed on it now.
15   # If it does, we cannot perform more than one scrub operation at a time.
16   while true; do
17     /sbin/zpool status | grep scrub: | grep "in progress" > /dev/null 2>&1
18     if [ $? == 0 ]; then
19         # Another zpool scrub operation is already running
20         # Wait until it is done before continuing
21         ransleep=$(($RANDOM % $maxsleeptime))
22         sleep $ransleep
23     else
24         # Another zpool scrub operation is not running
25         break
26     fi
27   done
28
29   date=`date`
30   echo "$date: Scrub started for zfs pool $i" >> $logfile
31   /sbin/zpool scrub $i
32   sleep 60
33
34 done