conf/156396: Make 220.backup-pkgdb cd(1) and backup only the package database.

Pan Tsu inyaoo at gmail.com
Fri Apr 15 09:23:57 UTC 2011


"J. Hellenthal" <jhell at 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 ...


More information about the freebsd-stable mailing list