conf/176668: [PATCH] Only save pkgdb if it has changed

Carl Johnson carlj at
Tue Mar 5 17:00:02 UTC 2013

>Number:         176668
>Category:       conf
>Synopsis:       [PATCH] Only save pkgdb if it has changed
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 05 17:00:02 UTC 2013
>Originator:     Carl Johnson
>Release:        FreeBSD 9.1-RELEASE amd64
System: FreeBSD bonsai.localnet 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec 4 09:23:10 UTC 2012 root at amd64
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.
The normal behaviour is to always save.
--- /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 @@
        fi ;;
+echo 'Done.'

 exit $rc


More information about the freebsd-bugs mailing list