From carlj@peak.org  Tue Mar  5 16:59:52 2013
Return-Path: <carlj@peak.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id E080F4E4
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  5 Mar 2013 16:59:52 +0000 (UTC)
	(envelope-from carlj@peak.org)
Received: from mail-ie0-x232.google.com (mail-ie0-x232.google.com [IPv6:2607:f8b0:4001:c03::232])
	by mx1.freebsd.org (Postfix) with ESMTP id B3CD4F48
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  5 Mar 2013 16:59:52 +0000 (UTC)
Received: by mail-ie0-f178.google.com with SMTP id c13so7902151ieb.23
        for <FreeBSD-gnats-submit@freebsd.org>; Tue, 05 Mar 2013 08:59:52 -0800 (PST)
Received: from bonsai.localnet ([207.55.107.62])
        by mx.google.com with ESMTPS id dy5sm18340245igc.1.2013.03.05.08.59.47
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Tue, 05 Mar 2013 08:59:48 -0800 (PST)
Received: from bonsai.localnet (localhost.localnet [127.0.0.1])
	by bonsai.localnet (Postfix) with ESMTP id D247A3DBD6
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  5 Mar 2013 08:59:45 -0800 (PST)
Received: (from carlj@localhost)
	by bonsai.localnet (8.14.5/8.14.5/Submit) id r25GxjD8029959;
	Tue, 5 Mar 2013 08:59:45 -0800 (PST)
	(envelope-from carlj)
Message-Id: <201303051659.r25GxjD8029959@bonsai.localnet>
Date: Tue, 5 Mar 2013 08:59:45 -0800 (PST)
From: Carl Johnson <carlj@peak.org>
Reply-To: Carl Johnson <carlj@peak.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Only save pkgdb if it has changed
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         176668
>Category:       conf
>Synopsis:       [periodic] [patch] Only save pkgdb if it has changed
>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 05 17:00:02 UTC 2013
>Closed-Date:    
>Last-Modified:  Sun Mar 10 04:49:37 UTC 2013
>Originator:     Carl Johnson
>Release:        FreeBSD 9.1-RELEASE amd64
>Organization:
>Environment:
System: FreeBSD bonsai.localnet 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec 4 09:23:10 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
The periodic daily scripts normally save the entire state of the pkgdb
and a backup, even when there are no changes.  That is a considerable
use of backup space when there is no change.  The accompanying patch to
/etc/periodic/daily/220.backup-pkgdb saves only if there have been some
changes in the /var/db/pkg/ directory.  I have tested the same patch on
8.3-RELEASE and 9.0-RELEASE systems.
>How-To-Repeat:
The normal behaviour is to always save.
>Fix:
--- /etc/periodic/daily/220.backup-pkgdb.orig   2013-03-01 10:45:28.199970000 -0800
+++ /etc/periodic/daily/220.backup-pkgdb        2013-02-27 15:32:45.201213000 -0800
@@ -32,6 +32,12 @@
        echo ''
        echo 'Backing up package db directory:'

+       changes=$(find $pkg_dbdir -newer $bak_file -print 2>&1 | wc -l)
+       if [ "$changes" -eq "0" ] ; then
+           echo 'No changes.'
+           exit 0
+       fi
+
        new_bak_file=`mktemp ${bak_file}-XXXXX`

        if tar -cjHf "${new_bak_file}" "$pkg_dbdir" 2>/dev/null; then
@@ -47,5 +53,6 @@
            rc=3
        fi ;;
 esac
+echo 'Done.'

 exit $rc

>Release-Note:
>Audit-Trail:
>Unformatted:
