oracle bbed 恢复无归档的数据库

郑重申明:BBED是oracle的内部工具,如果一旦使用oracle将不在支持该库,所以请慎重。

1,bbed的创建(10g的测试)

[oracle@rac1 ~]$ cd $ORACLE_HOME/rdbms/lib

[oracle@rac1 lib]$ make -f ins_rdbms.mk  BBED=$ORACLE_HOME/bin/bbed  $ORACLE_HOME/bin/bbed

[oracle@rac1 lib]$ cd $ORACLE_HOME/bin

[oracle@rac1 bin]$ ls -lrt bbed
-rwxr-xr-x 1 oracle oinstall 548768 Dec 17 11:49 bbed

2,使用bbed工具

(1) 创建par配置文件

sql>select file#||' '||name||' '||bytes from v$datafile ; 将查询的结果放入/home/oracle/bbed/filelist.txt中。

[oracle@rac1 ~]$ cat /home/oracle/bbed/bbed.par

blocksize=8192

/home/oracle/bbed/filelist.txt

mode=edit

(2)登陆bbed

[oracle@rac1 bbed]$bbed parfile=bbed.par

默认的密码为:blockedit

BBED> help all     -- 可以查看所有可以使用的命令

(3)常用命令

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

(4)直接修改数据文件头的起库

SQL> startup
ORACLE instance started.

Total System Global Area  788529152 bytes
Fixed Size                  2087216 bytes
Variable Size             423626448 bytes
Database Buffers          356515840 bytes
Redo Buffers                6299648 bytes
Database mounted.
ORA-01113: file 4 needs media recovery
ORA-01110: data file 4: '/opt/ora10g/oradata/orcl/users01.dbf'


SQL> select name,checkpoint_change# from v$datafile;

NAME                                               CHECKPOINT_CHANGE#
-------------------------------------------------- ------------------
/opt/ora10g/oradata/orcl/system01.dbf                        13185657
/opt/ora10g/oradata/orcl/undotbs01.dbf                       13185657
/opt/ora10g/oradata/orcl/sysaux01.dbf                        13185657
/opt/ora10g/oradata/orcl/users01.dbf                         13185657
/opt/ora10g/oradata/orcl/test_data.dbf                       13185657
/opt/ora10g/oradata/orcl/xldata01.dbf                        13185657
/opt/ora10g/oradata/orcl/timdata01.dbf                       13185657
/opt/ora10g/oradata/orcl/xllogtmpdata01.dbf                  13185657
/opt/ora10g/oradata/orcl/user02.dbf                          13185657
                                                                                        13185657 换算为16进制 C93279

SQL> select name,checkpoint_change# from v$datafile_header;

NAME                                               CHECKPOINT_CHANGE#
-------------------------------------------------- ------------------
/opt/ora10g/oradata/orcl/system01.dbf                        13185657
/opt/ora10g/oradata/orcl/undotbs01.dbf                       13185657
/opt/ora10g/oradata/orcl/sysaux01.dbf                        13185657
/opt/ora10g/oradata/orcl/users01.dbf                          5609780    5609780换算为16进制559934
/opt/ora10g/oradata/orcl/test_data.dbf                       13185657
/opt/ora10g/oradata/orcl/xldata01.dbf                        13185657
/opt/ora10g/oradata/orcl/timdata01.dbf                       13185657
/opt/ora10g/oradata/orcl/xllogtmpdata01.dbf                  13185657
/opt/ora10g/oradata/orcl/user02.dbf                          13185657

可以看到数据库users01.dbf的scn点为5609780明显是用的备份的数据文件。oracle在open数据库时要对控制文件,数据文件头的scn进行检查,一致才能打开,所以这里我们通过ddeb来修改数据文件头让它和其他的数据文件的scn相同,达到起库的目的。

BBED> set dba 1,1
        DBA             0x00400001 (4194305 1,1)

BBED> p kcvfhckp
struct kcvfhckp, 36 bytes                   @484    
   struct kcvcpscn, 8 bytes                 @484    
      ub4 kscnbas                           @484      0x00c93279  块头的scn
      ub2 kscnwrp                           @488      0x0000
   ub4 kcvcptim                             @492      0x2fd1ebda
   ub2 kcvcpthr                             @496      0x0001
   union u, 12 bytes                        @500    
      struct kcvcprba, 12 bytes             @500    
         ub4 kcrbaseq                       @500      0x000005cc
         ub4 kcrbabno                       @504      0x0000ebe1
         ub2 kcrbabof                       @508      0x0010
   ub1 kcvcpetb[0]                          @512      0x02
   ub1 kcvcpetb[1]                          @513      0x00
   ub1 kcvcpetb[2]                          @514      0x00
   ub1 kcvcpetb[3]                          @515      0x00
   ub1 kcvcpetb[4]                          @516      0x00
   ub1 kcvcpetb[5]                          @517      0x00
   ub1 kcvcpetb[6]                          @518      0x00
   ub1 kcvcpetb[7]                          @519      0x00

 

BBED> set filename '/opt/ora10g/oradata/orcl/users01.dbf'
        FILENAME        /opt/ora10g/oradata/orcl/users01.dbf

BBED> p kcvfhckp
struct kcvfhckp, 36 bytes                   @484    
   struct kcvcpscn, 8 bytes                 @484    
      ub4 kscnbas                           @484      0x00559934  块头的scn号
      ub2 kscnwrp                           @488      0x0000
   ub4 kcvcptim                             @492      0x2f56f20a
   ub2 kcvcpthr                             @496      0x0001
   union u, 12 bytes                        @500    
      struct kcvcprba, 12 bytes             @500    
         ub4 kcrbaseq                       @500      0x000000ee
         ub4 kcrbabno                       @504      0x00003cea
         ub2 kcrbabof                       @508      0x0010
   ub1 kcvcpetb[0]                          @512      0x02
   ub1 kcvcpetb[1]                          @513      0x00
   ub1 kcvcpetb[2]                          @514      0x00
   ub1 kcvcpetb[3]                          @515      0x00
   ub1 kcvcpetb[4]                          @516      0x00
   ub1 kcvcpetb[5]                          @517      0x00
   ub1 kcvcpetb[6]                          @518      0x00
   ub1 kcvcpetb[7]                          @519      0x00

查看users01.dbf的块头

BBED> d /v dba 4,1 offset 484
 File: /opt/ora10g/oradata/orcl/users01.dbf (4)
 Block: 1       Offsets:  484 to  995  Dba:0x01000001
-------------------------------------------------------
 34995500 00000000 0af2562f 01000160 l 4.U......騐/...`  红色的标志和块头的scn号00559934是否很相似啊?

 ee000000 ea3c0000 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 ................
 0d000d00 0d000100 00000000 00000000 l ................
 00000000 02000001 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................

看一下第一块的块头信息 

 BBED> d /v dba 1,1 offset 484     
 File: /opt/ora10g/oradata/orcl/system01.dbf (1)
 Block: 1       Offsets:  484 to  995  Dba:0x00400001
-------------------------------------------------------
 7932c900 00000000 daebd12f 01000160 l y2?....陔?...`红色的标志和块头的scn号00c93279是否很相似啊?

 cc050000 e1eb0000 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 ................
 0d000d00 0d000100 00000000 00000000 l ................

猜想是oracle为了保护数据文件头而特意将scn号反正写。

BBED> modify /x 7932c900 dba 4,1 offset 484
 File: /opt/ora10g/oradata/orcl/users01.dbf (4)
 Block: 1                Offsets:  484 to  995           Dba:0x01000001
------------------------------------------------------------------------
 7932c900 00000000 0af2562f 01000160 ee000000 ea3c0000 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
 0d000d00 0d000100 00000000 00000000 00000000 02000001 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>

BBED> sum dba 4,1 apply
Check value for File 4, Block 1:
current = 0x3ffd, required = 0x3ffd

检查一下块头

BBED> d /v dba 4,1 offset 484
 File: /opt/ora10g/oradata/orcl/users01.dbf (4)
 Block: 1       Offsets:  484 to  995  Dba:0x01000001
-------------------------------------------------------
 7a32c900 00000000 1c28d22f 01000000 l z2?.....(?....
 cc050000 e1eb0000 10000000 02000000 l ?..犭..........
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................

数据块头已经修改可以起库了。

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 4 needs media recovery
ORA-01110: data file 4: '/opt/ora10g/oradata/orcl/users01.dbf'


SQL> recover database;
Media recovery complete.
SQL> alter database open;

Database altered.


 

你可能感兴趣的:(oracle bbed 恢复无归档的数据库)