Page 2 of 2

Re: Automating Scrub

PostPosted: Tue Aug 15, 2017 7:17 am
by tangent
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.

Re: Automating Scrub

PostPosted: Thu Aug 24, 2017 10:29 am
by haer22
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

Re: Automating Scrub

PostPosted: Thu Aug 24, 2017 4:55 pm
by lundman
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.

Re: Automating Scrub

PostPosted: Fri Aug 25, 2017 12:43 am
by haer22
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.