From jhellenthal@gmail.com  Thu Apr 14 09:52:02 2011
Return-Path: <jhellenthal@gmail.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A44AA1065674;
	Thu, 14 Apr 2011 09:52:02 +0000 (UTC)
	(envelope-from jhellenthal@gmail.com)
Received: from mail-iw0-f182.google.com (mail-iw0-f182.google.com [209.85.214.182])
	by mx1.freebsd.org (Postfix) with ESMTP id 5462A8FC14;
	Thu, 14 Apr 2011 09:52:02 +0000 (UTC)
Received: by iwn33 with SMTP id 33so1670098iwn.13
        for <multiple recipients>; Thu, 14 Apr 2011 02:52:01 -0700 (PDT)
Received: by 10.42.123.15 with SMTP id p15mr764314icr.93.1302772927118;
        Thu, 14 Apr 2011 02:22:07 -0700 (PDT)
Received: from DataIX.net ([99.19.43.8])
        by mx.google.com with ESMTPS id wo11sm1007110icb.20.2011.04.14.02.22.04
        (version=TLSv1/SSLv3 cipher=OTHER);
        Thu, 14 Apr 2011 02:22:05 -0700 (PDT)
Received: from DataIX.net (localhost [127.0.0.1])
	by DataIX.net (8.14.4/8.14.4) with ESMTP id p3E9M2Ta053053
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Thu, 14 Apr 2011 05:22:02 -0400 (EDT)
	(envelope-from jhell@DataIX.net)
Received: (from jhell@localhost)
	by DataIX.net (8.14.4/8.14.4/Submit) id p3E9M246053052;
	Thu, 14 Apr 2011 05:22:02 -0400 (EDT)
	(envelope-from jhell)
Message-Id: <201104140922.p3E9M246053052@DataIX.net>
Date: Thu, 14 Apr 2011 05:22:02 -0400 (EDT)
From: "J. Hellenthal" <jhell@DataIX.net>
Sender: "J. Hellenthal" <jhellenthal@gmail.com>
Reply-To: "J. Hellenthal" <jhell@DataIX.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc: stable@freebsd.org
Subject: Make 220.backup-pkgdb cd(1) and backup only the package database.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         156396
>Category:       conf
>Synopsis:       Make 220.backup-pkgdb cd(1) and backup only the package database.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dougb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 14 10:00:01 UTC 2011
>Closed-Date:    Thu Apr 14 19:07:24 UTC 2011
>Last-Modified:  Fri Apr 15 17:50:07 UTC 2011
>Originator:     J. Hellenthal
>Release:        FreeBSD 8.2-STABLE i386
>Organization:
>Environment:
System: FreeBSD 8.2-STABLE #0 r220564M Tue Apr 12 10:02:17 EDT 2011 i386

	
>Description:
Currently the backup script archives a full path starting from '/' and then strips the leading slash off of the path which is correct. Upon extraction that full path without the leading slash is extracted in the current directory as var/db/pkg/<contents> with the first two and possibly more directories left empty.

If a user has a different PKG_DBDIR as designated by ports(7) that is larger this can lead to frustration with the length of emptiness in the archive with the leading paths.
	
>How-To-Repeat:
Run ( /etc/periodic/daily/220.backup-pkgdb ) and extract the archive located in /var/backups/
	
>Fix:
This patch makes 220.backup-pkgdb respectifully cd to where the pkgdb is located and create the archive from the relative path so there is only the pkgdb directory and contents upon extraction.

http://patches.jhell.googlecode.com/hg/220.backup-pkgdb_cd.patch?r=f60df831e62d64fd336b6c6612a6619eaf17a17f

diff -r aa37d382121b -r 3fbae1ba29a4 etc/periodic/daily/220.backup-pkgdb
--- a/etc/periodic/daily/220.backup-pkgdb
+++ b/etc/periodic/daily/220.backup-pkgdb
@@ -33,7 +33,8 @@
 
 	new_bak_file=`mktemp ${bak_file}-XXXXX`
 
-	if tar -cjf "${new_bak_file}" "$pkg_dbdir"; then
+	cd $pkg_dbdir/..
+	if tar -cjf "${new_bak_file}" "$(basename $pkg_dbdir)"; then
 	    chmod 644 "${new_bak_file}"
 
 	    if [ -e "${bak_file}.2" -a -e "${bak_file}" ]; then

	


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: dougb 
State-Changed-When: Thu Apr 14 19:04:01 UTC 2011 
State-Changed-Why:  

Thank you for your interest in this issue. However, it's safer to back up 
from the absolute path for a variety of reasons, especially because there 
may be symlinks involved in the path. Given that restoring should be an 
infrequent event we can live with a minor inconvenience at that point to 
have the safety of making sure that the backup itself is valid.  


http://www.freebsd.org/cgi/query-pr.cgi?pr=156396 
Responsible-Changed-From-To: freebsd-bugs->dougb 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Thu Apr 14 19:07:26 UTC 2011 
Responsible-Changed-Why:  

I committed this, and I closed the PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=156396 

From: Pan Tsu <inyaoo@gmail.com>
To: "J. Hellenthal" <jhell@DataIX.net>
Cc: FreeBSD-gnats-submit@FreeBSD.org,  stable@FreeBSD.org
Subject: Re: conf/156396: Make 220.backup-pkgdb cd(1) and backup only the package database.
Date: Fri, 15 Apr 2011 12:57:15 +0400

 "J. Hellenthal" <jhell@DataIX.net> writes:
 
 [...]
 > @@ -33,7 +33,8 @@
 >  
 >  	new_bak_file=`mktemp ${bak_file}-XXXXX`
 >  
 > -	if tar -cjf "${new_bak_file}" "$pkg_dbdir"; then
 > +	cd $pkg_dbdir/..
 > +	if tar -cjf "${new_bak_file}" "$(basename $pkg_dbdir)"; then
 
 Why not use `-s' (substitution) option of bsdtar(1)?
 
   if tar -cjf "${new_bak_file}" -s "|$pkg_dbdir||" "$pkg_dbdir"; then
 
 $(basename $pkg_dbdir) is technically wrong as PKG_DBDIR points not to
 /var/db but to /var/db/pkg by default and is not guaranteed to contain
 `pkg' at the tail, e.g.
 
   PKG_DBDIR is /foo, so /var/backups/pkgdb.bak.tbz-XXX has foo/ prefix
   PKG_DBDIR is /blah/bar, so /var/backups/pkgdb.bak.tbz-YYY has bar/ prefix
 
 It only adds one more hoop to jump through when restoring from backup, e.g.
 
   tar xf /var/backups/pkgdb.bak.tbz-XXX --strip-components 1 -C $PKG_DBDIR ...

From: "J. Hellenthal" <jhell@DataIX.net>
To: Pan Tsu <inyaoo@gmail.com>
Cc: FreeBSD-gnats-submit@FreeBSD.org, stable@FreeBSD.org
Subject: Re: conf/156396: Make 220.backup-pkgdb cd(1) and backup only the
 package database.
Date: Fri, 15 Apr 2011 05:30:45 -0400

 --nFreZHaLTZJo0R7j
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Fri, Apr 15, 2011 at 12:57:15PM +0400, Pan Tsu wrote:
 >"J. Hellenthal" <jhell@DataIX.net> writes:
 >
 >[...]
 >> @@ -33,7 +33,8 @@
 >> =20
 >>  	new_bak_file=3D`mktemp ${bak_file}-XXXXX`
 >> =20
 >> -	if tar -cjf "${new_bak_file}" "$pkg_dbdir"; then
 >> +	cd $pkg_dbdir/..
 >> +	if tar -cjf "${new_bak_file}" "$(basename $pkg_dbdir)"; then
 >
 >Why not use `-s' (substitution) option of bsdtar(1)?
 >
 >  if tar -cjf "${new_bak_file}" -s "|$pkg_dbdir||" "$pkg_dbdir"; then
 >
 >$(basename $pkg_dbdir) is technically wrong as PKG_DBDIR points not to
 >/var/db but to /var/db/pkg by default and is not guaranteed to contain
 >`pkg' at the tail, e.g.
 
 I think you misunderstood how this works. You should test it...
 
 With a pkg_dbdir pointing to /var/db/pkg basename strips off "/var/db/".
 The cd(1) you notice before that line makes sure your in the directory
 just before the actual pkg_dbdir so therefore calling tar on $(basename
 $pkg_dbdir) tar's up only the actual name of the 'pkg' directory and not
 the path before it.
 
 I suppose this could also be achieved simply by:
 
 tar -C $pkg_dbdir/.. -cjf "${new_bak_file}" "$(basename $pkg_dbdir)"
 
 which is equivalent to:
 
 tar -C /var/db/pkg/.. -cvjf /tmp/foo.tbz `basename /var/db/pkg`
 
 '-v' added for show.
 
 But I don't think the author is willing to take any improvements and has
 the wrong impression of why the '/..' is where it is and how that
 suffices for the same motive behind archiving a direct path.
 
 
 PS: The PR says this was committed... It was not AFAIK.
 
 
 --=20
 
  Regards,
 
  J. Hellenthal
 
 
 --nFreZHaLTZJo0R7j
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.17 (FreeBSD)
 Comment: http://bit.ly/0x89D8547E
 
 iQEcBAEBAgAGBQJNqBBEAAoJEJBXh4mJ2FR+4LAH+wTJLhwQRvyMRiXSDia+r6OM
 FiKiehPPvADtp33MpoC9r7iJrw7oUkt19RFeDHkRePe32b0Mav3tsAHXDEzHw/JI
 TJMoDiNZX9IIcx3zgKhd8ITEzXvdZ6rKAKusjKTDR3o/z8eFFc/TRxUo8KfT2OTy
 MWhZh4PTGK4H7cS0/hv2tj/o+/88mTmsag/viV4N4iQXJuPkfF5hSCIWH2p8+6zK
 qe7+UNFX2zilCNnAo4LiijNEsJWy3mFY9ZcRB81RJliVMplpxwL3Tqd8TczK4FtB
 YzQxxw08J0+uZeRsbYCPWUBzmyDwe2N7NSqdZrJ4NfuATulwIrZe+Uvm0Q5pO8o=
 =szKz
 -----END PGP SIGNATURE-----
 
 --nFreZHaLTZJo0R7j--

From: Doug Barton <dougb@FreeBSD.org>
To: "J. Hellenthal" <jhell@DataIX.net>
Cc: Pan Tsu <inyaoo@gmail.com>, stable@FreeBSD.org, 
 FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/156396: Make 220.backup-pkgdb cd(1) and backup only the
 package database.
Date: Fri, 15 Apr 2011 10:47:25 -0700

 On 04/15/2011 02:30, J. Hellenthal wrote:
 > PS: The PR says this was committed... It was not AFAIK.
 
 I committed the script itself, which is why I picked up the PR.
 
 This is an excellent example of a bikeshed issue since it's something 
 simple enough that everyone feels qualified to offer an opinion on. And 
 yet, there is no actual problem here. As I said when I closed the PR, 
 using the full path is the safest, most conservative option, and there 
 is no reason to do otherwise. Let's move on.
 
 
 Doug
 
 -- 
 
 	Nothin' ever doesn't change, but nothin' changes much.
 			-- OK Go
 
 	Breadth of IT experience, and depth of knowledge in the DNS.
 	Yours for the right price.  :)  http://SupersetSolutions.com/
 
>Unformatted:
