# Installed ports database issue



## carltonfsck (Nov 30, 2010)

Greetings,

I'm having a dilemma with my installed ports.  I have a server that I use only for HTTP and Email.  I have NO Xorg GUI desktop installed at all.  It's just straight command line.  I have about 10-12 ports installed on it.  

Unfortunately, I recently had the hard drive that houses the /VAR partition crap out on me.  I was able to get another HD, and I thought I had a recent backup of the /VAR partition that I copied over to it.  Upon mounting it, I did some checks to make sure everything was ok.  Upon doing a CVSUP (pkg_version -v) to update my ports, it said I had over 100 ports installed.  A lot of them pertaining to X11 ports (apparently, when I did have a desktop a while back).  Looks like the old ports/package database was copied to my current system. 

My question to you all is, how can I delete the ports/database info that I know don't exist or aren't installed, even though the "pkg_version -v" shows otherwise?  Or do I have to systematically go through and delete each ports that I don't need?

Thank You in advance everyone!


--Cf


----------



## wblock@ (Nov 30, 2010)

That's kind of ugly.  The package database from another system has zero relation to what is actually installed on the current system.

With only a few ports installed, I'd suggest just pkg_delete -a and nstall them all again.  That will wipe out the package database, which is completely wrong anyway.


----------



## DutchDaemon (Nov 30, 2010)

If you don't know which ports you had installed originally, you could run (a scripted run of) *pkg_info -W* against all binaries in /usr/local/bin/ and /usr/local/sbin/ and do some grep/awk/sort/uniq on the output. That should give you what you need to reinstall.

Something like this should do. it's a bit crude && bruteforce, but it should work 


```
cd /usr/local/bin
ls | while read file
do
pkg_info -W $file 2>/dev/null | awk '{print $6}' | xargs pkg_info -o | grep "/" >> /tmp/ports
done
cd /usr/local/sbin/
ls | while read file
do
pkg_info -W $file 2>/dev/null | awk '{print $6}' | xargs pkg_info -o | grep "/" >> /tmp/ports
done
sort -u /tmp/ports > /tmp/ports.installed
```

You should be able to feed that straight to e.g. portmaster.


----------



## carltonfsck (Nov 30, 2010)

Thank You both for your replies.  What I actually did was attempt to run 'portupgrade' to see what would happen.  I then got a message about several inconsistencies, and was advised to run, "pkgdb -F", in which I did.  I(t) deleted all irrelevant ports/packages and then allowed ports that I knew needed to be installed.  I finally ended up manually deleting some other ports, and reinstalling others.  I than ran cvsup/portupgrade and all seems to be back to normal.  I actually had more ports originally installed than I first thought.  

Kind Regards,

--Cf


----------

