Date: Tue, 12 May 2015 09:52:14 +0100 From: Matthew Seaman <matthew@freebsd.org> To: freebsd-ports@freebsd.org Subject: Re: damage to pkg's sqlite data base Message-ID: <5551BF3E.9060602@freebsd.org> In-Reply-To: <201505120617.t4C6HkA3019096@sdf.org> References: <201505120617.t4C6HkA3019096@sdf.org>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --1oUXi0Bk6uVJETcGWVfVj29UrgWETG5xf Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/12/15 07:17, Scott Bennett wrote: > I'm not familiar with sqlite commands, nor with the structure of t= he > pkg data base, nor any of several other relevant topics. But I do have= > questions: >=20 > 1) how might the damage have happened? Could be any number of things, but in principle the corruption is usually due to some IO request that didn't complete successfully. That can happen if pkg(8) gets killed at exactly the wrong moment, or if your pkg database is on an NFS mount and the locking isn't working properly. > 2) how might such an event be avoided/prevented in the future? It's pretty rare judging by the lack of complaints we've had. So long as your disk hardware is OK, and you're keeping the pkg DB on a local disk it should be reliable enough that you don't need to take any special measures. However the prudent sysadmin will always have backups, and there are a couple of periodic scripts that will backup your package database for you. One, as I recall, just copies the local.sqlite file to /var/backup, while the other uses 'pkg backup' to create a database dump. > 3) most urgently, how can I *fix* it? If your backups don't sort it for you, and you aren't happy to go into sqlite and mend things by using SQL directly, then you can fix it in the true heroic fashion: 1) Make sure that you have packages available for everything installed on your system, either in whatever repo you're using (preferred), or by creating pkg tarballs of all the packages installed on your system: # mkdir /tmp/pkg-backup # pkg create -a -o /tmp/pkg-backup (That might be affected by the corruption you've experienced. Watch out for any error messages.) 2) Generate a list of all the *non-automatic* packages you have installed: # pkg query -e "%a =3D=3D 0" "%n-%v" > /tmp/pkg-list 3) Move aside your corrupted pkg database: # mv /var/db/pkg/local.sqlite{,.save} 4) Reinstall pkg(8) -- this will reinitialise your database: # /usr/sbin/pkg bootstrap -f 5) Reinstall all the packages you had previously installed: # xargs pkg install < /tmp/pkg-backup or -- if and only if you could create tarballs of everything without error -- you can reinstall from those packages: # cd /tmp/pkg-backup # sed -e 's,$,.txz,' < /tmp/pkg-list | xargs pkg add This should restore your system to its previous state preserving the automatic flags on your packages. It should install any dependencies required and mark them as automatic. You will want to list all the packages installed before and after and compare the two as a sanity check. If there are packages that you used to have installed but are no longer listed, then you'll have the old package files left orphaned on your drive, which it would be a good idea to clean up. Doing that I leave as an exercise for the student. > 4) I was unable to find any instructions for recreating a pkg data > base if the data base gets damaged/destroyed. Is there a way to > do that that I missed? It's not something that needs doing that often. The general approach will be -- as shown above -- to create a new package database and reinstall everything. You may or may not want to wipe the contents of /usr/local before you do that (obviously save your config files from /usr/local/etc and any precious web content from /usr/local/www, etc. etc.), depending on how badly the database was damaged, how up-to-date the system was and whether you have a good idea of what packages you had installed previously or not. Cheers, Matthew --1oUXi0Bk6uVJETcGWVfVj29UrgWETG5xf Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQJ8BAEBCgBmBQJVUb9EXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQxOUYxNTRFQ0JGMTEyRTUwNTQ0RTNGMzAw MDUxM0YxMEUwQTlFNEU3AAoJEABRPxDgqeTnklYP+wYMNgMi2ykvMVQRJkwsZBv1 ymoGNg1QuguZAZ8sK2BtiZZi+nH9cvftkjnuV3NKOk52v7N7qWVlOB8IYf6JttQL 9hutpfkPO9OFrmhQtXUB44zEEoZx+FIiRcvJ1tlL4Qzqt+kJu65bCmcGULCNzTV1 7ssbISDf7342n2RJUohjEY9WdWDIV/utR8hm7A5RyiDVQFXEZSjVy0PaTuGnTv67 MwcWXNMnD17x6kBTjIAnMKbcEcbuVI0qT4zhxJj8CtVkhA9FVXi1M1SakfsOcx3U xNlRF71POMsSEY1ZfxNUMiAgm3QYBqxLEzFnWT6yqpg0pirDoTJyLIz0JWD2rKH4 6ffqu5bkh0Dlwu4KcLyq1spnVRznO58pxLrk7Ecij6ZNTRARddVjg2oy/1iiWzat KNYiGZ+4SS+71ahS45+RpESkWL0aGR4kH0Wbi6kbLDmf4H0cONxPFaSqUYK1xWNW NQNcG2vI0S+mNBjKpS26Rz59t2jJFI7PHcI27PqWby0Vnp95xUxZI2c/Yx4EyyIx kBhnGtv9IacTvsGlMU9xCKORsz1In0ksT8ETb88emQSvGgA1SjIzq0R9CdzTCzOY qJPBh7tRhnmevLuY8pUsl5aCwq6u2GPsHmaMXW3CopC08GcPHD3GUxjloxUrwgO2 7U4ROjhKZdm2E1q2393G =A+o/ -----END PGP SIGNATURE----- --1oUXi0Bk6uVJETcGWVfVj29UrgWETG5xf--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5551BF3E.9060602>