Updated paths
[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 PATH=/usr/sbin:/sbin:$PATH
10
11 maxsleeptime=360
12 logfile=/var/log/zfs/zfs-scrub.log
13
14 for i in tank storage
15 do
16   # Check to see if this zfs filesystem has a scrub being performed on it now.
17   # If it does, we cannot perform more than one scrub operation at a time.
18   while true; do
19     zpool status | grep scrub: | grep "in progress" > /dev/null 2>&1
20     if [ $? == 0 ]; then
21         # Another zpool scrub operation is already running
22         # Wait until it is done before continuing
23         ransleep=$(($RANDOM % $maxsleeptime))
24         sleep $ransleep
25     else
26         # Another zpool scrub operation is not running
27         break
28     fi
29   done
30
31   date=`date`
32   echo "$date: Scrub started for zfs pool $i" >> $logfile
33   zpool scrub $i
34   sleep 60
35
36 done