您的位置:首页 > 数据库 > Oracle

Oracle bbed的使用(跨归档恢复)

2013-08-12 23:48 357 查看
   正常情况下,数据库要打开则数据文件头的SCN号要和控制文件记录的一致(数据文件或表空间离线的情况例外),我们可以利用这个特性,通过修改数据文件头上SCN的方式来跨过相应归档实现不完全恢复,这种方法在非常规的恢复中可能会用到,当然最好还是从备份中恢复,提前做好备份方案,这样心里才有底,下面简单演示如果跨归档恢复,仅仅演示而已,希望生产环境中永远不会碰到。

 

1、  删除一个数据文件,查看相应SCN号

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

 

NAME                              STATUS  CHECKPOINT_CHANGE#

---------------------------------------------------------- ------------------

/u02/app/oracle/oradata/ora10g/system01.dbf    ONLINE        1490772

/u02/app/oracle/oradata/ora10g/undotbs01.dbf    ONLINE       1490772

/u02/app/oracle/oradata/ora10g/sysaux01.dbf    ONLINE        1490772

                                                    ONLINE         0

可以看到数据文件已经丢失,下面从RMAN备份中还原一个但不做恢复

 

2、从RMAN备份中还原一个数据文件,但不做恢复

RMAN> restore datafile4;

Startingrestore at 12-8月 -13

allocatedchannel: ORA_DISK_1

channelORA_DISK_1: sid=155 devtype=DISK

channelORA_DISK_1: starting datafile backupset restore

channelORA_DISK_1: specifying datafile(s) to restore from backup set

restoringdatafile 00004 to /u02/app/oracle/oradata/ora10g/users01.dbf

channelORA_DISK_1: reading from backup piece /u01/backup/0doh4ghj_1_1.bkp

channelORA_DISK_1: restored backup piece 1

piecehandle=/u01/backup/0doh4ghj_1_1.bkp tag=TAG20130812T165619

channelORA_DISK_1: restore complete, elapsed time: 00:00:02

Finishedrestore at 12-8月 -13

 

再次查看数据文件头

 

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

 

NAME                              STATUS  CHECKPOINT_CHANGE#

---------------------------------------------------------- ------------------

/u02/app/oracle/oradata/ora10g/system01.dbf    ONLINE        1490772

/u02/app/oracle/oradata/ora10g/undotbs01.dbf    ONLINE       1490772

/u02/app/oracle/oradata/ora10g/sysaux01.dbf    ONLINE        1490772

/u02/app/oracle/oradata/ora10g/users01.dbf     ONLINE       1378511

 

现在打开数据库:

SQL> alter database open;

alterdatabase open

*

ERRORat line 1:

ORA-01113:file 4 needs media recovery if it was restored from backup, or END BACKUP if itwas not

ORA-01110:data file 4: '/u02/app/oracle/oradata/ora10g/users01.dbf'

SQL>recover database;##此时归档已经删除

ORA-00279:change 1378511 generated at 08/12/2013 16:56:19 needed for thread 1

ORA-00289:suggestion :

/u02/app/oracle/flash_recovery_area/ORA10G/archivelog/2013_08_12/o1_mf_1_54_%u_.arc

ORA-00280:change 1378511 for thread 1 is in sequence #54

Specifylog: {<RET>=suggested | filename | AUTO | CANCEL}

auto

ORA-00308:cannot open archived log

'/u02/app/oracle/flash_recovery_area/ORA10G/archivelog/2013_08_12/o1_mf_1_54_%u_.arc'

ORA-27037:unable to obtain file status

Linux-x86_64Error: 2: No such file or directory

Additionalinformation: 3

ORA-00308:cannot open archived log '/u02/app/oracle/flash_recovery_area/ORA10G/archivelog/2013_08_12/o1_mf_1_54_%u_.arc'

ORA-27037:unable to obtain file status

Linux-x86_64Error: 2: No such file or directory

Additionalinformation: 3

 

3、使用BBED修改4号文件头上的SCN号,使他和其他数据文件一致,然后再打开数据库

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

 

BBED:Release 2.0.0.0.0 - Limited Production on 星期一 8月12 21:50:52 2013

 

Copyright(c) 1982, 2007, Oracle.  All rightsreserved.

 

*************!!! For Oracle Internal Use only !!! ***************

 

BBED> p dba 4,1 kcvfhckp

structkcvfhckp, 36 bytes                    @484    

   struct kcvcpscn, 8 bytes                 @484    

      ub4 kscnbas                           @484      0x001508cf

      ub2 kscnwrp                           @488      0x0000

   ub4 kcvcptim                             @492      0x31124233

   ub2 kcvcpthr                             @496      0x0001

   union u, 12 bytes                        @500    

      struct kcvcprba, 12 bytes             @500    

         ub4 kcrbaseq                       @500      0x00000036

         ub4 kcrbabno                       @504      0x00000002

         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> p dba 2,1 kcvfhckp

structkcvfhckp, 36 bytes                    @484    

   struct kcvcpscn, 8 bytes                 @484    

      ub4kscnbas                            @484      0x0016bf54

      ub2 kscnwrp                           @488      0x0000

   ub4 kcvcptim                             @492      0x3112838f

   ub2 kcvcpthr                             @496      0x0001

   union u, 12 bytes                        @500    

      struct kcvcprba, 12 bytes             @500    

         ub4 kcrbaseq                       @500      0x0000003c

         ub4 kcrbabno                       @504      0x00000002

         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> p dba 3,1kcvfhckp

struct kcvfhckp, 36 bytes                   @484    

   struct kcvcpscn, 8 bytes                 @484    

      ub4kscnbas                            @484      0x0016bf54

      ub2 kscnwrp                           @488      0x0000

   ub4 kcvcptim                             @492      0x3112838f

   ub2 kcvcpthr                             @496      0x0001

   union u, 12 bytes                        @500    

      struct kcvcprba, 12 bytes             @500    

         ub4 kcrbaseq                       @500      0x0000003c

         ub4 kcrbabno                       @504      0x00000002

         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

 

   可以看到4号文件SCN号所在位置

                   ub4kscnbas                          @484      0x001508cf

   与2和3两个数据文件的SCN是不一样的

                   ub4kscnbas                          @484      0x0016bf54

                   ub4kscnbas                          @484      0x0016bf54

                  

4、修改4号文件的SCN使其和其他数据文件一致

         总共修改了三个地方:

              ub4 kscnbas                           @484      0x0016bf54

              ub4 kcvcptim                          @492      0x3112838f

              ub4 kcrbaseq                          @500      0x0000003c

 

 BBED> d /v dba 3,1 offset 484 count 10

 File:/u02/app/oracle/oradata/ora10g/sysaux01.dbf (3)

 Block: 1      Offsets:  484 to  493 Dba:0x00c00001

-------------------------------------------------------

 54bf1600 00001e22 8f83              l T......"..

 <16 bytes per line>

 

BBED> d /v dba 4,1 offset484 count 10

 File:/u02/app/oracle/oradata/ora10g/users01.dbf (4)

 Block: 1      Offsets:  484 to  493 Dba:0x01000001

-------------------------------------------------------

 cf081500 00000000 3342              l ........3B

 <16 bytes per line>

 

BBED> m /x 54bf1600 dba4,1 offset 484

Warning:contents of previous BIFILE will be lost. Proceed? (Y/N) Y

 File:/u02/app/oracle/oradata/ora10g/users01.dbf (4)

 Block: 1                Offsets:  484 to 493           Dba:0x01000001

------------------------------------------------------------------------

 54bf1600 00000000 3342

 <32 bytes per line>

 

BBED> d /v dba 4,1offset 484 count 10

 File:/u02/app/oracle/oradata/ora10g/users01.dbf (4)

 Block: 1      Offsets:  484 to  493 Dba:0x01000001

-------------------------------------------------------

 54bf1600 00000000 3342              l T.......3B

 <16 bytes per line>

 

BBED> d /v dba 3,1offset 484 count 10

 File:/u02/app/oracle/oradata/ora10g/sysaux01.dbf (3)

 Block: 1      Offsets:  484 to  493 Dba:0x00c00001

-------------------------------------------------------

 54bf1600 00001e22 8f83              l T......"..

 <16 bytes per line>

 

需要修改的地方还有:

    
ub4 kcvcptim                             @492      0x3112838f

BBED> m /x 8f83 dba 4,1 offset 492

Warning: contents ofprevious BIFILE will be lost. Proceed? (Y/N) Y

 File: /u02/app/oracle/oradata/ora10g/users01.dbf(4)

 Block: 1                Offsets:  492 to 501           Dba:0x01000001

------------------------------------------------------------------------

 8f831231 01000000 3600

 <32 bytes per line>

 

    ub4 kcrbaseq                       @500      0x0000003c

BBED> m /x 3c00 dba 4,1 offset 500

 File:/u02/app/oracle/oradata/ora10g/users01.dbf (4)

 Block: 1                Offsets:  500 to 509           Dba:0x01000001

------------------------------------------------------------------------

 3c000000 02000000 1000

 

 <32 bytes per line>

 

BBED> sum apply

Check value for File3, Block 1:

current = 0x2f20,required = 0x2f20

BBED> exit

 

4、查看数据文件SCN号

SQL> select name,checkpoint_change# fromv$datafile_header;

 

NAME                                                CHECKPOINT_CHANGE#

---------------------------------------------------------------

/u02/app/oracle/oradata/ora10g/system01.dbf         1490772

/u02/app/oracle/oradata/ora10g/undotbs01.dbf        1490772

/u02/app/oracle/oradata/ora10g/sysaux01.dbf         1490772

/u02/app/oracle/oradata/ora10g/users01.dbf          1490772

 

SQL> alter database open;

alter database open

*

ERRORat line 1:

ORA-01113:file 4 needs media recovery if it was restored from backup, or END

BACKUPif it was not

ORA-01110:data file 4: '/u02/app/oracle/oradata/ora10g/users01.dbf'

SQL>recover datafile 4;

Mediarecovery complete.

SQL> alter database open;

Databasealtered.

SQL>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: