bbed是oracle内部一款用来直接查看和修改数据文件数据的工具,可以直接修改Oracle数据文件块的内容,在一些特殊恢复场景下比较有用。
1.bbed 的安装
在9i/10g中连接生成bbed: cd $ORACLE_HOME/rdbms/lib make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed 11g中缺省未提供BBED库文件,但可以把10g的文件copy到相应目录下,再进行编译 oracle 11g中缺bbed包,oracle11g bbed install and example 上传(sbbdpt.o ssbbded.o bbedus.msb,该三个文件拷贝oracle的linux64版本的)文件 $ORACLE_HOME/rdbms/lib/ssbbded.o $ORACLE_HOME/rdbms/lib/sbbdpt.o $ORACLE_HOME/rdbms/mesg/bbedus.msb 执行如下命令: cd $ORACLE_HOME/rdbms/lib make -f $ORACLE_HOME/rdbms/lib/ins_rdbms.mk BBED=$ORACLE_HOME/bin/bbed $ORACLE_HOME/bin/bbed
2.bbed 的使用
[oracle@ora11g ~]$ bbed -help LRM-00118: syntax error at '-' at the end of input 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] BBED-00105: LRM error 110 occurred during command line parsing
为了用起来方便,可以先定义一个文件,将数据文件查询出来,放入到参数文件中
[oracle@ora11g ~]$ vi parameter.txt blocksize=8192 listfile=dbfiles.txt mode=edit $vi dbfiles.txt select file#||chr(9)||name||chr(9)||bytes from v$datafile; 1 /u01/app/oracle/oradata/test1212/system01.dbf 713031680 2 /u01/app/oracle/oradata/test1212/sysaux01.dbf 524288000 3 /u01/app/oracle/oradata/test1212/undotbs01.dbf 372244480 4 /u01/app/oracle/oradata/test1212/users01.dbf 136314880 5 /u01/app/oracle/oradata/test1212/ss01.dbf 104857600
用了参数文件之后再次进入:
[oracle@ora11g ~]$ bbed parfile=parameter.txt Password: BBED: Release 2.0.0.0.0 - Limited Production on Fri Feb 7 00:54:04 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. ************* !!! For Oracle Internal Use only !!! *************** BBED>
3.初步使用
info命令 --显示当前可以进行browse 或者edit 的file。即filelist 里指定的datafile信息。
BBED> info File# Name Size(blks) ----- ---- ---------- 1 /u01/app/oracle/oradata/test1212/system01.dbf 87040 2 /u01/app/oracle/oradata/test1212/sysaux01.dbf 64000 3 /u01/app/oracle/oradata/test1212/undotbs01.dbf 45440 4 /u01/app/oracle/oradata/test1212/users01.dbf 16640 5 /u01/app/oracle/oradata/test1212/ss01.dbf 12800
show命令 -- 显示当前的配置选项
BBED> show all FILE# 1 BLOCK# 1 OFFSET 0 --偏移量,0代表从第1个字节, DBA 0x00400001 (4194305 1,1) --DBA(data block addr)的组成 = 文件号 + 块号,一共32位 FILENAME /u01/app/oracle/oradata/test1212/system01.dbf BIFILE bifile.bbd LISTFILE dbfiles.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 512 LOGFILE log.bbd SPOOL No
备注:
DBA(data block addr) = file#(10bit) + block#(22bit) =32bit
所以文件个数最多是2的10次方=1024个
DBA = 0x00400001 ====> 0000 0000 0100 0000 0000 0000 0000 0001
从以上所知的前10位为file#,所以可以放一个分隔符再看:
0000 0000 01[分隔符]00 0000 0000 0000 0000 0001 (4194305 1,1)
可以看出file#=1,block#=1 ,就和上面的show出来的信息对应起来了
set命令 --设置相应的信息
如果要查看2号文件的2号块,则可以使用set命令来设置文件号和块号
BBED> set file 2 FILE# 2 BBED> set block 2 BLOCK# 2 BBED> show all FILE# 2 BLOCK# 2 OFFSET 0 DBA 0x00800002 (8388610 2,2) FILENAME /u01/app/oracle/oradata/test1212/sysaux01.dbf BIFILE bifile.bbd LISTFILE dbfiles.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 512 LOGFILE log.bbd SPOOL No DBA = 0x00800002 ===》 0000 0000 1000 0000 0000 0000 0000 0010
再次回到1号文件的0号块
BBED> set file 1 FILE# 1 BBED> set block 0 BLOCK# 0 BBED> show all FILE# 1 BLOCK# 0 OFFSET 0 DBA 0x00400000 (4194304 1,0) FILENAME /u01/app/oracle/oradata/test1212/system01.dbf BIFILE bifile.bbd LISTFILE dbfiles.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 512 LOGFILE log.bbd SPOOL No
dump命令 --十六进制查看block
dump /v --查看十六进制内容的同时以文本方式“翻译”十六进制显示的内容,相当于对当前block执行strings命令
BBED> dump File: /u01/app/oracle/oradata/test1212/system01.dbf (1) Block: 0 Offsets: 0 to 511 Dba:0x00400000 ------------------------------------------------------------------------ 00a20000 0000c0ff 00000000 00000000 67ae0000 00200000 00540100 7d7c7b7a a0810000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line>
备注:
从Offsets可以看出,只显示了0-511个字节的偏移,也就是512个字节的信息,因为默认是 COUNT=512
我们知道oracle一个块默认大小8192,所以如果要让一个块的dump信息显示完全的话,就可以set count 8192,再执行dump
map命令 --Map会通过偏移量来显示block里的详细信息,如block header,data block header 和row directory。
在不指定block的情况下,会显示当前block的信息,如果想显示其他block的信息,可以使用file name,file id,block 和DBA 来指定要显示的block。
BBED> map File: /u01/app/oracle/oradata/test1212/system01.dbf (1) Block: 1 Dba:0x00400001 ------------------------------------------------------------ Data File Header struct kcvfh, 860 bytes @0 ub4 tailchk @8188
备注:
u 代表没有符号的 unsigned
tailchk 尾部校验,一共是8192个块,因为是从0开始的,所以最后一个字节是8191,换句话说就是从8188-8191这4个字节是不能用的,是拿来做尾部校验的
struct kcvfh ,其中的kcvfh其实在oracle中也有一个视图可以查询select * from x$kcvfh; 今后再进行仔细研究
map /v --比map更详细的查看block里面的信息
BBED> map /v File: /u01/app/oracle/oradata/test1212/system01.dbf (1) Block: 1 Dba:0x00400001 ------------------------------------------------------------ Data File Header struct kcvfh, 860 bytes @0 struct kcvfhbfh, 20 bytes @0 struct kcvfhhdr, 76 bytes @20 ub4 kcvfhrdb @96 struct kcvfhcrs, 8 bytes @100 ub4 kcvfhcrt @108 ub4 kcvfhrlc @112 struct kcvfhrls, 8 bytes @116 ub4 kcvfhbti @124 struct kcvfhbsc, 8 bytes @128 ub2 kcvfhbth @136 ub2 kcvfhsta @138 struct kcvfhckp, 36 bytes @484 ub4 kcvfhcpc @140 ub4 kcvfhrts @144 ub4 kcvfhccc @148 struct kcvfhbcp, 36 bytes @152 ub4 kcvfhbhz @312 struct kcvfhxcd, 16 bytes @316 sword kcvfhtsn @332 ub2 kcvfhtln @336 text kcvfhtnm[30] @338 ub4 kcvfhrfn @368 struct kcvfhrfs, 8 bytes @372 ub4 kcvfhrft @380 struct kcvfhafs, 8 bytes @384 ub4 kcvfhbbc @392 ub4 kcvfhncb @396 ub4 kcvfhmcb @400 ub4 kcvfhlcb @404 ub4 kcvfhbcs @408 ub2 kcvfhofb @412 ub2 kcvfhnfb @414 ub4 kcvfhprc @416 struct kcvfhprs, 8 bytes @420 struct kcvfhprfs, 8 bytes @428 ub4 kcvfhtrt @444 ub4 tailchk @8188
print命令 --查看命令,可以用p来简写
如果想对上面的 struct kcvfhbfh再进行详细的查看,可以使用命令print来查看
BBED> p kcvfhbfh struct kcvfhbfh, 20 bytes @0 ub1 type_kcbh @0 0x0b ub1 frmt_kcbh @1 0xa2 ub1 spare1_kcbh @2 0x00 ub1 spare2_kcbh @3 0x00 ub4 rdba_kcbh @4 0x00400001 ub4 bas_kcbh @8 0x00000000 ub2 wrp_kcbh @12 0x0000 ub1 seq_kcbh @14 0x01 ub1 flg_kcbh @15 0x04 (KCBHFCKV) ub2 chkval_kcbh @16 0xe81a ub2 spare3_kcbh @18 0x0000