当进行不完全恢复后,可能没达到恢复的要求,这个时候数据库已经被resetlogs方式打开过了,如果在进行不完全恢复前没有对数据库进行全库备份,这个时候又想恢复上一个incarnation的某些数据,在这种场景下就需要进行incarnation穿越,下面来演示下这个场景!
一:准备实验基础数据
SQL> create table t043_incarnation(a varchar2(20)) tablespace example;
Table created.
SQL> insert into t043_incarnation values ('corss
1 row created.
SQL> commit;
Commit complete.
SQL> create table t043_other (a number) tablespace example;
Table created.
SQL> insert into t043_other values (1);
1 row created.
SQL> insert into t043_other values (2);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> insert into t043_other values (3);
1 row created.
SQL> alter system switch logfile;
System altered.
SQL> select sysdate from dual;
SYSDATE
-------------------
2011-07-17-21:22:30
SQL> truncate table t043_incarnation;
Table truncated.
SQL> archive log list;
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
SQL> insert into t043_other values (4);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> insert into t043_other values (5);
1 row created.
SQL> alter system switch logfile;
System altered.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
二:删除全部控制文件第67号归档日志文件,这样进行恢复的时候就必须进行不完全恢复
[oracle@rhel6 2011_07_17]$ pwd
/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17
[oracle@rhel6 2011_07_17]$ rm -i o1_mf_1_67_725rmcx1_.arc
rm: remove regular file `o1_mf_1_67_725rmcx1_.arc'? y
[oracle@rhel6 2011_07_17]$ rm -rf /u01/app/oradata/ora10g/control0*
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
ORA-00205: error in identifying control file, check alert log for more info
三:使用控制文件二进制自动备份进行恢复,也可以使用trace脚本,由于归档日志丢失的原因,都需要进行不完全恢复
RMAN> restore controlfile from autobackup;
Starting restore at 2011-07-17-21:28:29
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=154 devtype=DISK
recovery area destination: /u01/app/flash_recovery_area
database name (or database unique name) used for search: ORA10G
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /u01/app/flash_recovery_area/ORA10G/autobackup/2011_07_17/o1_mf_s_756768121_725rhvkf_.bkp
channel ORA_DISK_1: control file restore from autobackup complete
output filename=/u01/app/oradata/ora10g/control01.ctl
output filename=/u01/app/oradata/ora10g/control02.ctl
output filename=/u01/app/oradata/ora10g/control03.ctl
Finished restore at 2011-07-17-21:28:34
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> list incarnation;
List of Database Incarnations
DB Key
------- ------- -------- ---------------- --- ---------- ----------
1
2
3
4
RMAN> restore database;
Starting restore at 2011-07-17-21:29:21
Starting implicit crosscheck backup at 2011-07-17-21:29:21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=154 devtype=DISK
Crosschecked 1 objects
——————————其他输出省略——————————
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 9022073 generated at 07/17/2011 21:20:26 needed for thread 1
ORA-00289: suggestion :
/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17/o1_mf_1_64_%u_.arc
ORA-00280: change 9022073 for thread 1 is in sequence #64
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 9022129 generated at 07/17/2011 21:21:35 needed for thread 1
ORA-00289: suggestion :
/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17/o1_mf_1_65_%u_.arc
ORA-00280: change 9022129 for thread 1 is in sequence #65
ORA-00278: log file
'/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17/o1_mf_1_64_725rh0wy_.
arc' no longer needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 9022148 generated at 07/17/2011 21:22:01 needed for thread 1
ORA-00289: suggestion :
/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17/o1_mf_1_66_%u_.arc
ORA-00280: change 9022148 for thread 1 is in sequence #66
ORA-00278: log file
'/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17/o1_mf_1_65_725rhtt9_.
arc' no longer needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 9022403 generated at 07/17/2011 21:23:46 needed for thread 1
ORA-00289: suggestion :
/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17/o1_mf_1_67_%u_.arc
ORA-00280: change 9022403 for thread 1 is in sequence #67
ORA-00278: log file
'/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17/o1_mf_1_66_725rm33n_.
arc' no longer needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00308: cannot open archived log
'/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17/o1_mf_1_67_%u_.arc'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 9022403 generated at 07/17/2011 21:23:46 needed for thread 1
ORA-00289: suggestion :
/u01/app/flash_recovery_area/ORA10G/archivelog/2011_07_17/o1_mf_1_67_%u_.arc
ORA-00280: change 9022403 for thread 1 is in sequence #67
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
四:恢复完后打开数据库,发现之前被truncate的表没有被成功恢复,这个时候就需要进行incarnation穿越
SQL> alter database open resetlogs;
Database altered.
SQL> select * from t043_other;
A
----------
1
2
3
4
SQL> select * from t043_incarnation;
no rows selected
五:关闭数据库后将数据库启动在mount状态,利用rman进行incarnation穿越,恢复t043_incarnation表
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
Database mounted.
[oracle@rhel6 ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Jul 17 21:34:14 2011
Copyright (c) 1982, 2005, Oracle.
connected to target database: ORA10G (DBID=4061806388)
RMAN> list incarnation;
using target database control file instead of recovery catalog
List of Database Incarnations
DB Key
------- ------- -------- ---------------- --- ---------- ----------
1
2
3
4
5
RMAN> reset database to incarnation 4;
database reset to incarnation 4
RMAN> list incarnation;
List of Database Incarnations
DB Key
------- ------- -------- ---------------- --- ---------- ----------
1
2
3
4
5
RMAN> run {
2> set until time '2011-07-17-21:22:30';
3> restore database;
4> recover database;
5> }
RMAN> alter database open resetlogs;
database opened
SQL> select * from t043_incarnation;
A
------------------------------------------------------------
corss
SQL> select * from t043_other;
A
----------
1
2
总结:穿越incarnation后,将会产生孤儿incarnation(orphan),这个时候最好重新备份下数据库