From owner-freebsd-fs@FreeBSD.ORG Thu Jun 10 19:11:22 2010 Return-Path: Delivered-To: fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0A516106567C for ; Thu, 10 Jun 2010 19:11:22 +0000 (UTC) (envelope-from jhellenthal@gmail.com) Received: from mail-pw0-f54.google.com (mail-pw0-f54.google.com [209.85.160.54]) by mx1.freebsd.org (Postfix) with ESMTP id C65A98FC08 for ; Thu, 10 Jun 2010 19:11:21 +0000 (UTC) Received: by pwj1 with SMTP id 1so154190pwj.13 for ; Thu, 10 Jun 2010 12:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:cc:subject:references:in-reply-to :x-enigmail-version:openpgp:content-type:content-transfer-encoding; bh=kr9TGqryv95PLQPydMzDZEJ669kD8Xs8cIiI9T1H9E8=; b=Xs2pPKntmo9nxXa0fJxPVxlR0C5Q+iLGD/PxT359oklmDeFAvaNucEdLrZI3hMUQ3p rQXhHDFzPRGbiRHjepDxK5e+jLlRVKxkryddUw2YK87Aw+TpCMOyCe0bkcmneOAki4fz vgsdq34vhvRcC+tYjDnWtwe+spR9eiaWNqEjs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:cc:subject :references:in-reply-to:x-enigmail-version:openpgp:content-type :content-transfer-encoding; b=JsQU+kx8Q28G9j6hJhOD9DzGnAcJLY+UvLldwhdXmkq/7MRJXyjZAUDhvcdrfrG1cl ij4+jajVKKu6wUGYrG239aYMLIBWrf4nFoBBObAXkDIAydtZLuNYnsGIkcnih0i698SP /m1GTPvfoh2c4GjV61XG6d48T/TfQwjFd0hdE= Received: by 10.143.26.1 with SMTP id d1mr428550wfj.311.1276197076119; Thu, 10 Jun 2010 12:11:16 -0700 (PDT) Received: from centel.dataix.local (adsl-99-181-128-180.dsl.klmzmi.sbcglobal.net [99.181.128.180]) by mx.google.com with ESMTPS id s21sm186820wff.12.2010.06.10.12.11.13 (version=SSLv3 cipher=RC4-MD5); Thu, 10 Jun 2010 12:11:14 -0700 (PDT) Sender: "J. Hellenthal" Message-ID: <4C1138D0.7070901@dataix.net> Date: Thu, 10 Jun 2010 15:11:12 -0400 From: jhell User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.9.1.9) Gecko/20100515 Thunderbird MIME-Version: 1.0 References: <20100609162627.11355zjzwnf7nj8k@webmail.leidinger.net> <4C0FAE2A.7050103@dataix.net> <4C0FB1DE.9080508@dataix.net> <20100610115324.10161biomkjndvy8@webmail.leidinger.net> <20100610173825.164930ekkryr5tes@webmail.leidinger.net> In-Reply-To: X-Enigmail-Version: 1.0.1 OpenPGP: id=89D8547E Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Alexander Leidinger , fs@freebsd.org Subject: Re: Do we want a periodic script for a zfs scrub? X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jun 2010 19:11:22 -0000 On 06/10/2010 12:34, Artem Belevich wrote: > You can do something like this: > > #SCRUB_TS="2010-06-08.20:51:12" > SCRUB_TS=$1 > # parse timestamp, move it forward by 1 month and print in seconds since Epoch > NEXT_SCRUB_DATE_S=`date -j -f "%Y-%m-%d.%H:%M:%S" -v+1m +"%s" $SCRUB_TS` > # for debugging purposes convert epoch time into something human-readable > NEXT_SCRUB_DATE=`date -r $NEXT_SCRUB_DATE` > # surrent time in secs since Epoch. > NOW_S=`date +"%s"` > # Compare two times to figure out if next scrub time is still in the future > if [ $NOW_S -gt $NEXT_SCRUB_DATE_S ]; then > echo yup. > else > echo nope. > fi > > --Artem #!/bin/sh lastscrub=$(zpool history exports |grep scrub |tail -1 |cut -f1 -d.) todaypoch=$(date -j -f "%Y-%m-%d" "+%s" $(date "+%Y-%m-%d")) scrubpoch=$(date -j -f "%Y-%m-%d" "+%s" $lastscrub) echo $lastscrub Last Scrub From zpool history echo $todaypoch Today converted to seconds since epoch echo $scrubpoch Last scrub converted to seconds since epoch expired=$((((($todaypoch-$scrubpoch)/60)/60)/24)) if [ ${expired:=30} -ge ${daily_scrub_zfs_threshold:=30} ]; then echo "Performing Scrub...." else echo "SORRY its only been $expired days since your last scrub." fi My reasoning for setting expired to have a default value of 30 depended on whether a pool may have just been created in which a scrub would have never been performed thus with this value being equal to that of the default threshold would allow that pool to be scrubbed on the first day it was created. I considered just doing ${expired:=${daily_scrub_zfs_threshold:=30}} which would also allow it to be set to whatever a user set their value to before the pool was created and adds another layer of redundancy on that variable in a fail-safe sort of way. Regards & nice work on this. I just noticed the CFT just after writing this. but still have a look at the above it may simplify the testing while providing some fallback for what I stated above. > > > > On Thu, Jun 10, 2010 at 8:38 AM, Alexander Leidinger > wrote: >> Quoting Artem Belevich (from Thu, 10 Jun 2010 07:59:46 >> -0700): >> >>>> Good idea! I even found a command line which does the calculation for the >>>> number of days between "now" and the last run (not taking a leap year >>>> into >>>> account, but an off-by-one day error here does not matter). >>> >>> You can get exactly one month difference by using -v option of 'date' >>> command to figure out the time/date offset by arbitrary amount. >>> Combined with +"%s" format to print number of seconds since Epoch and >>> -r to specify the reference point in time it makes 'date' pretty >>> useful in scripts. >> >> What we have is the date of the last scrub (e.g. 2010-06-08.20:51:12), and >> what we want to know is if between the last scrub and now we passed a >> specific amount of days or not. >> >> What I do is taking the year multiplied with 365 plus the day of the year. >> Both of this for the last date of the scrub and "now". The difference is the >> number of days between those two dates. This value I can use with -le or -ge >> for the test command. >> >> This is only off by one once in a leap year when the leap-day is in-between >> the two dates (those people which want to scrub every 4 years are off by two >> when both leap-days are in-between, but a scrub of every 4 years or more >> looks unreasonable to me, so I do not care much about this). >> >> This is done in one line with two calls to date (once for the last scrub, >> once for "now") and a little bit of shell-buildin-arithmetic. If you have a >> more correct version which is not significantly more complex, feel free to >> share it here. >> >> Bye, >> Alexander. >> >> -- >> "Who would have though hell would really exist? And that it would be in New >> Jersey?" -Leela >> "Actually..." - Fry >> >> http://www.Leidinger.net Alexander @ Leidinger.net: PGP ID = B0063FE7 >> http://www.FreeBSD.org netchild @ FreeBSD.org : PGP ID = 72077137 >> > _______________________________________________ > freebsd-fs@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-fs > To unsubscribe, send any mail to "freebsd-fs-unsubscribe@freebsd.org" -- jhell