BBED(Oracle Block Browerand EDitor Tool),用来直接查看和修改数据文件数据的一个工具,是Oracle一款内部工具,可以直接修改Oracle数据文件
块的内容,在一些极端恢复场景下比较有用。该工具不受Oracle支持,所以默认是没有生成可执行文件的,在使用前需要重新连接。OracleDatabase
11g中缺省的未提供BBED库文件,但是可以用10g的文件编译出来,需要先从10g中复制如下文件到相应目录
bbedus.msb  复制到$ORACLE_HOME/rdbms/mesg
sbbdpt.o ssbbded.o 复制到$ORACLE_HOME/rdbms/lib
编译
make -f ins_rdbms.mk BBED=$ORACLE_HOME/bin/bbed $ORACLE_HOME/bin/bbed
在9i/10g中有bbed,需要编译
Linking BBED utility (bbed)
rm -f /u01/app/oracle/product/11.2.0/dbhome_1/bin/bbed
/usr/bin/gcc -m32 -o
/u01/app/oracle/product/11.2.0/dbhome_1/bin/bbed -m32 -
L/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib/ -
L/u01/app/oracle/product/11.2.0/dbhome_1/lib/ -
L/u01/app/oracle/product/11.2.0/dbhome_1/lib/stubs/ -
L/u01/app/oracle/product/11.2.0/dbhome_1/lib/ -lirc -lipgo
/u01/app/oracle/product/11.2.0/dbhome_1/lib/s0main.o
/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib/ssbbded.o
/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib/sbbdpt.o `cat
/u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags` -lncrypt11 -
lnsgr11 -lnzjs11 -ln11 -lnl11 -ldbtools11 -lclntsh `cat
/u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags` -lncrypt11 -
lnsgr11 -lnzjs11 -ln11 -lnl11 -lnro11 `cat
/u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags` -lncrypt11 -
lnsgr11 -lnzjs11 -ln11 -lnl11 -lnnz11 -lzt11 -lztkg11 -lztkg11 -
lclient11 -lnnetd11 -lvsn11 -lcommon11 -lgeneric11 -lmm -lsnls11
-lnls11 -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -
lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 `cat
/u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags` -lncrypt11 -
lnsgr11 -lnzjs11 -ln11 -lnl11 -lnro11 `cat
/u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags` -lncrypt11 -
lnsgr11 -lnzjs11 -ln11 -lnl11 -lclient11 -lnnetd11 -lvsn11 -
lcommon11 -lgeneric11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11
-lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -
lnls11 -lcore11 -lnls11 -lclient11 -lnnetd11 -lvsn11 -lcommon11 -
lgeneric11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lcore11 -
lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -
lcore11 -lnls11 `cat
/u01/app/oracle/product/11.2.0/dbhome_1/lib/sysliblist` -Wl,-
rpath,/u01/app/oracle/product/11.2.0/dbhome_1/lib -lm `cat
/u01/app/oracle/product/11.2.0/dbhome_1/lib/sysliblist` -ldl -lm
-L/u01/app/oracle/product/11.2.0/dbhome_1/lib
BBED是Oracle 内部使用的命令,所以Oracle 不提供技术支持。 为了安全
,BBED设置了口令保护,默认密码为blockedit。
[oracle@guo ~]bbed
Password:
BBED: Release 2.0.0.0.0 – Limited Production on Tue May 19
10:14:00 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights
reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> show
FILE# 0
BLOCK# 1
OFFSET 0
DBA 0×00000000 (0 0,1)
FILENAME
BIFILE bifile.bbd
LISTFILE
BLOCKSIZE 8192
MODE Browse
EDIT Unrecoverable
IBASE Dec
测试环境
SYS@PROD1 > select * from v$version;
BANNER
——————————————————————————–
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – Production
PL/SQL Release 11.2.0.3.0 – Production
CORE    11.2.0.3.0      Production
TNS for Linux: Version 11.2.0.3.0 – Production
NLSRTL Version 11.2.0.3.0 – Production
破坏system表空间文件
cd $ORACLE_BASE/oradata/PROD1
cp system01.dbf system01.dbf.bak
切日志模拟生产交易,更新SCN
SYS@PROD1 > alter system switch logfile;
切多次
SYS@PROD1 > /
System altered.
SYS@PROD1 > /
System altered.
把旧的system文件直接复制替换掉新的
cp system01.dbf.bak system01.dbf
再次切日志模拟生产交易
SYS@PROD1 > alter system switch logfile;
切多次
SYS@PROD1 > /
System altered.
SYS@PROD1 > /
System altered.
/
alter system switch logfile
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 25597
Session ID: 24 Serial number: 887
出现问题,数据库直接宕掉
SYS@PROD1 > ERROR:
ORA-03114: not connected to ORACLE
SYS@PROD1 > conn / as sysdba
Connected.
SYS@PROD1 > select status from v$instance;
ERROR:
ORA-01012: not logged on
SYS@PROD1 > conn / as sysdba
SYS@PROD1 > startup
ORACLE instance started.
Total System Global Area  313860096 bytes
Fixed Size                  1344652 bytes
Variable Size             260049780 bytes
Database Buffers           46137344 bytes
Redo Buffers                6328320 bytes
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: ‘/u01/app/oracle/oradata/PROD1/system01.dbf’
SYS@PROD1 > col name for a50
SYS@PROD1 > select name,checkpoint_change# from v$datafile;
NAME                                               CHECKPOINT_CHANGE#
————————————————– ——————
/u01/app/oracle/oradata/PROD1/system01.dbf                    1199315
/u01/app/oracle/oradata/PROD1/sysaux01.dbf                    1199315
/u01/app/oracle/oradata/PROD1/undotbs01.dbf                   1199315
/u01/app/oracle/oradata/PROD1/users01.dbf                     1199315
/u01/app/oracle/oradata/PROD1/example01.dbf                   1199315
scn转换成16进制
SYS@PROD1 > select to_char(1199315,’xxxxxxxx’) from dual;
TO_CHAR(1
———
124cd3
对应数据文件头
SYS@PROD1 > select name,checkpoint_change# from v$datafile_header;
NAME                                               CHECKPOINT_CHANGE#
————————————————– ——————
/u01/app/oracle/oradata/PROD1/system01.dbf                    1191817
/u01/app/oracle/oradata/PROD1/sysaux01.dbf                    1199315
/u01/app/oracle/oradata/PROD1/undotbs01.dbf                   1199315
/u01/app/oracle/oradata/PROD1/users01.dbf                     1199315
/u01/app/oracle/oradata/PROD1/example01.dbf                   1199315
可以看到数据库users01.dbf的scn点为1191817明显是用的备份的数据文件。oracle在open数据库时要对控制文件,数据文件头的scn进行检查,一致才能打开,所以这里我们通过ddeb来修改
数据文件头让它和其他的数据文件的scn相同,达到起库的目的。
[oracle@guo ~]$ bbed parfile=bbed.par
Password:
BBED: Release 2.0.0.0.0 – Limited Production on Tue May 19 10:52:04 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
用bbed查询bbed01数据文件结构信息
BBED> set dba 1,1
DBA 0×00400001 (4194305 1,1)
Bbed查看kcvfh信息
BBED> p kcvfhckp
struct kcvfhckp, 36 bytes @484
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 0×00122f89
ub2 kscnwrp @488 0×0000
ub4 kcvcptim @492 0×34754da5
ub2 kcvcpthr @496 0×0001
union u, 12 bytes @500
struct kcvcprba, 12 bytes @500
ub4 kcrbaseq @500 0×0000001e
ub4 kcrbabno @504 0×00000002
ub2 kcrbabof @508 0×0010
ub1 kcvcpetb[0] @512 0×02
ub1 kcvcpetb[1] @513 0×00
ub1 kcvcpetb[2] @514 0×00
ub1 kcvcpetb[3] @515 0×00
ub1 kcvcpetb[4] @516 0×00
ub1 kcvcpetb[5] @517 0×00
ub1 kcvcpetb[6] @518 0×00
ub1 kcvcpetb[7] @519 0×00
BBED> set filename ‘/u01/app/oracle/oradata/PROD1/system01.dbf’
FILENAME /u01/app/oracle/oradata/PROD1/system01.dbf
BBED> p kcvfhckp
struct kcvfhckp, 36 bytes @484
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 0×00122f89
ub2 kscnwrp @488 0×0000
ub4 kcvcptim @492 0×34754da5
ub2 kcvcpthr @496 0×0001
union u, 12 bytes @500
struct kcvcprba, 12 bytes @500
ub4 kcrbaseq @500 0×0000001e
ub4 kcrbabno @504 0×00000002
ub2 kcrbabof @508 0×0010
ub1 kcvcpetb[0] @512 0×02
ub1 kcvcpetb[1] @513 0×00
ub1 kcvcpetb[2] @514 0×00
ub1 kcvcpetb[3] @515 0×00
ub1 kcvcpetb[4] @516 0×00
ub1 kcvcpetb[5] @517 0×00
ub1 kcvcpetb[6] @518 0×00
ub1 kcvcpetb[7] @519 0×00
<16 bytes per line>
system文件头
BBED> d /v dba 1,1 offset 484
File: /u01/app/oracle/oradata/PROD1/system01.dbf (1)
Block: 1 Offsets: 484 to 995 Dba:0×00400001
——————————————————-
892f1200 000089bf a54d7534 01000000 l ./…..??Mu4….
1e000000 02000000 10000000 02000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
0a000a00 0a000100 00000000 00000000 l …………….
00000000 02004000 72fc0b00 00000000 l ……@.r?……
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 024c6582 l ………….Le.
d61636a4 7acf3f5d 13b1e763 d0000000 l ?.6?z??].??c?…
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00173356 l …………..3V
1c4cd306 46040f87 3704db71 a6210600 l .L?.F…7.?q?!..
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
<16 bytes per line>
查看正常数据文件头
BBED> d /v dba 4,1
File: /u01/app/oracle/oradata/PROD1/users01.dbf (4)
Block: 1 Offsets: 484 to 995 Dba:0×01000001
——————————————————-
d34c1200 0000ae31 c9607534 0100af31 l ?L….?1?`u4..?1   应该是oracle为保护数据文件,在文件头与SCN做了重排
29000000 02000000 10000000 02000000 l )……………
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
0a000a00 0a000100 00000000 00000000 l …………….
00000000 02000001 03000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
修改system文件头
BBED> modify /x d34c1200 dba 1,1
BBED-00209: invalid number (d34c1200)
BBED> sum dba 1,1 apply
Check value for File 1, Block 1:
current = 0×6d23, required = 0×6d23
BBED> d /v dba 1,1
File: /u01/app/oracle/oradata/PROD1/system01.dbf (1)
Block: 1 Offsets: 484 to 995 Dba:0×00400001
——————————————————-
892f1200 000089bf a54d7534 01000000 l ./…..??Mu4….
1e000000 02000000 10000000 02000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
0a000a00 0a000100 00000000 00000000 l …………….
00000000 02004000 72fc0b00 00000000 l ……@.r?……
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 024c6582 l ………….Le.
d61636a4 7acf3f5d 13b1e763 d0000000 l ?.6?z??].??c?…
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00173356 l …………..3V
1c4cd306 46040f87 3704db71 a6210600 l .L?.F…7.?q?!..
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
<16 bytes per line>
BBED> modify /x d34c1200 dba 1,1 offset 484
BBED-00209: invalid number (d34c1200)
完整16进制提示无效d34c1200,大小字节数问题
892f1200 旧
d34c1200 新
对比发现新旧文件头地址后四位一样,只需改后四位即可
如果为纯数字16进制,无此错误,不知为什么。
BBED> modify /x d34c dba 1,1 offset 484  (填写部分,字母前的)
File: /u01/app/oracle/oradata/PROD1/system01.dbf (1)
Block: 1 Offsets: 484 to 995 Dba:0×00400001
————————————————————————
d34c1200 000089bf a54d7534 01000000 1e000000 02000000 10000000 02000000
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
0a000a00 0a000100 00000000 00000000 00000000 02004000 72fc0b00 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 024c6582 d61636a4 7acf3f5d 13b1e763 d0000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00173356
1c4cd306 46040f87 3704db71 a6210600 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>
BBED> sum dba 1,1 apply
Check value for File 1, Block 1:
current = 0×0e79, required = 0×0e79
BBED> d /v dba 1,1
File: /u01/app/oracle/oradata/PROD1/system01.dbf (1)
Block: 1 Offsets: 484 to 995 Dba:0×00400001
——————————————————-
d34c1200 000089bf a54d7534 01000000 l ?L…..??Mu4….
1e000000 02000000 10000000 02000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
0a000a00 0a000100 00000000 00000000 l …………….
00000000 02004000 72fc0b00 00000000 l ……@.r?……
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 024c6582 l ………….Le.
d61636a4 7acf3f5d 13b1e763 d0000000 l ?.6?z??].??c?…
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00173356 l …………..3V
1c4cd306 46040f87 3704db71 a6210600 l .L?.F…7.?q?!..
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
00000000 00000000 00000000 00000000 l …………….
<16 bytes per line>
BBED>
SYS@PROD1 > alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: ‘/u01/app/oracle/oradata/PROD1/system01.dbf’
SYS@PROD1 > recover database;
Media recovery complete.
SYS@PROD1 > alter database open;
Database altered.



Related posts

coded by nessus
分享:  DeliciousGReader鲜果豆瓣CSDN网摘
Trackback

no comment untill now

Add your comment now

无觅相关文章插件