本文主要是介绍Oracle RMAN Recover中使用BBED 跳过缺失的归档恢复测试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一.测试场景
cebpm:/home/oracle@cebpm>rman target /Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jan 10 09:10:31 2018Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.connected to target database: CEBPM (DBID=3677012495)RMAN> backup database format '/data/backup/cebpm/fullback/bak_U%';Starting backup at 2018/01/10 09:11:00
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=48 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf
input datafile file number=00002 name=/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf
input datafile file number=00003 name=/data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf
input datafile file number=00005 name=/data/CEBPM/datafile/test01.dbf
input datafile file number=00004 name=/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf
channel ORA_DISK_1: starting piece 1 at 2018/01/10 09:11:02
channel ORA_DISK_1: finished piece 1 at 2018/01/10 09:12:18
piece handle=/data/backup/cebpm/fullback/bak_U% tag=TAG20180110T091102 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:16
Finished backup at 2018/01/10 09:12:18Starting Control File and SPFILE Autobackup at 2018/01/10 09:12:18
piece handle=/data/backup/cebpm/ctlbackup/control_c-3677012495-20180110-01 comment=NONE
Finished Control File and SPFILE Autobackup at 2018/01/10 09:12:20
09:16:01 SQL> create table test (id int,times date);Table created.09:16:15 SQL> insert into test values(1,sysdate);1 row created.09:16:36 SQL> commit;Commit complete.09:16:38 SQL> select sequence# from v$log;SEQUENCE#
----------453
09:17:46 SQL> alter system archive log current;System altered.09:18:29 SQL> select sequence# from v$log;SEQUENCE#
----------45609:18:43 SQL> insert into test values(2,sysdate);1 row created.09:19:08 SQL> commit;Commit complete.09:19:11 SQL> alter system archive log current;System altered.09:19:22 SQL> select sequence# from v$log;SEQUENCE#
----------756
4.删除6的归档 cebpm:/data/CEBPM/archivelog@cebpm>ll
总用量 35132
-rw-r-----. 1 oracle dba 100864 12月 13 11:05 1_125_945593423.arc
-rw-r-----. 1 oracle dba 1024 12月 13 11:05 1_126_945593423.arc
-rw-r-----. 1 oracle dba 284672 12月 13 11:06 1_127_945593423.arc
-rw-r-----. 1 oracle dba 196096 12月 13 11:06 1_129_945593423.arc
-rw-r-----. 1 oracle dba 9365504 1月 5 07:35 1_1_962622394.arc
-rw-r-----. 1 oracle dba 17507328 1月 10 08:17 1_2_962622394.arc
-rw-r-----. 1 oracle dba 6851072 1月 10 08:53 1_3_962622394.arc
-rw-r-----. 1 oracle dba 1241600 1月 10 09:03 1_4_962622394.arc
-rw-r-----. 1 oracle dba 399872 1月 10 09:18 1_5_962622394.arc
-rw-r-----. 1 oracle dba 2048 1月 10 09:19 1_6_962622394.arc
-rw-r-----. 1 oracle dba 2048 1月 10 09:19 1_7_962622394.arc
cebpm:/data/CEBPM/archivelog@cebpm>rm -rf 1_6_962622394.arc
5.然后restore和recover 操作
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
Database mounted.
cebpm:/home/oracle@cebpm>rman target /Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jan 10 09:21:39 2018Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.connected to target database: CEBPM (DBID=3677012495, not open)RMAN> restore database;Starting restore at 2018/01/10 09:21:51
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISKchannel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf
channel ORA_DISK_1: restoring datafile 00002 to /data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf
channel ORA_DISK_1: restoring datafile 00005 to /data/CEBPM/datafile/test01.dbf
channel ORA_DISK_1: reading from backup piece /data/backup/cebpm/fullback/bak_1msoagpe_1_1
channel ORA_DISK_1: piece handle=/data/backup/cebpm/fullback/bak_1msoagpe_1_1 tag=TAG20180110T091317
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 2018/01/10 09:23:07RMAN> recover database;Starting recover at 2018/01/10 09:23:49
using channel ORA_DISK_1starting media recoveryarchived log for thread 1 with sequence 5 is already on disk as file /data/CEBPM/archivelog/1_5_962622394.arc
archived log for thread 1 with sequence 7 is already on disk as file /data/CEBPM/archivelog/1_7_962622394.arc
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/10/2018 09:23:50
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 6 and starting SCN of 1070624 found to restore
这个6是我们刚才手工删掉的归档。如果这个不搞定,后面没办法恢复。
6.BBED 修改SCN
(1)修改原理说明
System Checkpoint SCN:
SQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#
------------------1070928
Datafile CheckpointSCN:
SQL> select name,checkpoint_change# from v$datafile;NAME CHECKPOINT_CHANGE#
------------------------------------------------------------ ------------------
/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf 1070928
/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf 1070928
/data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf 1070928
/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf 1070928
/data/CEBPM/datafile/test01.dbf 1070928
START SCN:
SQL> select name,checkpoint_change# from v$datafile_header;NAME CHECKPOINT_CHANGE#
------------------------------------------------------------ ------------------
/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf 1070427
/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf 1070427
/data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf 1070427
/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf 1070427
/data/CEBPM/datafile/test01.dbf 1070427
在数据库启动过程中,当SystemCheckpoint SCN、Datafile Checkpoint SCN和Start SCN号都相同时,数据库可以正常启动,不需要做media recovery.三者当中有一个不同时,则需要做media recovery。
如果在启动的过程中,EndSCN号为NULL,则需要做instance recovery。ORACLE在启动过程中首先检查是否需要media recovery,然后再检查是否需要instance recovery。
在进行recovery的时候,我们根据归档,推进START SCN,但是归档缺失,导致无法推荐,数据库也无法启动。
我们这里缺失的是6的归档,我们只需要手工的修改datafile header,让数据库认为这个归档已经恢复了,即可。 这是一种欺骗行为,虽然可以继续,但还是会出现问题。
可以使用如下方法确定具体缺失的归档SCN,然后使用BBED 跳过这些SCN 即可
select sequence#,first_change#,next_change# from v$archived_log;SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
---------- ------------- ------------94 886923 88711295 887112 88770196 887701 88778197 887781 88791798 887917 88833699 888336 88844585 882971 88368786 883687 884020102 889538 889754102 889538 889754103 889754 889770SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
---------- ------------- ------------103 889754 889770104 889770 889779104 889770 889779105 889779 889784105 889779 889784106 889784 889806106 889784 889806107 889806 890028107 889806 890028108 890028 894208108 890028 894208SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
---------- ------------- ------------109 894208 894296109 894208 894296110 894296 910788110 894296 910788111 910788 910887111 910788 910887112 910887 934551113 934551 934580112 910887 934551113 934551 934580114 934580 934864SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
---------- ------------- ------------114 934580 934864115 934864 936779116 936779 936788117 936788 939244119 977459 977469118 939244 977459120 977469 986086121 986086 986095122 986095 987949123 987949 987957124 987957 1008998SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
---------- ------------- ------------125 1008998 1009546126 1009546 1009554127 1009554 1010197128 1010197 1010205125 1008998 1009546126 1009546 1009554127 1009554 1010197129 1010205 10107381 1010058 10411702 1041170 10669423 1066942 1069309SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
---------- ------------- ------------4 1069309 10696865 1069686 1070624 6 1070624 10706467 1070646 1070658103 rows selected.
这个正好与我们之前RMAN 错误一致:
archived log for thread 1 with sequence 5 is already on disk as file /data/CEBPM/archivelog/1_5_962622394.arc
archived log for thread 1 with sequence 7 is already on disk as file /data/CEBPM/archivelog/1_7_962622394.arc
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/10/2018 09:23:50
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 6 and starting SCN of 1070624 found to restore
(2)使用BBED 推进所有DATAFILE header SCN
关于BBED安装配置请参考:
http://blog.csdn.net/shiyu1157758655/article/details/56279479
这里,我们只修改kscnbas的值:
kscnbas (at offset 484) - SCN of lastchange to the datafile.
cebpm:/home/oracle@cebpm>bbed parfile=/home/oracle/bbed_parameter.txt
Password: BBED: Release 2.0.0.0.0 - Limited Production on Wed Jan 10 09:44:16 2018Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.************* !!! For Oracle Internal Use only !!! ***************BBED> info File# Name Size(blks)----- ---- ----------1 /data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf 896002 /data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf 768003 /data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf 371204 /data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf 6405 /data/CEBPM/datafile/test01.dbf 1280
我们需要将所有datafile 的SCN从1070624 推到1070646
SQL> select to_char(1070646,'xxxxxxxxx') from dual;TO_CHAR(10
----------105636
因此我们的kscnbas 的新值是:0x00105636。
但是注意,对于little-endian的format,他存储是先存储低位的,因此实际block 存储的是:36561000.
我们需要使用BBED 将所有datafileheader 的@484 的值修改成:36561000。
BBED> d /v dba 1,1 offset 484File: /data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf (1)Block: 1 Offsets: 484 to 995 Dba:0x00400001
-------------------------------------------------------5b551000 00000000 2e438539 01000000 l [U.......C.9....05000000 b9020000 10000000 02000000 l ....1...........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 02004000 504d0e00 00000000 l ......@.PM......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 0217f375 l ..............5cbea959 0e00be60 e9a26afe 9b000000 l \??Y..?`顪t....00000000 00000000 00000000 00000000 l ................00000000 00300000 00000000 003a1817 l .....0.......:..f6ca8655 2395b099 11bffb0e e9010600 l ??#.°..???.a3f10f00 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 3656 dba 1,1 offset 484File: /data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf (1)Block: 1 Offsets: 484 to 995 Dba:0x00400001
------------------------------------------------------------------------36561000 00000000 2e438539 01000000 05000000 b9020000 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 02004000 504d0e00 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 0217f375 5cbea959 0e00be60 e9a26afe 9b000000 00000000 00000000 00000000 00000000 00000000 00300000 00000000 003a1817 f6ca8655 2395b099 11bffb0e e9010600 a3f10f00 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 = 0xf385, required = 0xf385
按照同样的步骤,把剩下的4个datafile都修改
最终结果如下:
SQL> select file#,checkpoint_change#,status from v$datafile_header;FILE# CHECKPOINT_CHANGE# STATUS
---------- ------------------ -------1 1070646 ONLINE2 1070646 ONLINE3 1070646 ONLINE4 1070646 ONLINE5 1070646 ONLINE
这里的datafile 的SCN 都跳过了我们缺失的归档,我们可以继续进行recover了。
(3)重新recover
RMAN> recover database;Starting recover at 2018/01/10 13:09:33
using channel ORA_DISK_1starting media recovery
media recovery failed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/10/2018 13:09:57
ORA-00283: recovery session canceled due to errors
RMAN-11003: failure during parse/execution of SQL statement: alter database recover if neededstart
ORA-00283: recovery session canceled due to errors
ORA-00600: internal error code, arguments: [3020], [3], [34370], [12617282], [], [], [], [], [], [], [], []
ORA-10567: Redo is inconsistent with data block (file# 3, block# 34370, file offset is 281559040 bytes)
ORA-10564: tablespace UNDOTBS1
ORA-01110: data file 3: '/data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf'
ORA-10560: block type 'KTU UNDO BLOCK'
根据官网的说明,我们这是UNDO 表空间恢复无法继续了,详见:
Resolving ORA-600[3020] Raised During Recovery (文档 ID 361172.1)
尝试跳过坏块测试:
RMAN> recover database allow 50 corruption;Starting recover at 2018/01/10 13:10:33
using channel ORA_DISK_1starting media recovery
media recovery complete, elapsed time: 00:00:02Finished recover at 2018/01/10 13:10:36
恢复是没有问题,但是打开是有问题的:
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-01578: ORACLE data block corrupted (file # 3, block # 128)
ORA-01110: data file 3: '/data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf'
Process ID: 7040
Session ID: 21 Serial number: 35
(4)重建UNDO 表空间
这里里面的 3 就是我们的undo 表空间,我们把重新创建一个UNDO 在拉起数据库:
修改pfile:
SQL> create pfile from spfile;
cebpm:/data/CEBPM/archivelog@cebpm>vi /u01/app/oracle/product/11.2.0/db_1/dbs/initcebpm.ora
修改如下:
#*.undo_tablespace='UNDOTBS1'
*.undo_management='MANUAL'
*.rollback_segments='SYSTEM'
利用修改之后的pfile,重启数据库
SQL> startup pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initcebpm.ora';
ORACLE instance started.Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 545259984 bytes
Database Buffers 138412032 bytes
Redo Buffers 3031040 bytes
Database mounted.
Database opened.
删除原来的表空间,创建新的UNDO 表空间
SQL> select tablespace_name from dba_tablespaces;TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
TEST6 rows selected.SQL> select name from v$datafile;NAME
--------------------------------------------------------------------------------
/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf
/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf
/data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf
/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf
/data/CEBPM/datafile/test01.dbfSQL> drop tablespace UNDOTBS1;Tablespace dropped.SQL> create undo tablespace UNDOTBS1 datafile '/data/CEBPM/datafile/undotbs01.dbf' size 100M autoextend on next 32M maxsize unlimited;Tablespace created.
关闭数据库,修改pfile参数,然后用新的pfile创建spfile,在正常启动数据库。
*.undo_tablespace='UNDOTBS1'
#*.undo_management='MANUAL'
#*.rollback_segments='SYSTEM'
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile;File created.SQL> startup
ORACLE instance started.Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
Database mounted.
Database opened.
(5)验证
SQL> col name for a60
SQL> select name,checkpoint_change# from v$datafile;NAME CHECKPOINT_CHANGE#
------------------------------------------------------------ ------------------
/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf 1131748
/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf 1131748
/data/CEBPM/datafile/undotbs01.dbf 1131748
/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf 1131748
/data/CEBPM/datafile/test01.dbf 1131748SQL> select name,checkpoint_change# from v$datafile_header;NAME CHECKPOINT_CHANGE#
------------------------------------------------------------ ------------------
/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf 1131748
/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf 1131748
/data/CEBPM/datafile/undotbs01.dbf 1131748
/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf 1131748
/data/CEBPM/datafile/test01.dbf 1131748SQL> select checkpoint_change# from v$database;CHECKPOINT_CHANGE#
------------------1131748SQL> conn test/test
Connected.
SQL> select * from test;ID TIMES
---------- ---------1 10-JAN-18
如上我们数据库已经正常启动,但是测试表里之前是有2条数据,由于跳过丢失的归档现在只有1条数据。
这篇关于Oracle RMAN Recover中使用BBED 跳过缺失的归档恢复测试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!