说明:热备归档模式
1.准备环境:RMAN全库备份
RMAN> backup as compressed backupset full database;
Starting backup at 02-OCT-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/ORA11GR2/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf
channel ORA_DISK_1: starting piece 1 at 02-OCT-16
channel ORA_DISK_1: finished piece 1 at 02-OCT-16
piece handle=/u01/app/FRA/ORA11GR2/backupset/2016_10_02/o1_mf_nnndf_TAG20161002T130833_cz15lkxy_.bkp tag=TAG20161002T130833 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 02-OCT-16
channel ORA_DISK_1: finished piece 1 at 02-OCT-16
piece handle=/u01/app/FRA/ORA11GR2/backupset/2016_10_02/o1_mf_ncsnf_TAG20161002T130833_cz15nb28_.bkp tag=TAG20161002T130833 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 02-OCT-16
2.模拟建表:
SYS@ORA11GR2>create table scott.t1 as select 1 as id from dual;
Table created.
SYS@ORA11GR2>alter system archive log current;(强制日志归档)
System altered.
SYS@ORA11GR2>create table scott.t2 as select 2 as id from dual;
Table created.
SYS@ORA11GR2>alter system archive log current;(强制日志归档)
System altered.
SYS@ORA11GR2>create table scott.t3 as select 3 as id from dual;
Table created.
SYS@ORA11GR2>alter system archive log current;(强制日志归档)
System altered.
SYS@ORA11GR2>select table_name,tablespace_name from dba_tables where owner='SCOTT' AND table_name LIKE 'T_';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
T1 USERS
T2 USERS
T3 USERS
3.删除所有日志文件(因为已经完成归档了,所以可以删除在线日志文件)
SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/
control01.ctl redo01.log sysaux01.dbf ts_xxf_01.dbf
control02.ctl redo02.log system01.dbf undotbs01.dbf
example01.dbf redo03.log temp01.dbf users01.dbf
SYS@ORA11GR2>!rm /u01/app/oracle/oradata/ORA11GR2/*.log
SYS@ORA11GR2>!ls /u01/app/oracle/oradata/ORA11GR2/*.log
ls: /u01/app/oracle/oradata/ORA11GR2/*.log: No such file or directory
(丢失了在线日志,操作有关写日志的动作就会出错)
4.数据库启动到mount模式
SYS@ORA11GR2>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@ORA11GR2>
SYS@ORA11GR2>startup mount; (进行恢复操作)
ORACLE instance started.
Total System Global Area 830930944 bytes
Fixed Size 2257800 bytes
Variable Size 503319672 bytes
Database Buffers 322961408 bytes
Redo Buffers 2392064 bytes
Database mounted.
5.RMAN还原数据库
RMAN> restore database;(重储)
Starting restore at 02-OCT-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel 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 /u01/app/oracle/oradata/ORA11GR2/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/ORA11GR2/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/ORA11GR2/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/ORA11GR2/ts_xxf_01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/FRA/ORA11GR2/backupset/2016_10_02/o1_mf_nnndf_TAG20161002T130833_cz15lkxy_.bkp
channel ORA_DISK_1: piece handle=/u01/app/FRA/ORA11GR2/backupset/2016_10_02/o1_mf_nnndf_TAG20161002T130833_cz15lkxy_.bkp tag=TAG20161002T130833
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 02-OCT-16
6.SYS下基于cancel恢复(能恢复到哪就恢复到哪)
SYS@ORA11GR2>select status from v$instance;
STATUS
------------
MOUNTED
SYS@ORA11GR2>recover database until cancel;
ORA-00279: change 1212655 generated at 10/02/2016 13:08:33 needed for thread 1
ORA-00289: suggestion :/u01/app/FRA/ORA11GR2/archivelog/2016_10_02/o1_mf_1_1_cz15s2l0_.arc
ORA-00280: change 1212655 for thread 1 is in sequence #1
Specify log: {=suggested | filename | AUTO | CANCEL}
ORA-00279: change 1212939 generated at 10/02/2016 13:12:02 needed for thread 1
ORA-00289: suggestion : /u01/app/FRA/ORA11GR2/archivelog/2016_10_02/o1_mf_1_2_cz15sz68_.arc
ORA-00280: change 1212939 for thread 1 is in sequence #2
ORA-00278: log file '/u01/app/FRA/ORA11GR2/archivelog/2016_10_02/o1_mf_1_1_cz15s2l0_.arc' no longer needed for this recovery
Specify log: {=suggested | filename | AUTO | CANCEL}
ORA-00279: change 1212969 generated at 10/02/2016 13:12:31 needed for thread 1
ORA-00289: suggestion :/u01/app/FRA/ORA11GR2/archivelog/2016_10_02/o1_mf_1_3_cz15ttts_.arc
ORA-00280: change 1212969 for thread 1 is in sequence #3
ORA-00278: log file '/u01/app/FRA/ORA11GR2/archivelog/2016_10_02/o1_mf_1_2_cz15sz68_.arc' no longer needed for this recovery
Specify log: {=suggested | filename | AUTO | CANCEL}
cancel (到第三个归档日志时执行了cancel)
Media recovery cancelled.
——打开数据库(resetlogss方式,即不完全恢复)
SYS@ORA11GR2>alter database open resetlogs;
Database altered.
——验证:
SYS@ORA11GR2>select table_name,tablespace_name from dba_tables where owner='SCOTT' and table_name like 'T_';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
T1 USERS
T2 USERS
(表t3没有恢复回来)
注:应用了两个归档日志,第三个归档日志cancel了,从结果中也可以看到,恢复以后的数据库中,只存在T1,T2两张表,它们俩的重做日志就在前两个归档中,T3表的所有重做条目都在第三个归档中,由于采取了cancel,所以,T3表并未恢复!!!!!!!
alert.txt