近日有客户提到了这个有趣的问题,为此做了个Test Case研究了下:

测试控制文件的时间点恢复。
1、恢复到控制文件备份时间点之前
2、恢复到控制文件备份时间点之后
3、恢复到控制文件备份时间点的sequence#

步骤1:环境准备

[oracle@adg ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Aug 7 13:07:33 2017

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> archive log list;  
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence     13
Next log sequence to archive   15
Current log sequence           15
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@adg ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 – Production on Mon Aug 7 13:07:48 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ADGPRI (DBID=1362425892)

RMAN> backup database plus archivelog;


Starting backup at 07-AUG-17
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=55 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=5 RECID=1 STAMP=919155285
input archived log thread=1 sequence=6 RECID=2 STAMP=919155719
input archived log thread=1 sequence=7 RECID=3 STAMP=919155989
input archived log thread=1 sequence=8 RECID=4 STAMP=919156172
input archived log thread=1 sequence=9 RECID=5 STAMP=919156175
input archived log thread=1 sequence=10 RECID=6 STAMP=919156178
input archived log thread=1 sequence=11 RECID=7 STAMP=919156515
input archived log thread=1 sequence=12 RECID=9 STAMP=919156518
input archived log thread=1 sequence=13 RECID=17 STAMP=919156585
input archived log thread=1 sequence=14 RECID=18 STAMP=951396680
input archived log thread=1 sequence=15 RECID=19 STAMP=951397676
channel ORA_DISK_1: starting piece 1 at 07-AUG-17
channel ORA_DISK_1: finished piece 1 at 07-AUG-17
piece handle=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/0bsbab9d_1_1 tag=TAG20170807T130757 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 07-AUG-17

Starting backup at 07-AUG-17
using channel ORA_DISK_1
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=/home/oracle/app/oracle/oradata/adgpri/system01.dbf
input datafile file number=00002 name=/home/oracle/app/oracle/oradata/adgpri/sysaux01.dbf
input datafile file number=00003 name=/home/oracle/app/oracle/oradata/adgpri/undotbs01.dbf
input datafile file number=00004 name=/home/oracle/app/oracle/oradata/adgpri/users01.dbf
channel ORA_DISK_1: starting piece 1 at 07-AUG-17
channel ORA_DISK_1: finished piece 1 at 07-AUG-17
piece handle=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/0csbab9h_1_1 tag=TAG20170807T130801 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:45
channel ORA_DISK_1: starting 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 07-AUG-17
channel ORA_DISK_1: finished piece 1 at 07-AUG-17
piece handle=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/0dsbabcq_1_1 tag=TAG20170807T130801 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-AUG-17

Starting backup at 07-AUG-17
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=16 RECID=20 STAMP=951397790
channel ORA_DISK_1: starting piece 1 at 07-AUG-17
channel ORA_DISK_1: finished piece 1 at 07-AUG-17
piece handle=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/0esbabcu_1_1 tag=TAG20170807T130950 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-AUG-17

RMAN> list backup of controlfile;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
3       Full    9.36M      DISK        00:00:04     07-AUG-17      《===========================这里看不出控制文件备份的准确时间点,稍后通过v$backup_set查看backupset 3的创建时间点可得到
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20170807T130801
        Piece Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/0dsbabcq_1_1
  Control File Included: Ckp SCN: 992988       Ckp time: 07-AUG-17

RMAN> exit


Recovery Manager complete.
[oracle@adg ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Aug 7 13:11:38 2017

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence     15
Next log sequence to archive   17
Current log sequence           17
SQL> 
SQL> select sequence#,to_char(first_time,’yyyy-mm-dd hh24:mi:ss’), to_char(next_time,’yyyy-mm-dd hh24:mi:ss’) from v$archived_log;

 SEQUENCE# TO_CHAR(FIRST_TIME, TO_CHAR(NEXT_TIME,’
———- ——————- ——————-
         5 2016-08-06 07:05:28 2016-08-06 08:54:45
         6 2016-08-06 08:54:45 2016-08-06 09:01:59
         7 2016-08-06 09:01:59 2016-08-06 09:06:29
         8 2016-08-06 09:06:29 2016-08-06 09:09:32
         9 2016-08-06 09:09:32 2016-08-06 09:09:35
        10 2016-08-06 09:09:35 2016-08-06 09:09:38
        11 2016-08-06 09:09:38 2016-08-06 09:15:14
         6 2016-08-06 08:54:45 2016-08-06 09:01:59
        12 2016-08-06 09:15:14 2016-08-06 09:15:18
        12 2016-08-06 09:15:14 2016-08-06 09:15:18
         7 2016-08-06 09:01:59 2016-08-06 09:06:29

 SEQUENCE# TO_CHAR(FIRST_TIME, TO_CHAR(NEXT_TIME,’
———- ——————- ——————-
         9 2016-08-06 09:09:32 2016-08-06 09:09:35
        10 2016-08-06 09:09:35 2016-08-06 09:09:38
        11 2016-08-06 09:09:38 2016-08-06 09:15:14
         8 2016-08-06 09:06:29 2016-08-06 09:09:32
        13 2016-08-06 09:15:18 2016-08-06 09:16:24
        13 2016-08-06 09:15:18 2016-08-06 09:16:24
        14 2016-08-06 09:16:24 2017-08-07 12:51:19
        15 2017-08-07 12:51:19 2017-08-07 13:07:56
        16 2017-08-07 13:07:56 2017-08-07 13:09:50

20 rows selected.

SQL> select recid,to_char(start_time,’yyyy-mm-dd hh24:mi:ss’) from v$backup_set;

     RECID TO_CHAR(START_TIME,
———- ——————-
         1 2017-08-07 13:07:57
         2 2017-08-07 13:08:01
         3 2017-08-07 13:09:46《=============控制文件备份创建时间点,显然是在16号归档日志范围内.
         4 2017-08-07 13:09:50

步骤2:恢复到控制文件备份时间点之前
由于恢复过程只能前滚不能回滚(回滚是闪回的功能),所以无法使用控制文件备份,而根据ASk Tom的帖子,snapshot controlfile是个“精简版”的控制文件,只能用于无备份可恢复的情况,且完全恢复需要用snapshot controlfile创建之后的所有归档:
ASM tom的帖子:

3)In case of failure can we make use of snapshot controlfile to restore database from past backup? 

3) Yes. For example, from MOS note 372996.1, we describe an example where “everything” is lost – one of the options is 

“If no controlfile backup available it may be also an option to restore CONTROLFILE from a SNAPSHOT CONTROLFILE if available” 

测试过程:
[oracle@adg ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 – Production on Mon Aug 7 13:12:31 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ADGPRI (DBID=1362425892)

RMAN> run{
2> set until sequence 14;
3> restore controlfile preview;
4> }

executing command: SET until clause

Starting restore at 07-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=48 device type=DISK

List of Control File Copies
===========================

Key     S Completion Time Ckp SCN    Ckp Time       
——- – ————— ———- —————
2       A 06-AUG-16       969402     06-AUG-16      
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_adgpri.f
        Tag: TAG20160806T090132

using channel ORA_DISK_1

List of Archived Log Copies for database with db_unique_name ADGPRI
=====================================================================

Key     Thrd Seq     S Low Time 
——- —- ——- – ———
2       1    6       A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_6_919148645.dbf

3       1    7       A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_919148645.dbf

4       1    8       A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_8_919148645.dbf

5       1    9       A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_9_919148645.dbf

6       1    10      A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_10_919148645.dbf

7       1    11      A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_11_919148645.dbf

9       1    12      A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_12_919148645.dbf

17      1    13      A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_13_919148645.dbf

Media recovery start SCN is 969402
Recovery must be done beyond SCN 969402 to clear datafile fuzziness
Finished restore at 07-AUG-17

RMAN> 

步骤3:恢复到备份控制文件之后的时间点
这种情况可以利用控制文件备份
RMAN> run{
2> set until sequence 17;
3> restore controlfile preview;
4> }

executing command: SET until clause

Starting restore at 07-AUG-17
using channel ORA_DISK_1


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
3       Full    9.36M      DISK        00:00:04     07-AUG-17      
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20170807T130801
        Piece Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/0dsbabcq_1_1
  Control File Included: Ckp SCN: 992988       Ckp time: 07-AUG-17

List of Archived Log Copies for database with db_unique_name ADGPRI
=====================================================================

Key     Thrd Seq     S Low Time 
——- —- ——- – ———
20      1    16      A 07-AUG-17
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_16_919148645.dbf

Media recovery start SCN is 992988
Recovery must be done beyond SCN 992988 to clear datafile fuzziness
Finished restore at 07-AUG-17


步骤4:恢复到备份控制文件时间点的sequence#
这种情况比较特殊,但可以想明白为什么没走控制文件备份:因为archivelog sequence# 16对于控制文件备份来讲是当前redo而不是归档日志,其信息注册进了controlfile backup里却又不完整(没有END_OF_REDO,v$archived_log.END_OF_REDO),用它recover会导致后续的archivelog无法接续应用。
RMAN> run{
2> set until sequence 16;
3>  restore controlfile preview;
4> }

executing command: SET until clause

Starting restore at 07-AUG-17
using channel ORA_DISK_1

List of Control File Copies
===========================

Key     S Completion Time Ckp SCN    Ckp Time       
——- – ————— ———- —————
2       A 06-AUG-16       969402     06-AUG-16      
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_adgpri.f
        Tag: TAG20160806T090132


List of Archived Log Copies for database with db_unique_name ADGPRI
=====================================================================

Key     Thrd Seq     S Low Time 
——- —- ——- – ———
2       1    6       A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_6_919148645.dbf

3       1    7       A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_919148645.dbf

4       1    8       A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_8_919148645.dbf

5       1    9       A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_9_919148645.dbf

6       1    10      A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_10_919148645.dbf

7       1    11      A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_11_919148645.dbf

9       1    12      A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_12_919148645.dbf

17      1    13      A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_13_919148645.dbf

18      1    14      A 06-AUG-16
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_14_919148645.dbf

19      1    15      A 07-AUG-17
        Name: /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_15_919148645.dbf

Media recovery start SCN is 969402
Recovery must be done beyond SCN 969402 to clear datafile fuzziness
Finished restore at 07-AUG-17

RMAN> exit