BBED是用来直接查看和修改数据文件数据的一个工具,是Oracle一款内部工具,可以直接修改Oracle数据文件块的内容,在一些极端恢复场景下比较有用。要想使用该工具,需用户自己安装,在Oracle 9i和10g版本中,安装的方法很简单:
[oracle@node1 u01]$ cd $ORACLE_HOME/rdbms/lib/
[oracle@node1 lib]$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
Linking BBED utility (bbed)
rm -f /u01/app/oracle/10.2.0/db_1/rdbms/lib/bbed
gcc -o /u01/app/oracle/10.2.0/db_1/rdbms/lib/bbed -L/u01/app/oracle/10.2.0/db_1/rdbms/lib/ -L/u01/app/oracle/10.2.0/db_1/lib/ -L/u01/app/oracle/10.2.0/db_1/lib/stubs/ -L/usr/lib -lirc /u01/app/oracle/10.2.0/db_1/lib/s0main.o /u01/app/oracle/10.2.0/db_1/rdbms/lib/ssbbded.o /u01/app/oracle/10.2.0/db_1/rdbms/lib/sbbdpt.o `cat /u01/app/oracle/10.2.0/db_1/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 /u01/app/oracle/10.2.0/db_1/rdbms/lib/defopt.o -ldbtools10 -lclntsh `cat /u01/app/oracle/10.2.0/db_1/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat /u01/app/oracle/10.2.0/db_1/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10 -lvsn10 -lcommon10 -lgeneric10 -lmm -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 `cat /u01/app/oracle/10.2.0/db_1/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat /u01/app/oracle/10.2.0/db_1/lib/ldflags` -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10 -lvsn10 -lcommon10 -lgeneric10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 -lclient10 -lnnetd10 -lvsn10 -lcommon10 -lgeneric10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 `cat /u01/app/oracle/10.2.0/db_1/lib/sysliblist` -Wl,-rpath,/u01/app/oracle/10.2.0/db_1/lib -lm `cat /u01/app/oracle/10.2.0/db_1/lib/sysliblist` -ldl -lm -L/u01/app/oracle/10.2.0/db_1/lib
Oracle11g中缺省不提供BBET库文件,如果需要可以将10g中的文件copy到11g相应目录再执行安装:
$ORACLE_HOME/rdbms/lib/ssbbded.o
$ORACLE_HOME/rdbms/lib/sbbdpt.o
$ORACLE_HOME/rdbms/mesg/bbedus.msb
$ORACLE_HOME/rdbms/mesg/bbedus.msg
在第一次使用时会发现有默认的口令,从这里可以看出oracle对bbed工具的限制,默认的密码是blockedit
[oracle@node1 ~]$ cd $ORACLE_HOME/rdbms/lib
[oracle@node1 lib]$ ./bbed
Password:
BBED: Release 2.0.0.0.0 - Limited Production on Thu Jul 10 16:09:57 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
查看一下bbed 命令
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 [ <SET parameter> | 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 ]
</Nuf>:
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] <target spec>=<source spec>
<target spec> : [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
<source spec> : [ value | <target spec options> ]
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]
PUSH [ DBA | FILE | FILENAME | BLOCK | OFFSET ]
POP [ALL]
REVERT [ DBA | FILE | FILENAME | BLOCK ]
UNDO
HELP [ <bbed command> | ALL ]
VERIFY [ DBA | FILE | FILENAME | BLOCK ]
CORRUPT [ DBA | FILE | FILENAME | BLOCK ]
set 设定当前的环境
show 查看当前的环境参数,跟sqlplus的同名命令类似。
dump 列出指定block的内容
find 在指定的block中查找指定的字符串,结果是显示出字符串,及其偏移量--offset,偏移量就是在block中的字节数
modify 修改指定block的指定偏移量的值,可以在线修改。
copy 把一个block的内容copy到另一个block中
verify 检查当前环境是否有坏块
sum 计算block的checksum,modify之后block就被标识为坏块,current checksum与reqired checksum不一致,sum命令可以计算出新的checksum并应用到当前块。
undo 回滚当前的修改操作,如果手误做错了,undo一下就ok了,回到原来的状态。
revert 回滚所有之前的修改操作,意思就是 undo all
为bbed配置一个参数文本
制作bbed列表
SQL> set heading off;
SQL> set feedback off;
SQL> spool /u01/bbedlist.parf
SQL> select file#||' '||name||' '||bytes from v$datafile ;
1 /u01/app/oracle/oradata/orcl_dup/system01.dbf 524288000
3 /u01/app/oracle/oradata/orcl_dup/sysaux01.dbf 346030080
4 /u01/app/oracle/oradata/orcl_dup/users01.dbf 191365120
5 /u01/app/oracle/oradata/orcl_dup/example01.dbf 104857600
6 /u01/app/oracle/oradata/orcl_dup/tts01.dbf 20971520
7 /u01/app/oracle/oradata/orcl_dup/tts02.dbf 20971520
8 /u01/app/oracle/oradata/orcl_dup/undotbs001.dbf 104857600
SQL> spool off;
SQL> set heading on;
SQL> set feedback on;
制作parfile
[oracle@node1 lib]$ vi /u01/bbed.par
blocksize = 8192
listfile= /u01/bbedlist.parf
mode = edit
用parfile启动bbed
[oracle@node1 lib]$ ./bbed parfile=/u01/bbed.par password=blockedit
BBED: Release 2.0.0.0.0 - Limited Production on Thu Jul 10 16:42:27 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> show
FILE# 1
BLOCK# 1
OFFSET 0
DBA 0x00400001 (4194305 1,1)
FILENAME /u01/app/oracle/oradata/orcl_dup/system01.dbf
BIFILE bifile.bbd
LISTFILE /u01/bbedlist.parf
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No
通过bbed获取指定数值的RDBA(Relative Data Block Address)
SQL> select * from bbed_test;
JOB
-------------------------
123456
1234567890
2 rows selected.
SQL> select
2 rowid,
3 dbms_rowid.rowid_relative_fno(rowid)rel_fno,
4 dbms_rowid.rowid_block_number(rowid)blockno,
5 dbms_rowid.rowid_row_number(rowid)rowno
6 from bbed_test;
ROWID REL_FNO BLOCKNO ROWNO
------------------ ---------- ---------- ----------
AAAN9GAAEAAAAK0AAA 4 692 0
AAAN9GAAEAAAAK0AAB 4 692 1
2 rows selected.
BBED> set dba 4,692 offset 0
DBA 0x010002b4 (16777908 4,692)
OFFSET 0
BBED> show
FILE# 4
BLOCK# 692
OFFSET 8168
DBA 0x010002b4 (16777908 4,692)
FILENAME /u01/app/oracle/oradata/orcl_dup/users01.dbf
BIFILE bifile.bbd
LISTFILE /u01/bbedlist.parf
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No
当然数据库中通过dbms_utility包也很容易就能获得,此处可以对比一下
SQL> variable get_rdba varchar2(30);
SQL> exec :dba :=dbms_utility.make_data_block_address(4,692);
PL/SQL procedure successfully completed.
SQL> print dba
DBA
--------------------------------
16777908