Oct 17

OK, so you broke your freebsd /var/db/pkg directory and want to recover it from a backup.

backups look like this:
root@websrv:/var/db/pkg # ls -l /var/backups/
total 19190
-rw-r–r– 1 root wheel 1690 Jul 10 2014 aliases.bak
-rw-r–r– 1 root wheel 475 Jul 1 19:30 group.bak
-rw——- 1 root wheel 1937 Sep 7 10:25 master.passwd.bak
-rw——- 1 root wheel 1954 Aug 23 18:34 master.passwd.bak2
-rw-r–r– 1 root wheel 2429640 Oct 16 03:20 pkg.sql.xz
-rw-r–r– 1 root wheel 2429640 Oct 15 03:01 pkg.sql.xz.1
-rw-r–r– 1 root wheel 2429640 Oct 14 03:09 pkg.sql.xz.2
-rw-r–r– 1 root wheel 2429640 Oct 13 03:01 pkg.sql.xz.3
-rw-r–r– 1 root wheel 2429640 Oct 12 03:01 pkg.sql.xz.4
-rw-r–r– 1 root wheel 2429640 Oct 11 04:00 pkg.sql.xz.5
-rw-r–r– 1 root wheel 2429640 Oct 10 03:01 pkg.sql.xz.6
-rw-r–r– 1 root wheel 2429640 Oct 9 03:01 pkg.sql.xz.7

but it’s not working as advertised…

root@websrv:/var/db/pkg # pkg backup -r /var/backups/pkg.sql.xz
Restoring database:
Restoring: 100%
pkg: sqlite error while executing backup step in file backup.c:99: not an error
pkg: sqlite error — (null)

root@websrv:/tmp # pkg backup -r pkg.sql
Restoring database:
Restoring: 100%
pkg: sqlite error while executing backup step in file backup.c:99: not an error
pkg: sqlite error — (null)

always results in an fresh but empty /var/db/local.sqlite..

root@websrv:/var/backups # pkg info

manual fix

root@websrv:/var/db/pkg # pkg install sqlite3
Updating FreeBSD repository catalogue…
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
sqlite3: 3.8.11.1_1

root@websrv:/var/backups # cp pkg.sql.xz /tmp
root@websrv:/var/backups # xz -d /tmp/pkg.sql.xz
root@websrv:/var/backups # cd /var/db/pkg
root@websrv:/var/db/pkg # mv local.sqlite local.sqlite.broken
root@websrv:/var/db/pkg # sqlite3 local.sqlite
SQLite version 3.8.11.1 2015-07-29 20:00:57
Enter “.help” for usage hints.
sqlite> .read /tmp/
Display all 1316 possibilities? (y or n)
sqlite> .read /tmp/pkg.sql

tada

root@websrv:/var/backups # pkg info
ap24-mod_mpm_itk-2.4.7_1 This MPM allows you to run each vhost under a separate uid and gid
apache24-2.4.16_1 Version 2.4.x of Apache web server
apr-1.5.2.1.5.4 Apache Portability Library
autoconf-2.69 Automatically configure source code on many Un*x platforms
autoconf-wrapper-20131203 Wrapper script for GNU autoconf
automake-1.15 GNU Standards-compliant Makefile generator
automake-wrapper-20131203 Wrapper script for GNU automake
binutils-2.25.1 GNU binary tools
bison-2.7.1,1 Parser generator from FSF, (mostly) compatible with Yacc
boost-jam-1.55.0 Build tool from the boost.org
boost-libs-1.55.0_9 Free portable C++ libraries (without Boost.Python)
ca_root_nss-3.20 Root certificate bundle from the Mozilla Project
cmake-3.3.1 Cross-platform Makefile generator
cmake-modules-3.3.1 Modules and Templates for CMake
curl-7.44.0 Non-interactive tool to get files from FTP, GOPHER, HTTP(S) servers
db5-5.3.28_2 The Oracle Berkeley DB, revision 5.3
dialog4ports-0.1.5_2 Console Interface to configure ports

Leave a Reply

You must be logged in to post a comment.

preload preload preload