Linux 从 CLI 检查 Berkeley DB 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Examining Berkeley DB files from the CLI
提问by mercutio
I have a set of Berkeley DB files on my Linux file system that I'd like to examine.
我想检查我的 Linux 文件系统上的一组 Berkeley DB 文件。
What useful tools exist for getting a quick overview of the contents? I can write Perl scripts that use BDB modules for examining them, but I'm looking for some CLI utility to be able to take a look inside without having to start writing scripts.
有哪些有用的工具可以快速浏览内容?我可以编写使用 BDB 模块检查它们的 Perl 脚本,但我正在寻找一些 CLI 实用程序,以便无需开始编写脚本即可查看内部情况。
采纳答案by David Crow
Check out the db-utilspackage. If you use apt, you can install it with the following: apt-get install db-util
(or apt-get install db4.8-util
or whatever version you have or prefer.)
查看db-utils包。如果您使用 apt,则可以使用以下内容安装它:(apt-get install db-util
或apt-get install db4.8-util
您拥有或喜欢的任何版本。)
Additional links:
附加链接:
回答by Ishtiaq Ahmed
The db_hotbackup utility creates "hot backup" or "hot failover" snapshots of Berkeley DB database environments. Install it with the following
db_hotbackup 实用程序创建 Berkeley DB 数据库环境的“热备份”或“热故障转移”快照。使用以下命令安装它
apt-get install db-util
apt-get 安装 db-util
then run following command to take hot backup
然后运行以下命令进行热备份
db_hotbackup [-cDEguVv] [-d data_dir ...] [-h home] [-l log_dir] [-P password] -b backup_dir
db_hotbackup [-cDEguVv] [-d data_dir ...] [-h home] [-l log_dir] [-P 密码] -b backup_dir
回答by Gunnarsson
Once you have installed the db utils you can simple do a db_dumpon the db file.
安装 db utils 后,您可以简单地对 db 文件执行db_dump。
回答by A.R. Pepper
Note that the initial answer says to use "db-utils" package, but the example shows the correct "db-util" package. (with no "s")
请注意,最初的答案是使用“db-utils”包,但该示例显示了正确的“db-util”包。(没有“s”)
回答by strickli
As mentioned in the other answers, the db-utils package (db4-utils under RHEL) has some tools. However, db_dump can be unhelpful, since the output is 'bytevalue' format.
正如其他答案中提到的,db-utils 包(RHEL 下的 db4-utils)有一些工具。但是,db_dump 可能没有帮助,因为输出是“字节值”格式。
For a quick'n'dirty viewer, use python:
对于快速'n'dirty查看器,请使用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 since python 2.6.
请注意,自 python 2.6 起不推荐使用 dbhash。
回答by trjh
I found @strickli's answer to be the most helpful, as I didn't 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, not hash, so I had to use bsddb
我发现@strickli 的答案最有帮助,因为我不想使用我所在的数据库向机器添加任何新包。但是,我正在读取的 db 文件是 btree 类型,而不是哈希类型,所以我不得不使用 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
...
回答by Dan Herman
Under Amazon Linux you can install it with:
在 Amazon Linux 下,您可以使用以下命令安装它:
yum install db43-utils
yum 安装 db43-utils
回答by cdauth
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 whatever version you are using).
使用该db_dump
程序。它包含在包core/db
(Arch)、db-util
(Debian、Ubuntu)、sys-libs/db
(Gentoo,请注意这里调用的二进制文件db4.8_dump
或您使用的任何版本) 中。
On some systems the man pages are not installed, in that case the documentation can be found here. By default, db_dump
outputs some hex numbers, which is not really useful if you are trying to analyse the content of a database. Use the -p
argument to change this.
在某些系统上,没有安装手册页,在这种情况下,可以在此处找到文档。默认情况下,db_dump
输出一些十六进制数字,如果您尝试分析数据库的内容,这不是很有用。使用-p
参数来改变这一点。
Show everything that's in the file database.db
:
显示文件中的所有内容database.db
:
db_dump -p database.db
List the databases in the file database.db
:
列出文件中的数据库database.db
:
db_dump -l database.db
Show only the content of the database mydb
in the file database.db
:
仅显示mydb
文件中数据库的内容database.db
:
db_dump -p -s mydb database.db