How to Dump and Load a Berkeley Database File

You may see errors like this in the output from "spamassassin -D -t < msg":

debug: bayes: 29843 tie-ing to DB file R/O /home/jm/.spamassassin/bayes_toks
Cannot open bayes databases /home/jm/.spamassassin/bayes_* R/O: tie failed: 

This means that the DB_File module could not attach to a database file, which often means an incompatible version between the file and the libraries installed.

To fix, use the db_dump and db_load tools. Here's an example of how to upgrade your bayes_toks file with Berkeley db 4.1 installed:

cd ~
db4.1_dump .spamassassin/bayes_toks > dmp
db4.1_load bayes_toks < dmp
mv bayes_toks .spamassassin/bayes_toks

You may need to perform the "dump" step on the original machine, and the db_dump and db_load tools may have different names on your platform.

Note that some OS'es (like Debian!) install DB version 4.1, but using DB version 3.x for it's DB_File support! Use the "file" tool to find out what version is what:

file /home/jm/.spamassassin/bayes_*
/home/jm/.spamassassin/bayes_seen:  Berkeley DB (Hash, version 5, native byte-order)
/home/jm/.spamassassin/bayes_toks:  Berkeley DB (Hash, version 5, native byte-order)
/home/jm/.spamassassin/bayes_toks.copied: Berkeley DB (Hash, version 8, native byte-order)

"Version 5" is db3.x, "Version 8" is db4.x. Confused yet? Don't blame us, we only work here. You need to install db3-utils to get the "db3_load" command to save in a format that the DB_File module (and therefore SpamAssassin) can use.

(On Debian, don't install an older "-dev" package, like "libdb2-dev", as it'll override the newer stuff. You just need "libdb2" and "libdb2-utils", or "libdb4.3" and "db4.3-util", or similar.)

If all else fails, just convert the entire DB to text using this tool: http://spamassassin.taint.org/devel/db-to-text.pl.txt , and it's "-o" switch, and convert from text into the DB_File DB format on the other side using the same tool and the "-i" switch.

DB 1.8.5 to DB 4.2.x

db_load and db_dump as documented above are mostly useful for close versions. Converting between more dissimilar versions requires a little more work. To go from 1.8.5 to 4.2.x, you need to dump using the db_dump185 tool which is included in the tarball for 4.2.x but isn't always built. To build it, download and extract the tarball and then do this:

cd build_unix/
../dist/configure --enable-dump185
make

Of course, this will fail if you don't have the libs for 1.8.5 around - so build this on the old system, then dump the files, then move the dumps to the new system, and then finally, use db_load as described above to import them.

Other Dbs

You can do the same with the bayes_seen and auto-whitelist files, but they're not as important; I generally just blow them away:

cd ~
rm .spamassassin/bayes_seen
rm .spamassassin/auto-whitelist*

JustinMason