From owner-freebsd-bugs@FreeBSD.ORG Tue Mar 4 20:10:02 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E9C01065682 for ; Tue, 4 Mar 2008 20:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 596848FC3E for ; Tue, 4 Mar 2008 20:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m24KA2HJ084669 for ; Tue, 4 Mar 2008 20:10:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m24KA2sR084668; Tue, 4 Mar 2008 20:10:02 GMT (envelope-from gnats) Resent-Date: Tue, 4 Mar 2008 20:10:02 GMT Resent-Message-Id: <200803042010.m24KA2sR084668@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Stefan Moeding Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 902B41065672 for ; Tue, 4 Mar 2008 20:03:22 +0000 (UTC) (envelope-from sm@moeding.net) Received: from stingray.moeding.net (stingray.moeding.net [87.230.84.172]) by mx1.freebsd.org (Postfix) with ESMTP id 22C268FC36 for ; Tue, 4 Mar 2008 20:03:21 +0000 (UTC) (envelope-from sm@moeding.net) Received: from esprit.setuid.de (p50885CDA.dip.t-dialin.net [80.136.92.218]) by stingray.moeding.net (8.13.8/8.13.8/Debian-3) with ESMTP id m24Jkpuu009475 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 4 Mar 2008 20:46:55 +0100 Received: from esprit.setuid.de (localhost [127.0.0.1]) by esprit.setuid.de (8.14.2/8.14.2) with ESMTP id m24Jkpg7002194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 4 Mar 2008 20:46:51 +0100 (CET) (envelope-from sm@esprit.setuid.de) Received: (from sm@localhost) by esprit.setuid.de (8.14.2/8.14.2/Submit) id m24Jkpkb002193; Tue, 4 Mar 2008 20:46:51 +0100 (CET) (envelope-from sm) Message-Id: <200803041946.m24Jkpkb002193@esprit.setuid.de> Date: Tue, 4 Mar 2008 20:46:51 +0100 (CET) From: Stefan Moeding To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/121366: [zfs] [patch] Automatic disk scrubbing from periodic(8) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Stefan Moeding List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Mar 2008 20:10:02 -0000 >Number: 121366 >Category: bin >Synopsis: [zfs] [patch] Automatic disk scrubbing from periodic(8) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Mar 04 20:10:01 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Stefan Moeding >Release: FreeBSD 7.0-STABLE i386 >Organization: >Environment: System: FreeBSD elan.setuid.de 7.0-STABLE FreeBSD 7.0-STABLE #23: Sat Mar 1 14:17:18 CET 2008 root@elan.setuid.de:/usr/obj/usr/src/sys/ELAN i386 >Description: The ZFS Best Practices Guide recommends disk scrubbing on a regular basis. The attached file fits into the periodic(8) framework to start a weekly scrub. It will look at all pools and choose one of them on a round-robin basis depending on the date of the last scrub/resilver unless there is already a scrub or resilver running. The script should probably be installed to run at the end the weekly schedule to avoid I/O contention from scrubbing and other weekly scripts. The new periodic(8) switch 'weekly_zfs_scrubbing_enable' is introduced. One drawback: ZFS seems to forget the time of a scrub/resilver when shutting down. On machines with regular reboots and multiple pools the script will probably pick the same pool every time. >How-To-Repeat: >Fix: #!/bin/sh # # $FreeBSD$ # # If there is a global system configuration file, suck it in. # if [ -r /etc/defaults/periodic.conf ] then . /etc/defaults/periodic.conf source_periodic_confs fi scrubdate() { # Echo lines with timestamp (0=never, -1=running) # of last scrub/resilver and pool name to stdout. for pool in $(/sbin/zpool list -H -o name); do /sbin/zpool status ${pool} | while read line; do case "$line" in scrub:\ scrub\ completed*|scrub:\ resilver\ completed*) # Extract date from zpool output and convert to epoch date=$(echo $line | sed 's/^scrub: .* on //') date=$(date -jn -f "%+" "$date" +"%s") echo $date $pool ;; scrub:\ scrub\ in\ progress*|scrub:\ resilver\ in\ progress*) # Scrub or resilver is running echo -1 $pool ;; scrub:\ none\ requested) # Pool has never been scrubed or resilvered echo 0 $pool ;; esac done done } case "$weekly_zfs_scrubbing_enable" in [Yy][Ee][Ss]) line=$(scrubdate | sort -n | head -1) if [ -n "$line" ]; then date=$(echo $line | cut -d" " -f1) pool=$(echo $line | cut -d" " -f2) echo "" case "$date" in -1) echo "Scrub or resilver is running for pool $pool:" /sbin/zpool status $pool rc=1 ;; *) echo "Starting scrub for pool $pool:" /sbin/zpool scrub $pool rc=$? ;; esac else echo '$weekly_zfs_scrubbing_enable is set' \ 'but no zfs pools have been created' rc=2 fi;; *) rc=0;; esac exit $rc >Release-Note: >Audit-Trail: >Unformatted: