# what if /var/db/pkg is deleted?



## fluca1978 (Jun 21, 2012)

This could sound trivial, but as far as I get it the pkg_ tools use the /var/db/pkg directory to see the installed packages information. If this is true, supposing that the above directory is emptied due to an error, is there a way to rebuild it and to delete installed packages?


----------



## jb_fvwm2 (Jun 21, 2012)

If you meant "reinstall" to re-register the packages, some thing like

```
# requires [FILE]/usr/ports/ports-mgmt/pkg[/FILE] pre-installed... on
# the problematic computer or one with the same [ or same AND additional ]
# ports installed, from which to copy the [FILE]local.sqlite[/FILE] file.
# (see additional conditions below...)
cd /usr/local/sbin
find . -type f -exec pkg which {} \; | awk '{print $6}' | uniq | sort | uniq | tee -a /tmp/pkgs_to_reinstall_from_ports_or_portmasterPP.log
# repeat for /usr/local/bin, then check the large (firefox, etc) pkgs reinstalled.
#or, 
make missing
# from the /usr/ports/www/firefox which "exist" (run) but are not registered.
```
or combine both methods.

One could place the pkg database file on the computer from another one if it was built on a machine where the machine to repair has a lesser subset of ports. [No time to check the above for typos'...] BTW that file local.sqlite should be backed up somewhere on every machine if one is wise, /var/db/pkg also contains it. [I had to actually use that method because /var had to be reinstalled due to part[!!] of the hard disk being unusable.]


----------



## gkontos (Jun 21, 2012)

Default periodic scripts also create a backup under /var/backups


----------



## wblock@ (Jun 21, 2012)

jb_fvwm2 said:
			
		

> If you meant "reinstall" to re-register the packages, some thing like
> 
> ```
> cd /usr/local/sbin
> ...



That's pkgng, which is not out for general use yet.


----------

