在一次故障处理中,使用到了BBED(Oracle Block Brower and EDitor Tool),这是Oracle一款内部工具,可以直接修改Oracle数据文件块的内容,在一些极端恢复场景下比较有用。该工具不受Oracle支持,所以默认是没有生成可执行文件的,在使用前需要重新连接。
在9i/10g中连接生成BBED:
cd $Oracle_HOME/rdbms/lib make -f ins_rdbms.mk $Oracle_HOME/rdbms/lib/BBED
以上生成的BBED可执行文件在$Oracle_HOME/rdbms/lib目录,可以复制到其他位置或者其他同Oracle版本的机器上运行。也可通过以下命令将BBED生成到$Oracle_HOME/bin目录
make -f ins_rdbms.mk BBED=$Oracle_HOME/bin/BBED $Oracle_HOME/bin/BBED
在11g中生成BBED,需要先从10g中复制如下文件到相应目录,然后再执行上述连接命令:
$Oracle_HOME/rdbms/lib/ssbbded.o $Oracle_HOME/rdbms/lib/sbbdpt.o $Oracle_HOME/rdbms/mesg/BBEDus.msb
BBED设置了口令保护,密码为blockedit。BBED的命令行参数:
$BBED help=yes PASSWORD - Required parameter FILENAME - Database file name BLOCKSIZE - Database block size LISTFILE - List file name MODE - [browse/edit] SPOOL - Spool to logfile [no/yes] CMDFILE - BBED command file name LOGFILE - BBED log file name PARFILE - Parameter file name BIFILE - BBED before-image file name REVERT - Rollback changes from BIFILE [no/yes] SILENT - Hide banner [no/yes] HELP - Show all valid parameters [no/yes]
一般将一些常用选项写入到一个parfile中:
blocksize=8192 listfile=filelist.txt mode=edit
其中filelist.txt列出了需要使用BBED编辑的数据文件列表,格式为
文件编号 文件名字 文件大小 1 /u01/Oracle/oradata/NinGoo/system.dbf 2097160192 2 /u01/Oracle/oradata/NinGoo/test.dbf 2097160192
这里的文件编号不一定要和数据库里的file_id相同,当然最好能设置相同,以免在处理过程中搞混淆了。
$BBED parfile=BBED.par Password: BBED: Release 2.0.0.0.0 - Limited Production on Sun Nov 15 00:26:14 2009 Copyright (c) 1982, 2007, Oracle. All rights reserved. ************* !!! For Oracle Internal Use only !!! *************** BBED> help HELP [| ALL ] BBED> help all SET DBA [ dba | file#, block# ] SET FILENAME 'filename' SET FILE file# SET BLOCK [+/-]block# SET OFFSET [ [+/-]byte offset | symbol | *symbol ] SET BLOCKSIZE bytes SET LIST[FILE] 'filename' SET WIDTH character_count SET COUNT bytes_to_display SET IBASE [ HEX | OCT | DEC ] SET OBASE [ HEX | OCT | DEC ] SET MODE [ BROWSE | EDIT ] SET SPOOL [ Y | N ] SHOW [ | ALL ] INFO MAP[/v] [ DBA | FILENAME | FILE | BLOCK ] DUMP[/v] [ DBA | FILENAME | FILE | BLOCK | OFFSET | COUNT ] PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ] EXAMINE[/Nuf] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ] : N - a number which specifies a repeat count. u - a letter which specifies a unit size: b - b1, ub1 (byte) h - b2, ub2 (half-word) w - b4, ub4(word) r - Oracle table/index row f - a letter which specifies a display format: x - hexadecimal d - decimal u - unsigned decimal o - octal c - character (native) n - Oracle number t - Oracle date i - Oracle rowid FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ] COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ] MODIFY[/x|d|u|o|c] numeric/character string [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ] ASSIGN[/x|d|u|o] =
关于BBED的具体用法,这里就不罗嗦了,有兴趣的可以自行学习,下面这篇参考文档非常的详尽:
http://orafaq.com/papers/dissassembling_the_data_block.pdf