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
{EPITECH.} tek4
CamTrace S.A.S
On Thu, Apr 22, 2010 at 7:43 AM, Doug Barton <do...@freebsd.org> wrote:
> a
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
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
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
I took the backup location from one of the other periodic scripts.
Where should it be backed up to then?
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
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-----
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
Tried using a symlink from /var/db/pkg to /usr/local/.pkgdb or so?
Joerg
#!/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
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/
_______________________________________________
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
Make that just "/usr/bin/make" instead of pm_make, I should have looked
more carefully at what I pasted. :)
#!/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
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
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
have you tried pkgdb -u ?
--
psr
มะฃาม ฅินเดินดน
มะไฟ ฅนเหลิงฟ้า
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.
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.
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.
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
__
- d...@FreeBSD.org d...@db.net http://www.db.net/~db
> 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)
You can look into how NanoBSD does things if you want to go this route.
-- WXS
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/
_______________________________________________
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
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/
_______________________________________________
... unless it's possible that the path name will have spaces in it,
which is the main reason for my paranoia.
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
>
> 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
> 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.