Exploring Berkeley DB Files from the CLI

I have a set of Berkeley DB files on my Linux file system that I would like to learn.

What useful tools are there to quickly browse content? I can write Perl scripts that use BDB modules to learn them, but I'm looking for some CLI utility to be able to look inside without forcing to write scripts.

+51
linux command-line-interface berkeley-db
Sep 01 '08 at 9:10
source share
8 answers

Check out the db-utils package. If you use apt, you can install it using the following: apt-get install db-util (or apt-get install db4.8-util or any other version you prefer).

Additional links:

+23
Sep 01 '08 at 9:24 AM
source share

Use the db_dump program. It is contained in the package core/db (Arch), db-util (Debian, Ubuntu), sys-libs/db (Gentoo, note that here the binary is called db4.8_dump or any other version that you use).

On some systems, manual pages are not installed, in which case the documentation can be found here . By default, db_dump prints some hexadecimal numbers, which is not very useful if you are trying to parse the contents of a database. Use the -p argument to change this.

Show everything in the database.db file:

 db_dump -p database.db 

List the databases in database.db :

 db_dump -l database.db 

Show only the contents of the mydb database in the database.db file:

 db_dump -p -s mydb database.db 
+30
Dec 20 '15 at 1:47
source share

I found @strickli's answer most useful since I did not want to add any new packages to the machine with the database I was on. However, the db file I was reading was of type btree and not hash, so I had to use bsddb

 # file foo.db foo.db: Berkeley DB (Btree, version 9, native byte-order) # python >>> import bsddb >>> for k, v in bsddb.btopen("*<db filename here...>*").iteritems(): ... print k,v ... 
+14
Apr 11 '14 at 4:48
source share

As mentioned in other answers, the db-utils package (db4-utils under RHEL) has some tools. However, db_dump can be useless, since the output is in the "bytevalue" format.

For quick'n'dirty viewer use python:

 me@machine$ python Python 2.7.3 (default, Sep 26 2013, 20:03:06) >>> import dbhash >>> for k, v in dbhash.open( *<db filename here...>* ).iteritems(): print k, v ... 

Note that dbhash is deprecated after python 2.6.

+9
Nov 05 '13 at 16:07 on
source share

The db_hotbackup utility creates hot backup or hot restore snapshots in a Berkeley DB database environment. Install it with the following

apt-get install db-util

then run the following command to make a hot backup

db_hotbackup [-cDEguVv] [-d data_dir ...] [-h home] [-l log_dir] [-P password] -b backup_dir

+6
Feb 20 2018-12-12T00:
source share

Once you have installed the db utilities, you can simply do db_dump in the db file.

+5
Feb 15 '13 at 0:55
source share

Note that the "db-utils" package is used in the initial answer, but the example shows the correct "db-util" package. (without "s")

+3
Mar 20 '13 at 20:04
source share

On Amazon Linux, you can install it with:

yum install db43-utils

+2
Apr 27 '15 at 19:54
source share



All Articles