Automating Scrub

Developer discussions.

Re: Automating Scrub

Postby tangent » Tue Aug 15, 2017 7:17 am

While I do get the value in periodic scrubbing, particularly for pools that primarily hold infrequently-read data, what I don't get is why this needs to be a feature of O3X. It's two steps to do this yourself:

First:

Code: Select all
$ sudo crontab -e


Second, add this to the file in the editor the first command opens:

Code: Select all
@weekly /usr/local/bin/zpool scrub pool1 pool2


The full path to the zpool command is necessary because /usr/local/bin isn't in root's PATH on macOS. Even if you've modified your OS to change that, it's still good security practice.

Modify the list of pools as is locally appropriate.

It doesn't redirect any output because the command doesn't cause any unless there is a failure to start the scrub. You might want to somehow monitor the output of `zpool status` during the scrub, however.
tangent
 
Posts: 47
Joined: Tue Nov 11, 2014 6:58 pm

Re: Automating Scrub

Postby haer22 » Thu Aug 24, 2017 10:29 am

I scrub my three pools once a month on Friday night. As that is impossible to express in crontab I wrote a scrip that checks the the current weekday is a Friday.

Feel free to re-use/re-design it.

Call in crontab:
Code: Select all
scrub=/Users/hans/scrub.sh
# scrub once a month, the scrubscript only works once per week
1 1 1-7 * *   $scrub gaia               >> $log 2>&1
2 1 15-21  * *   $scrub zeus               >> $log 2>&1



Code: Select all
#!/bin/sh
PATH=${PATH}:/usr/local/bin
dateFmt="+%F_%T_(%a)"
#
scrubDay=5      # 0-6: Sun, Mon, ... Sat
wDay=$(date +%w)
#echo $wDay

if [ "$1" = "-force" ]; then
    wDay=$scrubDay
    echo Forced!
    shift
fi

if [ $wDay -eq $scrubDay ]; then
    echo $(date "$dateFmt") SCRUBDAY!
    zpool scrub $1
    sleep 5
    zpool status $1 | sed '/config:/,$d'
else
    echo $(date "$dateFmt") No scrubbing today "($1)"
fi
haer22
 
Posts: 123
Joined: Sun Mar 23, 2014 2:13 am

Re: Automating Scrub

Postby lundman » Thu Aug 24, 2017 4:55 pm

If my memory serves me, the legacy way to run something on the first Sunday of the month, was to add cron to run on all Sundays, then check if the day-of-month is 1-6 inclusive.

Like:
Code: Select all
00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script


Best part of Unix is that there are many solutions to the same problem, this is just another way to achieve the same thing.
User avatar
lundman
 
Posts: 1335
Joined: Thu Mar 06, 2014 2:05 pm
Location: Tokyo, Japan

Re: Automating Scrub

Postby haer22 » Fri Aug 25, 2017 12:43 am

Aah, short and sweet!
lundman wrote:
Code: Select all
00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script

I try to keep my crontab as simple as possible so I usually put any logic in scripts. Debugging a missing end-quote, variable expansion, parenthesis etc in cron is not optimal.
haer22
 
Posts: 123
Joined: Sun Mar 23, 2014 2:13 am

Previous

Return to OpenZFS on OS X Development

Who is online

Users browsing this forum: No registered users and 17 guests

cron