1.准备环境:RMAN全库备份
[oracle@host01 ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Dec 21 12:17:40 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD1 (DBID=2148633869)
RMAN> backup as compressed backupset full database;
Starting backup at 21-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=44 device type=DISK
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/PROD1/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD1/ts_setnew01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 21-DEC-16
channel ORA_DISK_1: finished piece 1 at 21-DEC-16
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_21/o1_mf_nnndf_TAG20161221T121754_d5n0mlnf_.bkp tag=TAG20161221T121754 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 21-DEC-16
Starting Control File and SPFILE Autobackup at 21-DEC-16
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_21/o1_mf_s_931177119_d5n0nzqm_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 21-DEC-16
2.模拟建表
SYS@PROD1>create table scott.t1 as select 1 as id from dual;
Table created.
强制日志归档
SYS@PROD1>alter system archive log current;
System altered.
SYS@PROD1>create table scott.t2 as select 2 as id from dual;
Table created.
强制日志归档
SYS@PROD1>alter system archive log current;
System altered.
SYS@PROD1>create table scott.t3 as select 3 as id from dual;
Table created.
强制日志归档
SYS@PROD1>alter system archive log current;
System altered.
SYS@PROD1>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@PROD1>! ls /u01/app/oracle/oradata/PROD1/redo*
/u01/app/oracle/oradata/PROD1/redo01.log /u01/app/oracle/oradata/PROD1/redo03.log
/u01/app/oracle/oradata/PROD1/redo02.log
SYS@PROD1>! rm /u01/app/oracle/oradata/PROD1/redo*
SYS@PROD1>! ls /u01/app/oracle/oradata/PROD1/redo*
ls: /u01/app/oracle/oradata/PROD1/redo*: No such file or directory
4.数据库启动到mount模式
SYS@PROD1>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@PROD1>startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 520096848 bytes
Database Buffers 310378496 bytes
Redo Buffers 2371584 bytes
Database mounted.
5.RMAN还原数据库
[oracle@host01 ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Dec 21 14:33:02 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD1 (DBID=2148633869, not open)
RMAN> restore database;
Starting restore at 21-DEC-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/PROD1/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/PROD1/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD1/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD1/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD1/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/ts_setnew01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_21/o1_mf_nnndf_TAG20161221T121754_d5n0mlnf_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_21/o1_mf_nnndf_TAG20161221T121754_d5n0mlnf_.bkp tag=TAG20161221T121754
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 21-DEC-16
6.SYS下基于cancel恢复(能恢复到哪就恢复到哪)
SYS@PROD1>select status from v$instance;
STATUS
------------
MOUNTED
SYS@PROD1>recover database until cancel;
ORA-00279: change 1120715 generated at 12/21/2016 12:17:54 needed for thread 1
ORA-00289: suggestion : /u01/app/backup/1_1_931176397.dbf
ORA-00280: change 1120715 for thread 1 is in sequence #1
Specify log: {=suggested | filename | AUTO | CANCEL}
ORA-00279: change 1122465 generated at 12/21/2016 14:25:07 needed for thread 1
ORA-00289: suggestion : /u01/app/backup/1_2_931176397.dbf
ORA-00280: change 1122465 for thread 1 is in sequence #2
ORA-00278: log file '/u01/app/backup/1_1_931176397.dbf' no longer needed for
this recovery
Specify log: {=suggested | filename | AUTO | CANCEL}
ORA-00279: change 1122485 generated at 12/21/2016 14:25:24 needed for thread 1
ORA-00289: suggestion : /u01/app/backup/1_3_931176397.dbf
ORA-00280: change 1122485 for thread 1 is in sequence #3
ORA-00278: log file '/u01/app/backup/1_2_931176397.dbf' no longer needed for
this recovery
Specify log: {=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
open resetlogs 方式打开数据库
SYS@PROD1>alter database open resetlogs;
Database altered.
SYS@PROD1>select table_name,tablespace_name from dba_tables where owner='SCOTT' and table_name like 'T_';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
T1 USERS
T2 USERS
注意:应用了两个归档日志,第三个归档日志cancel了,从结果中也可以看到,恢复以后的数据库中,只
存在T1,T2两张表,它们俩的重做日志就在前两个归档中,T3表的所有重做条目都在第三个归档中,
由于采取了cancel,所以,T3表并未恢复。
[oracle@host01 ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Dec 21 12:17:40 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD1 (DBID=2148633869)
RMAN> backup as compressed backupset full database;
Starting backup at 21-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=44 device type=DISK
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/PROD1/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD1/ts_setnew01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 21-DEC-16
channel ORA_DISK_1: finished piece 1 at 21-DEC-16
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_21/o1_mf_nnndf_TAG20161221T121754_d5n0mlnf_.bkp tag=TAG20161221T121754 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
Finished backup at 21-DEC-16
Starting Control File and SPFILE Autobackup at 21-DEC-16
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_21/o1_mf_s_931177119_d5n0nzqm_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 21-DEC-16
2.模拟建表
SYS@PROD1>create table scott.t1 as select 1 as id from dual;
Table created.
强制日志归档
SYS@PROD1>alter system archive log current;
System altered.
SYS@PROD1>create table scott.t2 as select 2 as id from dual;
Table created.
强制日志归档
SYS@PROD1>alter system archive log current;
System altered.
SYS@PROD1>create table scott.t3 as select 3 as id from dual;
Table created.
强制日志归档
SYS@PROD1>alter system archive log current;
System altered.
SYS@PROD1>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@PROD1>! ls /u01/app/oracle/oradata/PROD1/redo*
/u01/app/oracle/oradata/PROD1/redo01.log /u01/app/oracle/oradata/PROD1/redo03.log
/u01/app/oracle/oradata/PROD1/redo02.log
SYS@PROD1>! rm /u01/app/oracle/oradata/PROD1/redo*
SYS@PROD1>! ls /u01/app/oracle/oradata/PROD1/redo*
ls: /u01/app/oracle/oradata/PROD1/redo*: No such file or directory
4.数据库启动到mount模式
SYS@PROD1>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@PROD1>startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 520096848 bytes
Database Buffers 310378496 bytes
Redo Buffers 2371584 bytes
Database mounted.
5.RMAN还原数据库
[oracle@host01 ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Dec 21 14:33:02 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD1 (DBID=2148633869, not open)
RMAN> restore database;
Starting restore at 21-DEC-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/PROD1/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/PROD1/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD1/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD1/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD1/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/PROD1/ts_setnew01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_21/o1_mf_nnndf_TAG20161221T121754_d5n0mlnf_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_21/o1_mf_nnndf_TAG20161221T121754_d5n0mlnf_.bkp tag=TAG20161221T121754
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 21-DEC-16
6.SYS下基于cancel恢复(能恢复到哪就恢复到哪)
SYS@PROD1>select status from v$instance;
STATUS
------------
MOUNTED
SYS@PROD1>recover database until cancel;
ORA-00279: change 1120715 generated at 12/21/2016 12:17:54 needed for thread 1
ORA-00289: suggestion : /u01/app/backup/1_1_931176397.dbf
ORA-00280: change 1120715 for thread 1 is in sequence #1
Specify log: {=suggested | filename | AUTO | CANCEL}
ORA-00279: change 1122465 generated at 12/21/2016 14:25:07 needed for thread 1
ORA-00289: suggestion : /u01/app/backup/1_2_931176397.dbf
ORA-00280: change 1122465 for thread 1 is in sequence #2
ORA-00278: log file '/u01/app/backup/1_1_931176397.dbf' no longer needed for
this recovery
Specify log: {=suggested | filename | AUTO | CANCEL}
ORA-00279: change 1122485 generated at 12/21/2016 14:25:24 needed for thread 1
ORA-00289: suggestion : /u01/app/backup/1_3_931176397.dbf
ORA-00280: change 1122485 for thread 1 is in sequence #3
ORA-00278: log file '/u01/app/backup/1_2_931176397.dbf' no longer needed for
this recovery
Specify log: {=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
open resetlogs 方式打开数据库
SYS@PROD1>alter database open resetlogs;
Database altered.
SYS@PROD1>select table_name,tablespace_name from dba_tables where owner='SCOTT' and table_name like 'T_';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
T1 USERS
T2 USERS
注意:应用了两个归档日志,第三个归档日志cancel了,从结果中也可以看到,恢复以后的数据库中,只
存在T1,T2两张表,它们俩的重做日志就在前两个归档中,T3表的所有重做条目都在第三个归档中,
由于采取了cancel,所以,T3表并未恢复。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31400681/viewspace-2131133/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31400681/viewspace-2131133/