# /var/db/pkg deleted



## sk8harddiefast (Mar 19, 2011)

How to recreate the db? My packages exist on my system but db have none record of them. Also can not rebuilt my packages (logical because db find 0 packages). Any idea?


----------



## SirDice (Mar 19, 2011)

Tricky, did that once too when I first started with FreeBSD. As far as I know there's no way to recreate the database except to install everything again from the start.


----------



## sk8harddiefast (Mar 19, 2011)

Are you joking right? Ok. I think I have veeery hard work to do!!!!! And how I know all my system packages? 
	
	



```
pkg_info | grep *
```
 return 0 results. And installing a package is not installing all his dependencies too because already they exist on system. Now I am really stack! Well. That is something that is missing from FreeBSD. A tool to recreate the db!


----------



## SirDice (Mar 19, 2011)

sk8harddiefast said:
			
		

> Are you joking right? Ok.


Nope, you are basically SOL x(



> And how I know all my system packages?
> 
> 
> 
> ...


Memory?



> And installing a package is not installing all his dependencies too because already they exist on system. Now I am really stuck! Well. That is something that is missing from FreeBSD. A tool to recreate the db!


I ended up reinstalling the box from scratch. For the umpteenth time, I remember doing that a lot when I started out with FreeBSD :e


----------



## vermaden (Mar 19, 2011)

sk8harddiefast said:
			
		

> How to recreate the db? My packages exist on my system but db have none record of them. Also can not rebuilt my packages (logical because db find 0 packages). Any idea?



You cant ... write all app names that You use/need in some file, then remove all installed stuff and add them again:

```
# vi apps
# rm -rf /usr/local /var/db/pkg
# while read I
> do
>   pkg_add -r ${I}
> done < apps
#
```


----------



## wblock@ (Mar 19, 2011)

sk8harddiefast said:
			
		

> Are you joking right? Ok. I think I have veeery hard work to do!!!!! And how I know all my system packages?
> 
> 
> 
> ...



In theory, you could write a program that would go through $PREFIX and look up files in the pkg-plist files in ports.

In practice, many ports generate dynamic plists, and it would still require looping through every single port in /usr/ports.  Maybe there's a better way, like a master plist that shows the origin of every file.  The port-building clusters might have that, at least in their /var/db/pkg, but it's probably not available for download.  (If you use ports-mgmt/portupgrade, you might be able to get the installed-ports list from its separate /var/db/pkg/pkgdb.db.  No real idea how.)

Practical options are:

1.  Back up /usr/local/etc, delete /usr/local, and start reinstalling.

2.  Keep using the system, installing a port when you find it isn't listed in pkg_info output but you know the files are present.  Eventually/hopefully/maybe you'll get everything replaced.

3.  Post the question on the -ports mailing list, because more than a few people have experienced it, and maybe there is a way.


----------



## sk8harddiefast (Mar 20, 2011)

> Nope, you are basically SOL


I am just kidding. What means SOL?
Format solved my problem. Now I am trying OpenCDE


----------



## mk (Mar 20, 2011)

sh`t out of luck->sol


----------



## _martin (Mar 20, 2011)

Well, same old story - you should keep a backup. 

But to say something useful too: I did put a cron script on my systems which does a daily system check. Nothing special - it prints kernel version, installed packages, fstab contents, network info, etc. 

I do keep them stored in /var/log/bsd/checkconfig/ directory so I can check the system status from days before.  
I must say this information came in handy many times.


----------



## DutchDaemon (Mar 20, 2011)

At the very least (if you don't have backups, that is) you should run a command like [cmd=]portmaster --list-origins > ~root/ports.today[/cmd] or [cmd=]pkg_info -aoq > ~root/ports.today[/cmd] once a day from root's crontab.


----------

