You are not logged in.

#1 2007-10-14 22:57:16

rdt
Member
Registered: 2007-04-26
Posts: 24

Lost Pacman Installed Package Databse

On one of my Arch machines I seemed to have lost something for Pacman as 'Pacman -Q' gives absolutely no results.  smile
I've searched on both the forum & the wiki but I guess I'm too stupid to get the right search term to come up with anything.  I still have the packages in /var/cache/pacman/pkg and a lot in /var/lib/pacman, so I don't know what it is I lost.

Any ideas guys?

Offline

#2 2007-10-14 23:29:18

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Lost Pacman Installed Package Databse

Your local database of installed packages is in /var/lib/pacman/local - if you've lost that, you have a bit of a headache to sort out.

Because you're not the first person to do this(!), there have been various threads on the subject over the years - have a browse/search around here for various possible solutions. Essentially, you need to determine the names of your installed packages from the files currently installed, and then reinstall them.

Offline

#3 2007-10-14 23:54:54

rdt
Member
Registered: 2007-04-26
Posts: 24

Re: Lost Pacman Installed Package Databse

I wonder if I can just take the packagename from the files in /var/cache/pacman/pkg and just reinstall all of them?

Offline

#4 2007-10-15 00:06:54

byte
Member
From: Düsseldorf (DE)
Registered: 2006-05-01
Posts: 2,046

Re: Lost Pacman Installed Package Databse

Even if you have never cleared your cache (pacman -Sc/Scc), you'd still be missing the packages from the installation. /var/log/pacman.log is your best bet.


1000

Offline

#5 2007-10-15 00:53:15

rdt
Member
Registered: 2007-04-26
Posts: 24

Re: Lost Pacman Installed Package Databse

Thanks, byte for that info.  What I did was create:

#!/bin/bash
#
SEDEXP='s/^\[[^ ]* *[0-9][0-9]:[0-9][0-9]\] \([^ ]*\) *\([^ ]*\) .*/\1 \2/'
GRPEXP='(upgraded)|(installed)'
AWKEXP='{print $2}'
#
sed -e "$SEDEXP" /var/log/pacman.log | grep -E "$GRPEXP" | awk "$AWKEXP" | sort -u
# End

This gave me a list of some 272 packages, which (except for half a dozen errors) was the same list that I came up with from the /var/cache/pacman/pkg files list.  However, the script above when used on /var/log/pacman.log made fewer mistakes than when I tried it by hand.

Thanks again.

Offline

#6 2009-06-22 14:24:01

yitzle
Member
Registered: 2008-10-19
Posts: 18

Re: Lost Pacman Installed Package Databse

An improvement on rdt's script. This assumes (as did his) that package names do not have spaces in them.
It has the advantages of:
- replace 4 calls in a pipe with 1 call
- does not report packages that were removed since being installed
- is hopefully easier to read
- checks the correct column for 'upgraded' or 'installed' and not the entire line, ie will not report a line that says something along the lines of "warning: we upgraded your rc file"

awk '
  $3 == "installed" || $3 == "upgraded" { pkg[$4] = 1 }
  $3 == "removed" { pkg[$4] = 0 }
  END { for (i in pkg) if ( pkg[i] == 1 ) print i; }
' /var/log/pacman.log

Offline

#7 2009-09-09 07:14:29

OMGitsUGOD
Member
Registered: 2009-08-27
Posts: 21

Re: Lost Pacman Installed Package Databse

I did a minor change to the above scripts, because I only want to reinstall the packages that was lost from the database. Might be interestng if you have lots of packages and only a few of them are broken, take a look at
http://bbs.archlinux.org/viewtopic.php? … 34#p616234.

Offline

Board footer

Powered by FluxBB