Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

regenerating /var/db/pkg

1,045 views
Skip to first unread message

Aryeh M. Friedman

unread,
Apr 20, 2010, 10:11:24 PM4/20/10
to
I acciddentally rm'ed my /var/db/pkg and want to know is it possible to
rgenerate it (I have portmaster and portupgrade installed)
_______________________________________________
freebsd...@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hacke...@freebsd.org"

Doug Barton

unread,
Apr 22, 2010, 1:43:37 AM4/22/10
to
On 4/20/2010 7:11 PM, Aryeh M. Friedman wrote:
> I acciddentally rm'ed my /var/db/pkg and want to know is it possible to
> rgenerate it (I have portmaster and portupgrade installed)

Portmaster certainly can't do this, it uses the information from
/var/db/pkg. I'm not sure if portupgrade can do it or not.

Your most likely course of success is to generate a list of ports that
you know you're using ("root" and "leaf" ports in portmaster
terminology), back up any config or other key files from /usr/local,
then delete everything and reinstall.


Good luck,

Doug

--

... and that's just a little bit of history repeating.
-- Propellerheads

Improve the effectiveness of your Internet presence with
a domain name makeover! http://SupersetSolutions.com/

Samuel Martín Moro

unread,
Apr 22, 2010, 2:07:39 AM4/22/10
to
I once coded a shellscript to do that, restore from corrupted pkgdb
I have it at work (if you can wait until next monday)
the easyest way I found was to pkg_add -Ff every package missing in
pkg_info, and extract missing files from packages still there
but you would need a package list to do that


Samuel Martín Moro
{EPITECH.} tek4
CamTrace S.A.S


On Thu, Apr 22, 2010 at 7:43 AM, Doug Barton <do...@freebsd.org> wrote:

> a

Ruben de Groot

unread,
Apr 22, 2010, 7:17:58 AM4/22/10
to
On Wed, Apr 21, 2010 at 10:43:37PM -0700, Doug Barton typed:

> On 4/20/2010 7:11 PM, Aryeh M. Friedman wrote:
> > I acciddentally rm'ed my /var/db/pkg and want to know is it possible to
> > rgenerate it (I have portmaster and portupgrade installed)
>
> Portmaster certainly can't do this, it uses the information from
> /var/db/pkg. I'm not sure if portupgrade can do it or not.
>
> Your most likely course of success is to generate a list of ports that
> you know you're using ("root" and "leaf" ports in portmaster
> terminology), back up any config or other key files from /usr/local,
> then delete everything and reinstall.

This question (how to restore /var/db/pkg) comes up fairly regularly. How
about adding a /etc/periodic/daily/220.backup-pkgdb script or something?

Just asking opinions, if people want this, I'll make a patch and
file a PR.

Ruben

Eitan Adler

unread,
Apr 22, 2010, 8:21:16 AM4/22/10
to
>
> Just asking opinions, if people want this, I'll make a patch and
> file a PR.
>

Is this script correct?

#!/bin/sh
#
# $FreeBSD: src/etc/periodic/daily/210.backup-aliases,v 1.6.36.1.2.1
2009/10/25 01:10:29 kensmith Exp $
#

# 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

bak=/var/backups
db_loc="/var/db/pkg";
bk_loc="/$bak/pkgdb.bak.tar"

case "$daily_backup_pkgdb_enable" in
[Yy][Ee][Ss])
if [ ! -d $db_loc ]
then
echo '$daily_backup_pkgdb_enable is enabled but' \
"$db_loc doesn't exist"
rc=2
else
rc=0

echo ""
echo "Backing up mail aliases:"

if [ ! -f $bk_loc ]
then
echo "no $bk_loc"
tar -cjf $bk_loc $db_loc || rc=3
fi
fi;;

*) rc=0;;
esac

exit $rc

Diane Bruce

unread,
Apr 22, 2010, 8:49:32 AM4/22/10
to
On Tue, Apr 20, 2010 at 10:11:24PM -0400, Aryeh M. Friedman wrote:
> I acciddentally rm'ed my /var/db/pkg and want to know is it possible to
> rgenerate it (I have portmaster and portupgrade installed)


You would have to write a script which went through each file in
/usr/local/bin and /usr/local/lib (mostly sufficient) and examined
every single pkg-plist looking for the corresponding file. Then you
know what port the file was generated by. Needless to say, this would
be somewhat horrible.

- Diane
--
- d...@FreeBSD.org d...@db.net http://www.db.net/~db

Eitan Adler

unread,
Apr 22, 2010, 9:12:08 AM4/22/10
to
> Hmm, I guess you shouldn't backup /var/foo to /var/bar. If /var is lost,
> your backup is gone, too.

I took the backup location from one of the other periodic scripts.
Where should it be backed up to then?

Lars Engels

unread,
Apr 22, 2010, 8:54:02 AM4/22/10
to

Hmm, I guess you shouldn't backup /var/foo to /var/bar. If /var is lost,

Diane Bruce

unread,
Apr 22, 2010, 9:44:25 AM4/22/10
to
On Thu, Apr 22, 2010 at 04:12:08PM +0300, Eitan Adler wrote:
> > Hmm, I guess you shouldn't backup /var/foo to /var/bar. If /var is lost,
> > your backup is gone, too.

In your crontab

MAILTO=...
@weekly /usr/sbin/pkg_info -I -a

Once a week is reasonable.

- Diane
--
- d...@FreeBSD.org d...@db.net http://www.db.net/~db

Trond Endrestøl

unread,
Apr 22, 2010, 10:19:25 AM4/22/10
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, 22 Apr 2010 15:21+0300, Eitan Adler wrote:

> > Just asking opinions, if people want this, I'll make a patch and
> > file a PR.
>
> Is this script correct?
>
> #!/bin/sh
> #
> # $FreeBSD: src/etc/periodic/daily/210.backup-aliases,v 1.6.36.1.2.1 2009/10/25 01:10:29 kensmith Exp $
> #
>
> # 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
>
> bak=/var/backups
> db_loc="/var/db/pkg";

> bk_loc="/$bak/pkgdb.bak.tar"

It's really no big deal, but from a pragmatic view I'd write:

bk_loc="$bak/pkgdb.bak.tar"

Otherwise $bk_loc will contain:

//var/backups/pkgdb.bak.tar

>
> case "$daily_backup_pkgdb_enable" in
> [Yy][Ee][Ss])
> if [ ! -d $db_loc ]
> then
> echo '$daily_backup_pkgdb_enable is enabled but' \
> "$db_loc doesn't exist"
> rc=2
> else
> rc=0
>
> echo ""

> echo "Backing up mail aliases:"

It's really the package directory, no?

> if [ ! -f $bk_loc ]
> then
> echo "no $bk_loc"
> tar -cjf $bk_loc $db_loc || rc=3

How do you plan to capture changes made to /var/db/pkg? If we're
supposed to manually delete /var/backups/pkgdb.bak.tar from time to
time, then the presented code is probably ok.

> fi
> fi;;
>
> *) rc=0;;
> esac
>
> exit $rc


Just my $0.02,
Trond.

- --
- ----------------------------------------------------------------------
Trond Endrestøl | Trond.E...@fagskolen.gjovik.no
ACM, NAS, NUUG, SAGE, USENIX | FreeBSD 8.0-STABLE & Alpine 2.00

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAkvQWvIACgkQbYWZalUoEluyegCfYq/FMpdT9/wRGQyGF8+2WgKQ
aGIAn2S2br054BRHc38IpB4uWYVYH94I
=GA9V
-----END PGP SIGNATURE-----

Dan Rue

unread,
Apr 22, 2010, 9:56:39 AM4/22/10
to
On Thu, Apr 22, 2010 at 03:21:16PM +0300, Eitan Adler wrote:
> >
> > Just asking opinions, if people want this, I'll make a patch and
> > file a PR.
> >
>
> Is this script correct?

We're starting to use SSDs for boot drives in our freebsd boxes. We'd
like to have /var on a memory backed FS, but losing the package database
on every reboot is troublesome.

This script would be a decent solution to my problem as well,

Dan

Joerg Sonnenberger

unread,
Apr 22, 2010, 10:28:53 AM4/22/10
to
On Thu, Apr 22, 2010 at 08:56:39AM -0500, Dan Rue wrote:
> We're starting to use SSDs for boot drives in our freebsd boxes. We'd
> like to have /var on a memory backed FS, but losing the package database
> on every reboot is troublesome.

Tried using a symlink from /var/db/pkg to /usr/local/.pkgdb or so?

Joerg

Eitan Adler

unread,
Apr 22, 2010, 12:08:51 PM4/22/10
to
taking into account your feedback here is the new version
If all is good I'll submit a PR....

#!/bin/sh
#
# $FreeBSD: src/etc/periodic/daily/210.backup-aliases,v 1.6.36.1.2.1
2009/10/25 01:10:29 kensmith Exp $
#

# 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

bak=/var/backups
db_loc="/var/db/pkg";
bk_loc="$bak/pkgdb.bak.tar"

case "$daily_backup_pkgdb_enable" in
[Yy][Ee][Ss])
if [ ! -d $db_loc ]
then
echo '$daily_backup_pkgdb_enable is enabled but' \
"$db_loc doesn't exist"
rc=2
else
rc=0

echo ""
echo "Backing up package db directory:"

rm -f $bk_loc


tar -cjf $bk_loc $db_loc || rc=3

fi;;

*) rc=0;;
esac

exit $rc

Doug Barton

unread,
Apr 22, 2010, 12:48:37 PM4/22/10
to
On 4/22/2010 6:44 AM, Diane Bruce wrote:
> On Thu, Apr 22, 2010 at 04:12:08PM +0300, Eitan Adler wrote:
>>> Hmm, I guess you shouldn't backup /var/foo to /var/bar. If /var is lost,
>>> your backup is gone, too.
>
> In your crontab
>
> MAILTO=...
> @weekly /usr/sbin/pkg_info -I -a

pkg_info -o -a would probably be more useful from the standpoint of
rebuilding ports after a lost /var/db/pkg. For portmaster users
'portmaster --list-origins' would give you a list that you could then do
'portmaster `cat list`' to rebuild everything for you.


hth,

Doug

--

... and that's just a little bit of history repeating.
-- Propellerheads

Improve the effectiveness of your Internet presence with
a domain name makeover! http://SupersetSolutions.com/

_______________________________________________

Doug Barton

unread,
Apr 22, 2010, 12:54:05 PM4/22/10
to
On 4/22/2010 9:08 AM, Eitan Adler wrote:
> taking into account your feedback here is the new version
> If all is good I'll submit a PR....
>
> #!/bin/sh
> #
> # $FreeBSD: src/etc/periodic/daily/210.backup-aliases,v 1.6.36.1.2.1
> 2009/10/25 01:10:29 kensmith Exp $
> #
>
> # 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
>
> bak=/var/backups
> db_loc="/var/db/pkg";

The trailing ; here is superfluous. Also, a better invocation might be:
db_loc=`pm_make -f/usr/share/mk/bsd.port.mk -V PKG_DBDIR 2>/dev/null`
to support people who redefine it.

> bk_loc="$bak/pkgdb.bak.tar"

Since you (properly) compress the archive on the tar command line, that
should be: bk_loc="$bak/pkgdb.bak.tar.bz2"

> case "$daily_backup_pkgdb_enable" in
> [Yy][Ee][Ss])
> if [ ! -d $db_loc ]
> then
> echo '$daily_backup_pkgdb_enable is enabled but' \
> "$db_loc doesn't exist"
> rc=2
> else
> rc=0
>
> echo ""
> echo "Backing up package db directory:"
>
> rm -f $bk_loc

[ -e "$bk_loc" ] && unlink $bk_loc

> tar -cjf $bk_loc $db_loc || rc=3
> fi;;
>
> *) rc=0;;
> esac
>
> exit $rc

Doug Barton

unread,
Apr 22, 2010, 12:56:43 PM4/22/10
to
On 4/22/2010 9:54 AM, Doug Barton wrote:
> Also, a better invocation might be:
> db_loc=`pm_make -f/usr/share/mk/bsd.port.mk -V PKG_DBDIR 2>/dev/null`

Make that just "/usr/bin/make" instead of pm_make, I should have looked
more carefully at what I pasted. :)

Eitan Adler

unread,
Apr 22, 2010, 1:05:48 PM4/22/10
to
Same as before - if all is good I'll send a PR

#!/bin/sh
#
# $FreeBSD: src/etc/periodic/daily/210.backup-aliases,v 1.6.36.1.2.1
2009/10/25 01:10:29 kensmith Exp $
#

# 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

bak=/var/backups
db_loc=$(/usr/bin/make -f/usr/share/mk/bsd.port.mk -V PKG_DBDIR 2>/dev/null)
bk_loc="$bak/pkgdb.bak.tar.bz2"

case "$daily_backup_pkgdb_enable" in
[Yy][Ee][Ss])
if [ ! -d $db_loc ]
then
echo '$daily_backup_pkgdb_enable is enabled but' \
"$db_loc doesn't exist"
rc=2
else
rc=0

echo ""
echo "Backing up package db directory:"

[ -e $bk_loc ] && unlink $bk_loc


tar -cjf $bk_loc $db_loc || rc=3
fi;;

*) rc=0;;
esac

exit $rc

Diane Bruce

unread,
Apr 22, 2010, 1:18:55 PM4/22/10
to
On Thu, Apr 22, 2010 at 09:48:37AM -0700, Doug Barton wrote:
> On 4/22/2010 6:44 AM, Diane Bruce wrote:
> > On Thu, Apr 22, 2010 at 04:12:08PM +0300, Eitan Adler wrote:
...

> > MAILTO=...
> > @weekly /usr/sbin/pkg_info -I -a
>
> pkg_info -o -a would probably be more useful from the standpoint of

The sensible thing to do is to be putting a thumb drive on your machine
and backing up the /var/db/pkg after updating.

An e-mailed list of any sort would be a last resort and having it
fairly compact is a compromise, since you do have the thumb drive to fall
back on right?

> rebuilding ports after a lost /var/db/pkg. For portmaster users
> 'portmaster --list-origins' would give you a list that you could then do
> 'portmaster `cat list`' to rebuild everything for you.

YMMV ;-)

- Diane
--
- d...@FreeBSD.org d...@db.net http://www.db.net/~db

Matthias Andree

unread,
Apr 22, 2010, 1:39:58 PM4/22/10
to
Am 22.04.2010 14:49, schrieb Diane Bruce:
> On Tue, Apr 20, 2010 at 10:11:24PM -0400, Aryeh M. Friedman wrote:
>> I acciddentally rm'ed my /var/db/pkg and want to know is it possible to
>> rgenerate it (I have portmaster and portupgrade installed)
>
>
> You would have to write a script which went through each file in
> /usr/local/bin and /usr/local/lib (mostly sufficient) and examined
> every single pkg-plist looking for the corresponding file. Then you
> know what port the file was generated by. Needless to say, this would
> be somewhat horrible.

Diane,

it's not *that* bad. Consider this algorithm:

1. scan for files under /usr/local/{bin,include,lib,libexec,sbin} and sort or
hash the list - perhaps guess just a port name from an executable in /usr/local/bin

2. Repeat:

2.1 use the next file from the list and search for it
2.2 once you have a port name for this file, obtain the packing list and
remove it from the file list in 1. This cuts down the list from 1 quite a bit.

3. Now print the list of ports found,
and print the list of files not found in ports


Surely and index of plist files in port default configurations could help big
time, but even a blunt ( cd /usr/ports && find . -mindepth 3 -maxdepth 3 -name
pkg-plist -exec egrep FILENAME '{}' + ) might be reasonable given sufficient RAM
so that it runs from cache for the 2nd file you inquire.

If that is too slow, a step between 1 and 2 could procure all pkg-plists as some
sort of FILEINDEX file to accelerate searches.

HTH
Matthias

ไพรัช ศรีโยธา

unread,
Apr 22, 2010, 8:15:53 AM4/22/10
to
hi,

have you tried pkgdb -u ?

--

psr

มะฃาม ฅินเดินดน
มะไฟ ฅนเหลิงฟ้า

http://makham.blogspot.com


Quoting Diane Bruce <d...@db.net>:

> On Tue, Apr 20, 2010 at 10:11:24PM -0400, Aryeh M. Friedman wrote:
>> I acciddentally rm'ed my /var/db/pkg and want to know is it possible to
>> rgenerate it (I have portmaster and portupgrade installed)
>
>
> You would have to write a script which went through each file in
> /usr/local/bin and /usr/local/lib (mostly sufficient) and examined
> every single pkg-plist looking for the corresponding file. Then you
> know what port the file was generated by. Needless to say, this would
> be somewhat horrible.
>

> - Diane
> --
> - d...@FreeBSD.org d...@db.net http://www.db.net/~db

> _______________________________________________
> freebsd...@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hacke...@freebsd.org"
>

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

b. f.

unread,
Apr 22, 2010, 2:00:26 PM4/22/10
to
>Am 22.04.2010 14:49, schrieb Diane Bruce:
>> On Tue, Apr 20, 2010 at 10:11:24PM -0400, Aryeh M. Friedman wrote:
>>> I acciddentally rm'ed my /var/db/pkg and want to know is it possible to
>>> rgenerate it (I have portmaster and portupgrade installed)
>>
>>
>> You would have to write a script which went through each file in
>> /usr/local/bin and /usr/local/lib (mostly sufficient) and examined
>> every single pkg-plist looking for the corresponding file. Then you
>> know what port the file was generated by. Needless to say, this would
>> be somewhat horrible.
>
>Diane,
>
>it's not *that* bad. Consider this algorithm:
>
>1. scan for files under /usr/local/{bin,include,lib,libexec,sbin} and sort or
>hash the list - perhaps guess just a port name from an executable in /usr/local/bin
>
>2. Repeat:
>
> 2.1 use the next file from the list and search for it
> 2.2 once you have a port name for this file, obtain the packing list and
>remove it from the file list in 1. This cuts down the list from 1 quite a bit.
>
>3. Now print the list of ports found,
> and print the list of files not found in ports
>
>
>Surely and index of plist files in port default configurations could help big
>time, but even a blunt ( cd /usr/ports && find . -mindepth 3 -maxdepth 3 -name
>pkg-plist -exec egrep FILENAME '{}' + ) might be reasonable given sufficient RAM
>so that it runs from cache for the 2nd file you inquire.
>
>If that is too slow, a step between 1 and 2 could procure all pkg-plists as some
>sort of FILEINDEX file to accelerate searches.
>
>HTH
>Matthias

By the time you account for CONFLICTS, dynamic plists, substitutions
in plists, etc., I'd have to agree with Diane that this is a pain. It
could be done, and would help to reconstruct most if not all of an
average user's /var/db/pkg, but it's laborious.

b.

b. f.

unread,
Apr 22, 2010, 2:48:43 PM4/22/10
to
Doug Barton wrote:

>On 4/20/2010 7:11 PM, Aryeh M. Friedman wrote:
>> I acciddentally rm'ed my /var/db/pkg and want to know is it possible to
>> rgenerate it (I have portmaster and portupgrade installed)
>
>Portmaster certainly can't do this, it uses the information from
>/var/db/pkg. I'm not sure if portupgrade can do it or not.
>
>Your most likely course of success is to generate a list of ports that
>you know you're using ("root" and "leaf" ports in portmaster
>terminology), back up any config or other key files from /usr/local,
>then delete everything and reinstall.

With regard to portupgrade, if your pkgdb file is intact, you should
be able to reconstruct /var/db/pkg, although it may not be very
convenient to do so. Unfortunately, by default the pkgdb file is
/var/db/pkg/pkgdb.db, so it is often wiped out along with the rest of
/var/db/pkg. However, if it is intact, make sure you first back it up
before attempting to use it's contents, because most of the pkgtools
attempt to edit it to correspond with the current state of /var/db/pkg
(performing the equivalent of pkgdb -u/-aF) when invoked. You may be
able to disable this editing via the "-O" flag, but I haven't checked
this lately.

If you have a list of installed packages, and a corresponding ports
tree, you could reconstruct most but probably not all of /var/db/pkg
by running "make generate-plist fake-pkg" in the ports tree origin of
each package (if you built the packages with non-default options, you
should have an intact /var/db/ports for this to fully work). The
directories for packages with dynamic plists might not be fully
restored without rebuilding the ports, but this may be enough for a
first pass. You could then prune or account for files in
PREFIX/LOCALBASE that aren't listed as belonging to a registered
package, via something like:

find /usr/local -type f -print0 | xargs -0 pkg_which -v | fgrep '?'

or with something similar using "pkg_info -W..." instead of "pkg_which -v".

Alternatively, if you have backups of all the installed packages, or
can obtain them from a server, you could use their packing lists to
restore /var/db/pkg.

But as Doug suggests, a full cleanup of PREFIX/LOCALBASE and
reinstallation of all leaf packages may be easier than a
reconstruction of /var/db/pkg.

Diane Bruce

unread,
Apr 22, 2010, 3:24:55 PM4/22/10
to
On Thu, Apr 22, 2010 at 06:48:43PM +0000, b. f. wrote:
> Doug Barton wrote:
> >On 4/20/2010 7:11 PM, Aryeh M. Friedman wrote:
...

> find /usr/local -type f -print0 | xargs -0 pkg_which -v | fgrep '?'

libchk would also be useful.

...


>
> But as Doug suggests, a full cleanup of PREFIX/LOCALBASE and
> reinstallation of all leaf packages may be easier than a
> reconstruction of /var/db/pkg.

...

I also agree with Doug here. The key thing is to have a record or a good idea
of what you had installed in the first place.
I reiterate, having a thumb drive with copies of your /etc,/var/db/pkg
/usr/local/etc, you get the idea, is very useful to have around.

- Diane
__

Robert Huff

unread,
Apr 23, 2010, 10:35:36 AM4/23/10
to

Aryeh M. Friedman writes:

> I acciddentally rm'ed my /var/db/pkg and want to know is it
> possible to rgenerate it (I have portmaster and portupgrade
> installed)

(I'm assuming you have _completely_ deleted the contents of
/var/db/pkg.)
If you have not deleted /usr/ports/distfiles, this will give
you a starting place. Mind you, some of the distfile names bear
scant relation to the port names ... but they're usually not that
hard to track down.
The advice to "start with a big one" - OpenOffice, KDE, etc. -
is also sound.


Robert Huff
(who used this method
successfully a couple of years ago)

Wesley Shields

unread,
Apr 23, 2010, 10:55:43 PM4/23/10
to
On Thu, Apr 22, 2010 at 08:56:39AM -0500, Dan Rue wrote:
> On Thu, Apr 22, 2010 at 03:21:16PM +0300, Eitan Adler wrote:
> > >
> > > Just asking opinions, if people want this, I'll make a patch and
> > > file a PR.
> > >
> >
> > Is this script correct?
>
> We're starting to use SSDs for boot drives in our freebsd boxes. We'd
> like to have /var on a memory backed FS, but losing the package database
> on every reboot is troublesome.
>
> This script would be a decent solution to my problem as well,

You can look into how NanoBSD does things if you want to go this route.

-- WXS

Doug Barton

unread,
Apr 25, 2010, 10:33:48 PM4/25/10
to
FWIW, this looks fine to me. Have you submitted a PR?


Doug

--

... and that's just a little bit of history repeating.
-- Propellerheads

Improve the effectiveness of your Internet presence with
a domain name makeover! http://SupersetSolutions.com/

_______________________________________________

Garrett Cooper

unread,
Apr 25, 2010, 10:44:34 PM4/25/10
to
On Thu, Apr 22, 2010 at 10:05 AM, Eitan Adler <eitanad...@gmail.com> wrote:
> Same as before - if all is good I'll send a PR
>
> #!/bin/sh
> #
> # $FreeBSD: src/etc/periodic/daily/210.backup-aliases,v 1.6.36.1.2.1
> 2009/10/25 01:10:29 kensmith Exp $
> #
>
> # 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
>
> bak=/var/backups
> db_loc=$(/usr/bin/make -f/usr/share/mk/bsd.port.mk -V PKG_DBDIR 2>/dev/null)
> bk_loc="$bak/pkgdb.bak.tar.bz2"
>
> case "$daily_backup_pkgdb_enable" in
>    [Yy][Ee][Ss])

This could be done via rc.subr's checkyesno function.

>        if [ ! -d $db_loc ]

Please quote the string.

>        then
>            echo '$daily_backup_pkgdb_enable is enabled but' \
>                "$db_loc doesn't exist"
>            rc=2
>        else
>            rc=0
>
>            echo ""
>            echo "Backing up package db directory:"
>
>            [ -e $bk_loc ] && unlink $bk_loc

Please quote.

>            tar -cjf $bk_loc $db_loc || rc=3

Same here.

>        fi;;
>
>    *)  rc=0;;
> esac
>
> exit $rc

Thanks,
-Garrett

Doug Barton

unread,
Apr 25, 2010, 10:55:24 PM4/25/10
to
On 04/25/10 19:44, Garrett Cooper wrote:
> On Thu, Apr 22, 2010 at 10:05 AM, Eitan Adler <eitanad...@gmail.com> wrote:
>> Same as before - if all is good I'll send a PR
>>
>> #!/bin/sh
>> #
>> # $FreeBSD: src/etc/periodic/daily/210.backup-aliases,v 1.6.36.1.2.1
>> 2009/10/25 01:10:29 kensmith Exp $
>> #
>>
>> # 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
>>
>> bak=/var/backups
>> db_loc=$(/usr/bin/make -f/usr/share/mk/bsd.port.mk -V PKG_DBDIR 2>/dev/null)
>> bk_loc="$bak/pkgdb.bak.tar.bz2"
>>
>> case "$daily_backup_pkgdb_enable" in
>> [Yy][Ee][Ss])
>
> This could be done via rc.subr's checkyesno function.

It's periodic, not rc.d. :)

>> if [ ! -d $db_loc ]
>
> Please quote the string.

I generally do quote the string as a matter of paranoia, however the
practical result is likely to be the same.


Doug

--

... and that's just a little bit of history repeating.
-- Propellerheads

Improve the effectiveness of your Internet presence with
a domain name makeover! http://SupersetSolutions.com/

_______________________________________________

Doug Barton

unread,
Apr 26, 2010, 12:43:47 AM4/26/10
to
On 04/25/10 19:55, Doug Barton wrote:
>>> if [ ! -d $db_loc ]

>
> I generally do quote the string as a matter of paranoia, however the
> practical result is likely to be the same.

... unless it's possible that the path name will have spaces in it,
which is the main reason for my paranoia.

Eitan Adler

unread,
Apr 26, 2010, 3:53:56 AM4/26/10
to
On Mon, Apr 26, 2010 at 5:33 AM, Doug Barton <do...@freebsd.org> wrote:
> FWIW, this looks fine to me. Have you submitted a PR?
>
Yes, http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/145957

Garrett Cooper

unread,
Apr 26, 2010, 3:59:02 AM4/26/10
to
2010/4/25 Doug Barton <do...@freebsd.org>:

> On 04/25/10 19:44, Garrett Cooper wrote:
>> On Thu, Apr 22, 2010 at 10:05 AM, Eitan Adler <eitanad...@gmail.com> wrote:
>>> Same as before - if all is good I'll send a PR
>>>
>>> #!/bin/sh
>>> #
>>> # $FreeBSD: src/etc/periodic/daily/210.backup-aliases,v 1.6.36.1.2.1
>>> 2009/10/25 01:10:29 kensmith Exp $
>>> #
>>>
>>> # 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
>>>
>>> bak=/var/backups
>>> db_loc=$(/usr/bin/make -f/usr/share/mk/bsd.port.mk -V PKG_DBDIR 2>/dev/null)
>>> bk_loc="$bak/pkgdb.bak.tar.bz2"
>>>
>>> case "$daily_backup_pkgdb_enable" in
>>>    [Yy][Ee][Ss])
>>
>> This could be done via rc.subr's checkyesno function.
>
> It's periodic, not rc.d.  :)

It would be nice if some of the more usable functions got moved out of
rc.subr though :(... It would cure 20 lines of duplicate code here and
elsewhere outside of rc land...

>>>        if [ ! -d $db_loc ]
>>
>> Please quote the string.
>

> I generally do quote the string as a matter of paranoia, however the
> practical result is likely to be the same.

Yes, and you're assuming that users won't do:

PKG_DBDIR := /my /super /special/ directory with spaces

Granted, a lot of things probably won't work that way, but just
compounding to the issue of not quoting variables seems like a silly
mistake to make :/.
Thanks,
-Garrett

Eitan Adler

unread,
Apr 26, 2010, 4:10:18 AM4/26/10
to
> It would be nice if some of the more usable functions got moved out of
> rc.subr though :(... It would cure 20 lines of duplicate code here and
> elsewhere outside of rc land...
Where should they go? I'll gladly work on a patch to make them
available to periodic scripts.

>
> Yes, and you're assuming that users won't do:
>
> PKG_DBDIR := /my /super /special/ directory with spaces
>
> Granted, a lot of things probably won't work that way, but just
> compounding to the issue of not quoting variables seems like a silly
> mistake to make :/.

IMHO a user that uses crazy things should know that things will break
Almost no program around correctly handles all filenames:
http://www.dwheeler.com/essays/filenames-in-shell.html

RW

unread,
Apr 26, 2010, 7:01:55 AM4/26/10
to
On Thu, 22 Apr 2010 20:05:48 +0300
Eitan Adler <eitanad...@gmail.com> wrote:

> bak=/var/backups

This should be configurable IMO.

Eitan Adler

unread,
Apr 26, 2010, 8:32:21 AM4/26/10
to
On Mon, Apr 26, 2010 at 2:01 PM, RW <rwmai...@googlemail.com> wrote:
> On Thu, 22 Apr 2010 20:05:48 +0300
> Eitan Adler <eitanad...@gmail.com> wrote:
>
>> bak=/var/backups
>
> This should be configurable IMO.

This currently isn't configurable in 210.backup-aliases which is where
I copied this from.
I'm going to submit a *separate* PR with an enhancement allowing
configuration of the backup location. If accepted I'll update my
220.backup.pkgdb script.

0 new messages