您的当前位置:首页正文

Oracle_RMAN增量备份恢复测试记录

2022-05-19 来源:榕意旅游网
RMAN增量恢复测试记录

增量恢复测试记录

1 / 88

RMAN

RMAN增量恢复测试记录

目录

一、概述:....................................................................................................................................... 5

1.1、增量备份的基本概念 ..................................................................................................... 5

1.1.1、概念 ..................................................................................................................... 5 1.1.2、备份策略及恢复 ................................................................................................. 5 1.1.3、增量备份命令 ....................................................................................................... 6

二、备份过程 ................................................................................................................................... 7

2.1、第一次全备份: .............................................................................................................. 7

2.1.1、数据记录 ............................................................................................................... 7 2.1.2、当时的归档日志序列号: ................................................................................... 7 2.1.3、数据库当时的时间: ........................................................................................... 8 2.1.4、备份前的归档日志状态 ....................................................................................... 8 2.1.4、开始第一次全备份 ............................................................................................... 8

2.1.4.1、RMAN 配置选项: ................................................................................... 8 2.1.4.2、开始备份数据库及归档日志: ................................................................ 9 2.1.5、第一次备份完成后的时间: ............................................................................. 11 2.1.6、查看RMAN 备份集 ........................................................................................... 11 2.1.7、测试信息汇总 ..................................................................................................... 13 2.2、第一次增量备份 ............................................................................................................ 14

2.2.1、数据记录: ......................................................................................................... 14 2.2.2、归档日志序列号 ................................................................................................. 14 2.2.3、数据库当时的时间 ............................................................................................. 15 2.2.4、开始第一次增量备份 ......................................................................................... 15 2.2.5、备份后的归档日志状态 ..................................................................................... 17 2.2.6、第一次增量备份后的时间 ................................................................................. 17 2.2.7、查看第一次增量备份后的RMAN 备份集 ....................................................... 17 2.2.8、测试信息汇总 ..................................................................................................... 19 2.3、第二次增量备份 ............................................................................................................ 20

2.3.1、数据记录 ............................................................................................................. 20

2.3.1.1、先插入两条数据 ...................................................................................... 20 2.3.1.2、再插入两条数据: .................................................................................. 21 2.3.1.3、继续插入数据: ...................................................................................... 22 2.3.2、归档日志序列号 ................................................................................................. 23 2.3.3、数据库当时的时间 ............................................................................................. 23 2.3.4、开始第二次增量备份 ......................................................................................... 23 2.3.5、备份后的归档日志序列号 ................................................................................. 25 2.3.6、第二次增量备份后的时间 ................................................................................. 26 2.3.7、查看第二次增量备份RMAN 备份集 ............................................................... 26 2.3.8、第二次增量备份后查询系统的SCN ................................................................. 28 2.3.9、测试信息汇总 ..................................................................................................... 29 3.4、第三次增量备份 ............................................................................................................ 29

3.4.1、数据分布 ............................................................................................................. 29 3.4.2、归档日志序列号 ................................................................................................. 31 3.4.3、数据库当前的时间 ............................................................................................. 32

2 / 88

RMAN增量恢复测试记录

3.4.4、开始第三次增量备份 ......................................................................................... 32 3.4.5、备份后的归档日志序列号 ................................................................................. 34 3.4.6、第三次增量备份后的时间 ................................................................................. 35 3.4.7、查看第三次增量备份的RMAN备份集 ............................................................ 36 3.4.8、测试信息汇总 ..................................................................................................... 38

三、恢复过程 ................................................................................................................................. 39

3.1、进行任意时间点的恢复 ................................................................................................ 39

测试目的: ..................................................................................................................... 39 测试步骤: ..................................................................................................................... 39 3.1.1、模拟故障。 ......................................................................................................... 39 3.1.2、发现故障 ............................................................................................................. 39 3.1.3、恢复参数文件 ..................................................................................................... 40

3.1.3.1、连接RMAN,设置DBID ............................................................................ 40 3.1.3.2、通过Oracle 默认的参数文件启动 ........................................................ 40 3.1.3.3、从第一次全备份中恢复spfile ................................................................ 41 3.1.3.4、重新从恢复后的参数文件启动 .............................................................. 41 3.1.4、恢复控制文件 ..................................................................................................... 42 3.1.5、恢复第二次增量备份时的数据文件 ................................................................. 42 3.1.6、查看数据库的相关SCN ..................................................................................... 43 7、Recover数据库 ......................................................................................................... 46 3.1.8、打开数据库验证数据 ......................................................................................... 47 3.1.9、恢复测试小结 ..................................................................................................... 48 3.2、丢失某个增量备份集的恢复(基于时间点) ............................................................ 48

测试目的: ..................................................................................................................... 48 测试步骤: ..................................................................................................................... 49 3.2.1、恢复控制文件 ..................................................................................................... 49

3.2.1.1、恢复前,确认数据库已经处在nomount状态了 ................................. 49 3.2.1.2、恢复第三次增量备份时的控制文件 ...................................................... 49 3.2.2、恢复第一次全备份时的数据文件 ..................................................................... 50

2.2.2.1、首先,要把数据库启动到mount 状态 ................................................ 50 2.2.2.2、恢复第一次全备时的数据文件 .............................................................. 50 3.2.3、删除第二次增量备份时的数据片,模拟第二次增备损坏 ............................. 51 3.2.4、恢复数据到第三次增量备份时的状态 ............................................................. 52 3.2.5、修复数据库 ......................................................................................................... 53 3.2.6、恢复第一次增量备份后到第二次此增量备份完成这段时间的归档日志。 . 54 3.2.7、再次执行恢复数据库 ......................................................................................... 55 3.2.8、执行备份检查 ..................................................................................................... 56 3.2.9、再次执行恢复数据库 ......................................................................................... 61 3.2.10、打开数据库验证数据 ....................................................................................... 63 3.2.11、恢复测试小结 ................................................................................................... 64 3.3、基于SCN的恢复 ........................................................................................................... 64

测试目的: ..................................................................................................................... 64 测试步骤: ..................................................................................................................... 64 3.3.1、恢复并修复数据库 ............................................................................................. 65

3 / 88

RMAN增量恢复测试记录

3.3.2、验证数据 ............................................................................................................. 68 3.3.3、恢复测试小结 ..................................................................................................... 69 3.4、丢失中间某个增量备份归档日志的恢复(基于SCN) ............................................ 70

测试目的: ..................................................................................................................... 70 测试步骤: ..................................................................................................................... 70 3.4.1、恢复第二次增量备份的控制文件 ..................................................................... 70 3.4.2、删除第一次增量备份的归档日志 ..................................................................... 71 3.4.3、恢复数据文件 ..................................................................................................... 72 3.4.4、恢复数据库到第二次增量备份时的SCN ......................................................... 74 3.4.5、验证数据 ............................................................................................................. 76 3.4.6、恢复测试小结 ..................................................................................................... 77 3.5、基于日志序列号的恢复 ................................................................................................ 77

测试目的: ..................................................................................................................... 77 测试步骤: ..................................................................................................................... 77 3.5.1、恢复第二次增量备份的控制文件 ..................................................................... 77 3.5.2、恢复数据文件 ..................................................................................................... 78 3.5.3、查询恢复时间所对应的归档日志 ..................................................................... 79 3.5.4、按日志序列号恢复归档日志 ............................................................................. 81 3.5.5、按日志序列号恢复数据库 ................................................................................. 82 3.5.6、打开数据库,并验证数据 ................................................................................. 83 3.5.7、恢复测试小结 ..................................................................................................... 83 补充测试: ..................................................................................................................... 83

1)查询归档日志10所对应的时间 ..................................................................... 84 2)恢复并修复数据库 ........................................................................................... 84 3)验证数据 ........................................................................................................... 87

三、测试总结 ......................................................................................................................... 88

4 / 88

RMAN增量恢复测试记录

一、概述:

在rman增量备份中,有差异增量和累积增量的概念,本文主要介绍了在差异备份模式下,如何进行各种方式的恢复,使大家对Oracle RMAN 的差异备份恢复有个基本的了解。由于知识水平的限制,本文的一些推论或说明可能并不完全准确,文中的结论仅供大家进行学习和参考。本文所验证的很多内容,都是很难在互联网上搜索到的,所以在测试过程中保留了各种输出的详细信息,并未对输出信息进行过任何的更改,所以大家也可以从下面的测试和输出信息中发现新的结论。 文档说明:

本文红色字体部分代表是提醒注意的部分;绿色的字体代表是命令;斜体字部分代表的是输出信息的补充说明部分。 1.1、增量备份的基本概念

1.1.1、概念

差异增量:是备份上级及同级备份以来所有变化的数据块,差异增量是默认增量备份方式

累积增量:是备份上级备份以来所有变化的块

因为累积增量是备份上级备份以来所有变化的数据块,所以累积增量需要更多的备份时间,同时需要较小的恢复时间;而差异增量正好相反,它可以备份同级备份以来变化的数据块。所以会减少备份时间,但需要更多的恢复时间.在oracle 9中增量备份需要通过扫描整个数据库的数据块才能知道哪些数据块发生了变化,这是一个代价很大,时间很长的过程,而且由于增量备份形成多个不同的备份集,使恢复变得更加不可靠,所以增量备份在版本9中仍然不被推荐使用;在10g中,增量备份作了很大的改进,不需要再扫描所有数据块就能得知哪些数据块发生变化,从而大大提升备份效率。但这些却以牺牲磁盘i/o为代价,所以在oltp事务系统中还得衡量是否愿意以i/o为代价来保证安全及高可用性。10g还支持增量合并,增量备份可支持7级增量。 1.1.2、备份策略及恢复

以rman多级增量备份来作为备份策略例子:

增量备份都需要一个0级备份来作为基础,0级备份与全备份的区别在于0级可以用来增量恢复,而全备份则不可以。

5 / 88

RMAN增量恢复测试记录

备份策略:

例如:我们对一星期做如下备份策略,如果周六发生数据库故障,那么差异增量只需要使用星期天的0级,星期三的一级,星期四、五的二级就可以恢复,累积增量则需要星期天的0级,星期三的一级、星期五的二级即可进行恢复。

星期 星期天 星期一 星期二 星期三 星期四 星期五 星期六 星期天

1.1.3、增量备份命令

零级备份

backup incremental level 0 database; 一级差异增量

backup incremental level 1 database; 一级累计增量

backup incremental level 1 cumulative database;

差异增量 0级 2级 2级 1级 2级 2级 2级 0级 累积增量 0级 2级 2级 1级 2级 2级 2级 0级 6 / 88

RMAN增量恢复测试记录

二、备份过程

2.1、第一次全备份:

2.1.1、数据记录

说明:以下所有的测试表全部是在user1 用户模式下进行的

SQL> create table name(id number,name varchar(20));

Table created.

SQL> insert into name values(1,'zxk');

1 row created.

SQL> select * from name;

ID NAME ---------- -------------------- 1 zxk

SQL> commit;

Commit complete.

2.1.2、当时的归档日志序列号:

SQL> alter system switch logfile;

System altered.

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled Archive destination f:\\arch Oldest online log sequence 1 Next log sequence to archive 2 Current log sequence 2

7 / 88

RMAN增量恢复测试记录

2.1.3、数据库当时的时间:

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 12:52:23

2.1.4、备份前的归档日志状态

(在这之前做过一次全备份,非增量0级备份,所以下面的归档日志序列号增加了,不过并未更新数据)

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled Archive destination f:\\arch Oldest online log sequence 3 Next log sequence to archive 5 Current log sequence 5

2.1.4、开始第一次全备份

2.1.4.1、RMAN 配置选项:

RMAN> show all;

using target database controlfile instead of recovery catalog RMAN configuration parameters are:

CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'f:\\bak\\ctl-pf\\% d_ctf_bak_%F';

CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET;

8 / 88

RMAN增量恢复测试记录

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT 'f:\\bak\\data\\dt1\\%d_datafile_bak_% U';

CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT 'f:\\bak\\data\\dt2\\%d_datafile_bak_% U';

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'E:\\ORACLE\\PRODUCT\\10.1.0\\DB_1\\DATABASE\\S NCFORCL.ORA'; # default

2.1.4.2、开始备份数据库及归档日志:

RMAN> backup incremental level 0 database plus archivelog;

Starting backup at 15-3月 -12 current log archived

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=1 recid=46 stamp=777991779 channel ORA_DISK_1: starting piece 1 at 15-3月 -12

channel ORA_DISK_2: starting compressed archive log backupset channel ORA_DISK_2: specifying archive log(s) in backup set

input archive log thread=1 sequence=2 recid=47 stamp=777993230 input archive log thread=1 sequence=3 recid=48 stamp=777993432 input archive log thread=1 sequence=4 recid=49 stamp=777993480

channel ORA_DISK_2: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1CN5UFIR_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 channel ORA_DISK_2: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1DN5UFIR_1_1 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:02 channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=5 recid=50 stamp=777993819 channel ORA_DISK_1: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1EN5UFIT_1_1 comment=NONE

9 / 88

RMAN增量恢复测试记录

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 15-3月 -12

Starting backup at 15-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed incremental level 0 datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF

input datafile fno=00006 name=F:\\ORADATA2\\TABLESPACE1.DBF

input datafile fno=00004 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF channel ORA_DISK_1: starting piece 1 at 15-3月 -12

channel ORA_DISK_2: starting compressed incremental level 0 datafile backupset channel ORA_DISK_2: specifying datafile(s) in backupset

input datafile fno=00003 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF

input datafile fno=00005 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DB F

input datafile fno=00002 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DB F

channel ORA_DISK_2: starting piece 1 at 15-3月 -12 channel ORA_DISK_2: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1GN5UFIU_1_1 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:36

channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1FN5UFIU_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:43 Finished backup at 15-3月 -12

Starting backup at 15-3月 -12 current log archived

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=6 recid=51 stamp=777993865

channel ORA_DISK_1: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1HN5UFK9_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 15-3月 -12

Starting Control File and SPFILE Autobackup at 15-3月 -12

10 / 88

RMAN增量恢复测试记录

piece handle=F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-02 comment=NONE Finished Control File and SPFILE Autobackup at 15-3月 -12

RMAN>

2.1.5、第一次备份完成后的时间:

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 13:25:19

2.1.6、查看RMAN 备份集

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

40 2M DISK 00:00:02 15-3月 -12

BP Key: 40 Status: AVAILABLE Compressed: YES Tag: TAG20120315T132339

Piece Name: F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1DN5UFIR_1_1

List of Archived Logs in backup set 40

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 2 630832 15-3月 -12 631802 15-3月 -12 1 3 631802 15-3月 -12 632048 15-3月 -12 1 4 632048 15-3月 -12 632071 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

41 3M DISK 00:00:02 15-3月 -12

BP Key: 41 Status: AVAILABLE Compressed: YES Tag: TAG20120315T132339

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1CN5UFIR_1_1

List of Archived Logs in backup set 41

Thrd Seq Low SCN Low Time Next SCN Next Time

11 / 88

RMAN增量恢复测试记录

---- ------- ---------- ---------- ---------- ---------

1 1 627378 15-3月 -12 630832 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

42 67K DISK 00:00:00 15-3月 -12

BP Key: 42 Status: AVAILABLE Compressed: YES Tag: TAG20120315T132339

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1EN5UFIT_1_1

List of Archived Logs in backup set 42

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 5 632071 15-3月 -12 632247 15-3月 -12

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

43 Incr 0 213M DISK 00:00:31 15-3月 -12

BP Key: 43 Status: AVAILABLE Compressed: YES Tag: TAG20120315T132342

Piece Name: F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1GN5UFIU_1_1 List of Datafiles in backup set 43

File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ----

2 0 Incr 632252 15-3月 -12

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOT BS01.DBF

3 0 Incr 632252 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAU X01.DBF

5 0 Incr 632252 15-3月 -12

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMP LE01.DBF

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

44 Incr 0 330M DISK 00:00:40 15-3月 -12

BP Key: 44 Status: AVAILABLE Compressed: YES Tag: TAG20120315T132342

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1FN5UFIU_1_1 List of Datafiles in backup set 44

File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ----

1 0 Incr 632251 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTE M01.DBF

12 / 88

RMAN增量恢复测试记录

4 0 Incr 632251 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS 01.DBF

6 0 Incr 632251 15-3月 -12 F:\\ORADATA2\\TABLESPACE1.DBF

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

45 7K DISK 00:00:01 15-3月 -12

BP Key: 45 Status: AVAILABLE Compressed: YES Tag: TAG20120315T132425

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1HN5UFK9_1_1

List of Archived Logs in backup set 45

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 6 632247 15-3月 -12 632273 15-3月 -12

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

46 Full 2M DISK 00:00:01 15-3月 -12

BP Key: 46 Status: AVAILABLE Compressed: NO Tag: TAG20120315T132427 Piece Name: F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-02 Controlfile Included: Ckp SCN: 632278 Ckp time: 15-3月 -12 SPFILE Included: Modification time: 14-3月 -12

可以看到当时的备份集到达了46,下一个SCN 为632273

控制文件所对应的块为F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-02

2.1.7、测试信息汇总

1、 从插入数据到第一次全备份结束时产生的归档日志为2-6,即在恢复这一段时间用到的归档日志为2-6

2、当时的SCN 为632272(从最后一个备份的归档日志得知) 3、时间段为:12-03-15 12:52:23 至 12-03-15 13:25:19

4、控制文件的对应的备份片为:F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-02

13 / 88

RMAN增量恢复测试记录

2.2、第一次增量备份

2.2.1、数据记录

SQL> insert into name values(2,'wxh');

1 row created.

SQL> insert into name values(3,'zyx');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx

2.2.2、当时的归档日志序列号

SQL> alter system switch logfile;

System altered.

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled Archive destination f:\\arch Oldest online log sequence 6 Next log sequence to archive 8 Current log sequence 8

14 / 88

RMAN增量恢复测试记录

2.2.3、数据库当时的时间

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 13:33:54

2.2.4、开始第一次增量备份

RMAN> backup incremental level 1 database plus archivelog;

Starting backup at 15-3月 -12 current log archived

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=1 recid=46 stamp=777991779 channel ORA_DISK_1: starting piece 1 at 15-3月 -12

channel ORA_DISK_2: starting compressed archive log backupset channel ORA_DISK_2: specifying archive log(s) in backup set

input archive log thread=1 sequence=2 recid=47 stamp=777993230 input archive log thread=1 sequence=3 recid=48 stamp=777993432 input archive log thread=1 sequence=4 recid=49 stamp=777993480 input archive log thread=1 sequence=5 recid=50 stamp=777993819

channel ORA_DISK_2: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1JN5UGVH_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:06 channel ORA_DISK_2: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1KN5UGVH_1_1 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:06 channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=6 recid=51 stamp=777993865 input archive log thread=1 sequence=7 recid=52 stamp=777994374 input archive log thread=1 sequence=8 recid=53 stamp=777995249 channel ORA_DISK_1: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1LN5UGVN_1_1 comment=NONE

15 / 88

RMAN增量恢复测试记录

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02

Finished backup at 15-3月 -12

Starting backup at 15-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed incremental level 1 datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF

input datafile fno=00006 name=F:\\ORADATA2\\TABLESPACE1.DBF

input datafile fno=00004 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF channel ORA_DISK_1: starting piece 1 at 15-3月 -12

channel ORA_DISK_2: starting compressed incremental level 1 datafile backupset channel ORA_DISK_2: specifying datafile(s) in backupset

input datafile fno=00003 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF

input datafile fno=00005 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DB F

input datafile fno=00002 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DB F

channel ORA_DISK_2: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1MN5UGVQ_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35

channel ORA_DISK_2: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1NN5UGVQ_1_1 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:35 Finished backup at 15-3月 -12

Starting backup at 15-3月 -12 current log archived

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=9 recid=54 stamp=777995293

channel ORA_DISK_1: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1ON5UH0T_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 15-3月 -12

Starting Control File and SPFILE Autobackup at 15-3月 -12

16 / 88

RMAN增量恢复测试记录

piece handle=F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-03 comment=NONE Finished Control File and SPFILE Autobackup at 15-3月 -12

2.2.5、备份后的归档日志状态

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled Archive destination f:\\arch Oldest online log sequence 9 Next log sequence to archive 11 Current log sequence 11

2.2.6、第一次增量备份后的时间

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 14:02:39

2.2.7、查看第一次增量备份后的RMAN 备份集

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

47 3M DISK 00:00:02 15-3月 -12

BP Key: 47 Status: AVAILABLE Compressed: YES Tag: TAG20120315T134729

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1JN5UGVH_1_1

List of Archived Logs in backup set 47

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 1 627378 15-3月 -12 630832 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

48 2M DISK 00:00:02 15-3月 -12

17 / 88

RMAN增量恢复测试记录

BP Key: 48 Status: AVAILABLE Compressed: YES Tag: TAG20120315T134729

Piece Name: F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1KN5UGVH_1_1

List of Archived Logs in backup set 48

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 2 630832 15-3月 -12 631802 15-3月 -12 1 3 631802 15-3月 -12 632048 15-3月 -12 1 4 632048 15-3月 -12 632071 15-3月 -12 1 5 632071 15-3月 -12 632247 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

49 270K DISK 00:00:01 15-3月 -12

BP Key: 49 Status: AVAILABLE Compressed: YES Tag: TAG20120315T134729

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1LN5UGVN_1_1

List of Archived Logs in backup set 49

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 6 632247 15-3月 -12 632273 15-3月 -12 1 7 632273 15-3月 -12 632557 15-3月 -12 1 8 632557 15-3月 -12 632972 15-3月 -12

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

50 Incr 1 192K DISK 00:00:31 15-3月 -12

BP Key: 50 Status: AVAILABLE Compressed: YES Tag: TAG20120315T134737

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1MN5UGVQ_1_1 List of Datafiles in backup set 50

File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ----

1 1 Incr 632978 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTE M01.DBF

4 1 Incr 632978 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS 01.DBF

6 1 Incr 632978 15-3月 -12 F:\\ORADATA2\\TABLESPACE1.DBF

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

51 Incr 1 480K DISK 00:00:31 15-3月 -12

18 / 88

RMAN增量恢复测试记录

BP Key: 51 Status: AVAILABLE Compressed: YES Tag: TAG20120315T134737

Piece Name: F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1NN5UGVQ_1_1 List of Datafiles in backup set 51

File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ----

2 1 Incr 632979 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOT BS01.DBF

3 1 Incr 632979 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAU X01.DBF

5 1 Incr 632979 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMP LE01.DBF

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

52 5K DISK 00:00:01 15-3月 -12

BP Key: 52 Status: AVAILABLE Compressed: YES Tag: TAG20120315T134813

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1ON5UH0T_1_1

List of Archived Logs in backup set 52

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 9 632972 15-3月 -12 632997 15-3月 -12

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

53 Full 2M DISK 00:00:01 15-3月 -12

BP Key: 53 Status: AVAILABLE Compressed: NO Tag: TAG20120315T134815 Piece Name: F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-03 Controlfile Included: Ckp SCN: 633002 Ckp time: 15-3月 -12 SPFILE Included: Modification time: 14-3月 -12

可以看到此次备份的下一个SCN为:632997

控制文件所对应的块为:F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-03

2.2.8、测试信息汇总

1、 从插入数据到第一次增量备份结束时产生的归档日志为7-9,即在恢复这一段时间用到的归档日志为7-9

2、当时的SCN 为632996(从最后一个备份的归档日志得知) 3、时间段为:12-03-15 13:33:54 至 12-03-15 14:02:39

4、控制文件的片为:F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-03

19 / 88

RMAN增量恢复测试记录

2.3、第二次增量备份

2.3.1、数据记录

2.3.1.1、先插入两条数据

SQL> insert into name values(4,'wyk');

1 row created.

SQL> insert into name values(5,'zy');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx 4 wyk 5 zy

时间:

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 14:32:12

20 / 88

RMAN增量恢复测试记录

2.3.1.2、再插入两条数据:

SQL> insert into name values(6,'sms');

1 row created.

SQL> insert into name values(6,'wfq');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx 4 wyk 5 zy 6 sms 6 wfq

7 rows selected.

SQL> update name set id=7 where name='wfq';

1 row updated.

SQL> commit;

Commit complete.

SQL> select * from name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx

21 / 88

RMAN增量恢复测试记录

4 wyk 5 zy 6 sms 7 wfq

7 rows selected.

SQL>

时间:

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 14:40:23

2.3.1.3、继续插入数据:

SQL> insert into name values(8,'zl');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx 4 wyk 5 zy 6 sms 7 wfq 8 zl

8 rows selected.

时间:

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

22 / 88

RMAN增量恢复测试记录

TO_CHAR(SYSDATE,' -----------------

12-03-15 14:44:57

2.3.2、当时的归档日志序列号

SQL> alter system switch logfile;

System altered.

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled Archive destination f:\\arch Oldest online log sequence 10 Next log sequence to archive 12 Current log sequence 12 SQL>

2.3.3、数据库当时的时间

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 14:47:03

2.3.4、开始第二次增量备份

RMAN> backup incremental level 1 database plus archivelog;

Starting backup at 15-3月 -12 current log archived

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

23 / 88

RMAN增量恢复测试记录

input archive log thread=1 sequence=7 recid=52 stamp=777994374 input archive log thread=1 sequence=8 recid=53 stamp=777995249 input archive log thread=1 sequence=9 recid=54 stamp=777995293 input archive log thread=1 sequence=10 recid=55 stamp=777996028 channel ORA_DISK_1: starting piece 1 at 15-3月 -12

channel ORA_DISK_2: starting compressed archive log backupset channel ORA_DISK_2: specifying archive log(s) in backup set

input archive log thread=1 sequence=1 recid=46 stamp=777991779 input archive log thread=1 sequence=2 recid=47 stamp=777993230 input archive log thread=1 sequence=3 recid=48 stamp=777993432 input archive log thread=1 sequence=4 recid=49 stamp=777993480 input archive log thread=1 sequence=5 recid=50 stamp=777993819 input archive log thread=1 sequence=6 recid=51 stamp=777993865

channel ORA_DISK_2: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04

channel ORA_DISK_2: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1RN5UKHI_1_1 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:04 channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=11 recid=56 stamp=777998772 input archive log thread=1 sequence=12 recid=57 stamp=777998898 channel ORA_DISK_1: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1SN5UKHM_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 15-3月 -12

Starting backup at 15-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed incremental level 1 datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF

input datafile fno=00006 name=F:\\ORADATA2\\TABLESPACE1.DBF

input datafile fno=00004 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF channel ORA_DISK_1: starting piece 1 at 15-3月 -12

channel ORA_DISK_2: starting compressed incremental level 1 datafile backupset channel ORA_DISK_2: specifying datafile(s) in backupset

input datafile fno=00003 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF

24 / 88

RMAN增量恢复测试记录

input datafile fno=00005 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DB F

input datafile fno=00002 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DB F

channel ORA_DISK_2: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1TN5UKHP_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35

channel ORA_DISK_2: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1UN5UKHP_1_1 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:35 Finished backup at 15-3月 -12

Starting backup at 15-3月 -12 current log archived

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=13 recid=58 stamp=777998940

channel ORA_DISK_1: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1VN5UKIS_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 15-3月 -12

Starting Control File and SPFILE Autobackup at 15-3月 -12

piece handle=F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-04 comment=NONE Finished Control File and SPFILE Autobackup at 15-3月 -12

RMAN>

2.3.5、备份后的归档日志序列号

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled Archive destination f:\\arch Oldest online log sequence 12 Next log sequence to archive 14 Current log sequence 14

25 / 88

RMAN增量恢复测试记录

2.3.6、第二次增量备份后的时间

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 14:51:51

2.3.7、查看第二次增量备份RMAN 备份集

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

54 9M DISK 00:00:03 15-3月 -12

BP Key: 54 Status: AVAILABLE Compressed: YES Tag: TAG20120315T144818

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1

List of Archived Logs in backup set 54

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 7 632273 15-3月 -12 632557 15-3月 -12 1 8 632557 15-3月 -12 632972 15-3月 -12 1 9 632972 15-3月 -12 632997 15-3月 -12 1 10 632997 15-3月 -12 635746 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

55 6M DISK 00:00:03 15-3月 -12

BP Key: 55 Status: AVAILABLE Compressed: YES Tag: TAG20120315T144818

Piece Name: F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1RN5UKHI_1_1

List of Archived Logs in backup set 55

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 1 627378 15-3月 -12 630832 15-3月 -12 1 2 630832 15-3月 -12 631802 15-3月 -12 1 3 631802 15-3月 -12 632048 15-3月 -12 1 4 632048 15-3月 -12 632071 15-3月 -12 1 5 632071 15-3月 -12 632247 15-3月 -12 1 6 632247 15-3月 -12 632273 15-3月 -12

26 / 88

RMAN增量恢复测试记录

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

56 1M DISK 00:00:01 15-3月 -12

BP Key: 56 Status: AVAILABLE Compressed: YES Tag: TAG20120315T144818

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1SN5UKHM_1_1

List of Archived Logs in backup set 56

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 11 635746 15-3月 -12 637566 15-3月 -12 1 12 637566 15-3月 -12 637627 15-3月 -12

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

57 Incr 1 3M DISK 00:00:30 15-3月 -12

BP Key: 57 Status: AVAILABLE Compressed: YES Tag: TAG20120315T144824

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1TN5UKHP_1_1 List of Datafiles in backup set 57

File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ----

1 1 Incr 637632 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTE M01.DBF

4 1 Incr 637632 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS 01.DBF

6 1 Incr 637632 15-3月 -12 F:\\ORADATA2\\TABLESPACE1.DBF

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

58 Incr 1 8M DISK 00:00:31 15-3月 -12

BP Key: 58 Status: AVAILABLE Compressed: YES Tag: TAG20120315T144824

Piece Name: F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1UN5UKHP_1_1 List of Datafiles in backup set 58

File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ----

2 1 Incr 637633 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOT BS01.DBF

3 1 Incr 637633 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAU X01.DBF

5 1 Incr 637633 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMP LE01.DBF

27 / 88

RMAN增量恢复测试记录

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

59 6K DISK 00:00:01 15-3月 -12

BP Key: 59 Status: AVAILABLE Compressed: YES Tag: TAG20120315T144900

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1VN5UKIS_1_1

List of Archived Logs in backup set 59

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 13 637627 15-3月 -12 637648 15-3月 -12

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

60 Full 2M DISK 00:00:01 15-3月 -12

BP Key: 60 Status: AVAILABLE Compressed: NO Tag: TAG20120315T144902 Piece Name: F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-04 Controlfile Included: Ckp SCN: 637653 Ckp time: 15-3月 -12 SPFILE Included: Modification time: 14-3月 -12

RMAN>

2.3.8、第二次增量备份后查询系统的SCN

查询系统当前最新SCN(oracle内部时钟)

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER ------------------------

639262

查询数据库检查点SCN

SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE# ------------------

637648

查看数据文件的检查点SCN

SQL> select name,checkpoint_change# from v$datafile;

28 / 88

RMAN增量恢复测试记录

NAME CHECKPOINT_CHANGE# ---------------------------------------------------- ------------------

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF 637648 F:\\ORADATA2\\TABLESPACE1.DBF 637648

6 rows selected.

查看启动SCN

SQL> select name,checkpoint_change# from v$datafile_header;

NAME CHECKPOINT_CHANGE# ---------------------------------------------------- ------------------

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF 637648 F:\\ORADATA2\\TABLESPACE1.DBF 637648

6 rows selected.

2.3.9、测试信息汇总

1、 从插入数据到第二次增量备份结束时产生的归档日志为10-13,即在恢复这一段时间用到的归档日志为10-13

2、备份完成时的SCN 为637648(由系统检测点的SCN得知) 3、时间段为:12-03-15 14:47:03 至 12-03-15 14:51:51

4、控制文件的块为:F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-04

3.4、第三次增量备份

3.4.1、数据分布

SQL> insert into name values(9,'wys');

29 / 88

RMAN增量恢复测试记录

1 row created.

SQL> commit;

Commit complete.

SQL> select * from name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx 4 wyk 5 zy 6 sms 7 wfq 8 zl 9 wys 提交时间:

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 15:52:35

数据库检查点的SCN:

SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE# ------------------

637648

说明:数据库检查点的SCN并未改变

查询数据文件的SCN:

SQL> select name,checkpoint_change# from v$datafile;

NAME 30 / 88

CHECKPOINT_CHANGE#

RMAN增量恢复测试记录

---------------------------------------------------- ------------------

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF 637648 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF 637648 F:\\ORADATA2\\TABLESPACE1.DBF 637648

6 rows selected.

说明:数据文件的SCN也未发生改变,由此可见提交不直接对数据文件进行修改。

查询系统的SCN:

SQL> select dbms_flashback.get_system_change_number scn from dual;

SCN --------------

639997

3.4.2、当时的归档日志序列号

SQL> alter system switch logfile;

System altered.

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled Archive destination f:\\arch Oldest online log sequence 13 Next log sequence to archive 15 Current log sequence 15

再次查询数据库检查点的SCN

SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE# ------------------

637648

说明:SCN依然没有发生改变,说明切换日志也不会直接触发数据库的检查点操作

31 / 88

RMAN增量恢复测试记录

3.4.3、数据库当前的时间

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 16:02:56

SQL> select dbms_flashback.get_system_change_number scn from dual;

SCN --------------

640304

SQL> select scn_to_timestamp(640304) scn from dual; SCN

--------------------------------------------------------------------------- 15-3月 -12 04.02.57.000000000 下午

3.4.4、开始第三次增量备份

RMAN> backup incremental level 1 database plus archivelog;

Starting backup at 15-3月 -12 current log archived

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=9 recid=54 stamp=777995293 input archive log thread=1 sequence=10 recid=55 stamp=777996028 input archive log thread=1 sequence=11 recid=56 stamp=777998772 input archive log thread=1 sequence=12 recid=57 stamp=777998898 input archive log thread=1 sequence=13 recid=58 stamp=777998940 input archive log thread=1 sequence=14 recid=59 stamp=778003242 channel ORA_DISK_1: starting piece 1 at 15-3月 -12

channel ORA_DISK_2: starting compressed archive log backupset channel ORA_DISK_2: specifying archive log(s) in backup set

input archive log thread=1 sequence=1 recid=46 stamp=777991779 input archive log thread=1 sequence=2 recid=47 stamp=777993230

32 / 88

RMAN增量恢复测试记录

input archive log thread=1 sequence=3 recid=48 stamp=777993432 input archive log thread=1 sequence=4 recid=49 stamp=777993480 input archive log thread=1 sequence=5 recid=50 stamp=777993819 input archive log thread=1 sequence=6 recid=51 stamp=777993865 input archive log thread=1 sequence=7 recid=52 stamp=777994374 input archive log thread=1 sequence=8 recid=53 stamp=777995249 channel ORA_DISK_2: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_21N5UP1G_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04

channel ORA_DISK_2: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_22N5UP1G_1_1 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:04 channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=15 recid=60 stamp=778003503

channel ORA_DISK_1: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_23N5UP1K_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 15-3月 -12

Starting backup at 15-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed incremental level 1 datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF

input datafile fno=00006 name=F:\\ORADATA2\\TABLESPACE1.DBF

input datafile fno=00004 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF channel ORA_DISK_1: starting piece 1 at 15-3月 -12

channel ORA_DISK_2: starting compressed incremental level 1 datafile backupset channel ORA_DISK_2: specifying datafile(s) in backupset

input datafile fno=00003 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF

input datafile fno=00005 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DB F

input datafile fno=00002 name=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DB F

channel ORA_DISK_2: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_24N5UP1N_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35

33 / 88

RMAN增量恢复测试记录

channel ORA_DISK_2: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_25N5UP1N_1_1 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:35 Finished backup at 15-3月 -12

Starting backup at 15-3月 -12 current log archived

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting compressed archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=16 recid=61 stamp=778003546 channel ORA_DISK_1: starting piece 1 at 15-3月 -12 channel ORA_DISK_1: finished piece 1 at 15-3月 -12

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_26N5UP2Q_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02

Finished backup at 15-3月 -12

Starting Control File and SPFILE Autobackup at 15-3月 -12

piece handle=F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-05 comment=NONE Finished Control File and SPFILE Autobackup at 15-3月 -12

RMAN>

3.4.5、备份后的归档日志序列号

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled Archive destination f:\\arch Oldest online log sequence 15 Next log sequence to archive 17 Current log sequence 17 SQL>

34 / 88

RMAN增量恢复测试记录

3.4.6、第三次增量备份后的时间

SQL> select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,' -----------------

12-03-15 16:08:43

查询数据库检查点SCN:

SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE# ------------------

640383

说明:数据库检查点SCN 已经发生改变

查看数据文件检查点SCN和启动SCN:

SQL> select name,checkpoint_change# from v$datafile_header;

NAME ---------------------------------------------------- ------------------

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF F:\\ORADATA2\\TABLESPACE1.DBF

6 rows selected.

SQL> select name,checkpoint_change# from v$datafile;

NAME ---------------------------------------------------- ------------------

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF F:\\ORADATA2\\TABLESPACE1.DBF

35 / 88

CHECKPOINT_CHANGE# 640383 640383 640383 640383 640383 640383 CHECKPOINT_CHANGE# 640383 640383 640383 640383 640383 640383 RMAN增量恢复测试记录

6 rows selected.

SQL>

说明:SCN都已经发生改变

3.4.7、查看第三次增量备份的RMAN备份集

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

61 6M DISK 00:00:03 15-3月 -12

BP Key: 61 Status: AVAILABLE Compressed: YES Tag: TAG20120315T160503

Piece Name: F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_22N5UP1G_1_1

List of Archived Logs in backup set 61

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 1 627378 15-3月 -12 630832 15-3月 -12 1 2 630832 15-3月 -12 631802 15-3月 -12 1 3 631802 15-3月 -12 632048 15-3月 -12 1 4 632048 15-3月 -12 632071 15-3月 -12 1 5 632071 15-3月 -12 632247 15-3月 -12 1 6 632247 15-3月 -12 632273 15-3月 -12 1 7 632273 15-3月 -12 632557 15-3月 -12 1 8 632557 15-3月 -12 632972 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

62 16M DISK 00:00:04 15-3月 -12

BP Key: 62 Status: AVAILABLE Compressed: YES Tag: TAG20120315T160503

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_21N5UP1G_1_1

List of Archived Logs in backup set 62

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 9 632972 15-3月 -12 632997 15-3月 -12 1 10 632997 15-3月 -12 635746 15-3月 -12 1 11 635746 15-3月 -12 637566 15-3月 -12 1 12 637566 15-3月 -12 637627 15-3月 -12 1 13 637627 15-3月 -12 637648 15-3月 -12 1 14 637648 15-3月 -12 640226 15-3月 -12

36 / 88

RMAN增量恢复测试记录

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

63 74K DISK 00:00:01 15-3月 -12

BP Key: 63 Status: AVAILABLE Compressed: YES Tag: TAG20120315T160503

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_23N5UP1K_1_1

List of Archived Logs in backup set 63

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 15 640226 15-3月 -12 640358 15-3月 -12

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

64 Incr 1 368K DISK 00:00:31 15-3月 -12

BP Key: 64 Status: AVAILABLE Compressed: YES Tag: TAG20120315T160510

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_24N5UP1N_1_1 List of Datafiles in backup set 64

File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ----

1 1 Incr 640369 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTE M01.DBF

4 1 Incr 640369 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS 01.DBF

6 1 Incr 640369 15-3月 -12 F:\\ORADATA2\\TABLESPACE1.DBF

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

65 Incr 1 5M DISK 00:00:31 15-3月 -12

BP Key: 65 Status: AVAILABLE Compressed: YES Tag: TAG20120315T160510

Piece Name: F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_25N5UP1N_1_1 List of Datafiles in backup set 65

File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ---------- ----

2 1 Incr 640370 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOT BS01.DBF

3 1 Incr 640370 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAU X01.DBF

5 1 Incr 640370 15-3月 -12 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMP LE01.DBF

37 / 88

RMAN增量恢复测试记录

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

66 13K DISK 00:00:01 15-3月 -12

BP Key: 66 Status: AVAILABLE Compressed: YES Tag: TAG20120315T160546

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_26N5UP2Q_1_1

List of Archived Logs in backup set 66

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 16 640358 15-3月 -12 640383 15-3月 -12

BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ---------------

67 Full 2M DISK 00:00:01 15-3月 -12

BP Key: 67 Status: AVAILABLE Compressed: NO Tag: TAG20120315T160548 Piece Name: F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-05 Controlfile Included: Ckp SCN: 640388 Ckp time: 15-3月 -12 SPFILE Included: Modification time: 14-3月 -12

RMAN>

可以看到当前数据库的下一个SCN与我们前面看到的数据库检查点的SCN一致,

另外控制文件备份对应的块为:F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-05

3.4.8、测试信息汇总

1、 从插入数据到第三次增量备份结束时产生的归档日志为14-16,即在恢复这一段时间用到的归档日志为14-16

2、当时的SCN 为640358(由备份后的最后一个归档日志得知) 3、时间段为:12-03-15 16:02:56 至 12-03-15 16:08:43

4、控制文件的块为:F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-05

38 / 88

RMAN增量恢复测试记录

三、恢复过程

3.1、进行任意时间点的恢复

测试目的:

1、基于时间点的恢复,并把数据恢复数据库到第二次增量备份时间点的状态 2、能够恢复到任意时间点

3、增量恢复是否需要应用全备到增备阶段所有的归档日志

测试步骤:

1、恢复第二次增量备份时的控制文件

2、把数据恢复到中间一次事物的时间点(基于时间点) 3、把数据库recover 到中间一次事物的时间点

3.1.1、模拟故障。

正常关闭数据库,删除数据文件、控制文件、归档日志、及spfile等

3.1.2、发现故障

SQL> startup

ORA-01078: failure in processing system parameters

LRM-00109: could not open parameter file 'E:\\ORACLE\\PRODUCT\\10.1.0\\DB_1\\DATABASE \\INITORCL.ORA'

已经无法正常启动,提示找不到参数文件。

39 / 88

RMAN增量恢复测试记录

3.1.3、恢复参数文件

3.1.3.1、连接RMAN,设置DBID

C:\\Documents and Settings\\Administrator>rman target /

Recovery Manager: Release 10.1.0.2.0 - Production

Copyright (c) 1995, 2004, Oracle. All rights reserved.

connected to target database (not started)

RMAN> set dbid 1294617127

executing command: SET DBID

附:DBID,可通过控制文件的自动备份的文件获取到,如下图:

3.1.3.2、通过Oracle 默认的参数文件启动

RMAN> startup nomount;

startup failed: ORA-01078: failure in processing system parameters

LRM-00109: could not open parameter file 'E:\\ORACLE\\PRODUCT\\10.1.0\\DB_1\\DATABASE \\INITORCL.ORA'

trying to start the Oracle instance without parameter files ... Oracle instance started

40 / 88

RMAN增量恢复测试记录

Total System Global Area 113246208 bytes

Fixed Size 787708 bytes Variable Size 61602564 bytes Database Buffers 50331648 bytes Redo Buffers 524288 bytes

3.1.3.3、从第一次全备份中恢复spfile

RMAN> restore spfile from 'F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-02';

Starting restore at 15-3月 -12

using target database controlfile instead of recovery catalog allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=29 devtype=DISK

channel ORA_DISK_1: autobackup found: F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20 120315-02

channel ORA_DISK_1: SPFILE restore from autobackup complete Finished restore at 15-3月 -12

3.1.3.4、重新从恢复后的参数文件启动

关闭数据库实例,重新从刚才已恢复的参数文件启动数据库实例。 RMAN> shutdown immediate; Oracle instance shut down

RMAN> startup nomount;

connected to target database (not started) Oracle instance started

Total System Global Area 171966464 bytes

Fixed Size 787988 bytes Variable Size 145488364 bytes Database Buffers 25165824 bytes Redo Buffers 524288 bytes

可见SGA 等相关参数已经恢复正常,不再是默认的参数

41 / 88

RMAN增量恢复测试记录

3.1.4、恢复控制文件

恢复第二次增量备份的控制文件

RMAN> restore controlfile from 'F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315 -04';

Starting restore at 16-3月 -12 using channel ORA_DISK_1

channel ORA_DISK_1: restoring controlfile channel ORA_DISK_1: restore complete

output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL01.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL02.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL03.CTL Finished restore at 16-3月 -12

3.1.5、恢复第二次增量备份时的数据文件

把数据文件恢复到第二次增量备份,中间一次插入数据的时间点 RMAN> run 2> {

3> alter database mount;

4> set until time \"to_date('12-03-15 14:40:23','yy-mm-dd hh24:mi:ss')\"; 5> restore database; 6> }

database mounted

released channel: ORA_DISK_1

executing command: SET until clause

Starting restore at 16-3月 -12

Starting implicit crosscheck backup at 16-3月 -12 allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=160 devtype=DISK allocated channel: ORA_DISK_2

channel ORA_DISK_2: sid=159 devtype=DISK Crosschecked 26 objects

Finished implicit crosscheck backup at 16-3月 -12

42 / 88

RMAN增量恢复测试记录

Starting implicit crosscheck copy at 16-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2 Crosschecked 1 objects

Finished implicit crosscheck copy at 16-3月 -12

searching for all files in the recovery area cataloging files... cataloging done

no files cataloged

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_2: starting datafile backupset restore

channel ORA_DISK_2: specifying datafile(s) to restore from backup set

restoring datafile 00001 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF restoring datafile 00004 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF restoring datafile 00006 to F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00002 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF restoring datafile 00003 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF restoring datafile 00005 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1GN5UFIU_1_1 tag=TAG20120315T1323 42

channel ORA_DISK_1: restore complete

channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1FN5UFIU_1_1 tag=TAG20120315T1323 42

channel ORA_DISK_2: restore complete Finished restore at 16-3月 -12

分析说明:上面恢复阶段用到的piece handle 为全备份时的piece

3.1.6、查看数据库的相关SCN

数据文件检查点SCN

SQL> select name,checkpoint_change# from v$datafile;

43 / 88

RMAN增量恢复测试记录

NAME CHECKPOINT_CHANGE# --------------------------------------------------- ------------------

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF 637632 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF 637633 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF 637633 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF 637632 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF 637633 F:\\ORADATA2\\TABLESPACE1.DBF 637632

6 rows selected.

系统检查点SCN

SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE# ------------------

637627

启动SCN

SQL> select name,checkpoint_change# from v$datafile_header;

NAME CHECKPOINT_CHANGE# --------------------------------------------------- ------------------

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF 632251 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF 632252 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF 632252 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF 632251 E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF 632252 F:\\ORADATA2\\TABLESPACE1.DBF 632251

6 rows selected.

终止SCN

SQL> select name,last_change# from v$datafile;

NAME LAST_CHANGE# --------------------------------------------------- ------------

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF

44 / 88

RMAN增量恢复测试记录

E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF F:\\ORADATA2\\TABLESPACE1.DBF

6 rows selected.

以上看一下看出,系统检查点的 SCN、数据文件检查点的SCN、启动SCN 各不相同,需要介质恢复

SCN与系统恢复说明:

control中有三种SCN分别为,system SCN、datafile SCN、last SCN,数据文件头中有一种SCN start SCN。

system scn从视图v$database中获得,对应checkpoint_change#字段,datafile scn、last scn分别对应视图v$datafile中的checkpoint_change#,last_change#,而 start scn则从v$datafile_header中checkpoint_change#得到。

数据库在正常启动后下,system scn,datafile scn,start scn会相等,而last scn会被置于无穷大,这里为null。

正常关闭后(immediate,noraml,translate),上面四个scn会应执行full checkpoint 而相等。

当系统在非正常关闭后,如shutdown abort,这个时候last scn依然为无穷大,那么当重新启动实例时,系统首先会比较start scn与system scn,如果一致,那么再比较start scn 与last scan是否一样大,因为是非正常关闭,这里会不一样大,那么就需要例程恢复。 如果打开数据库时发现system scn>datafile scn,那么以为着使用旧的备份数据文件,也就是需要介质恢复

如果是system scnsystem scn=datafile scn=start scn=stop scn

1)system scn=datafile scn=start scn,不需要介质恢复 2)stopscn not null,不需要实例恢复 2、系统异常关闭:

system scn=datafile scn=start scn,stop scn null 1)system scn=datafile scn=start scn,不需要介质恢复 2)stopscn null,需要实例恢复 3、旧数据文件

system scn=datafile scn>start scn,stop scn null/notnull

1)system scn=datafile scn>start scn,需要介质恢复成system scn=datafile scn=start scn

2)stopscn null,需要实例恢复,not null 不需要实例恢复 4、备份控制文件

system scn=datafile scn<=start scn(当数据文件为旧的相等),stop scn notnull/null 1)system scn=datafile scn<=start scn,需要使用using backup controlfile介质恢复

45 / 88

RMAN增量恢复测试记录

成system scn=datafile scn=start scn=current log scn(当前日志最大SCN) 2)为保证上一次恢复没有用到log日志不被使用,必须resetlogs 5、重建noresetlogs控制文件

控制文件中 datafile Checkpoint来自Online logs中的Current log头

current log scn=system scn=datafile scn>=start scn,stop scn not null/null 1)current log scn=system scn=datafile scn>=start scn,需要介质恢复成system scn=datafile scn=start scn=redolog scn(当前日志最大SCN),stop scn not null 2)stopscn not null 不需要实例恢复 6、重建resetlogs控制文件

控制文件中datafile Checkpoint来自各数据文件头。

system scn>=datafile scn=start scn,stop scn not null/null

1)system scn>=datafile scn=start scn,需要使用using backup controlfile介质恢复成system scn=datafile scn=start scn(当前日志最大SCN),stop scn not null

2)stop notnull,因为SCN已经为redolog scn,log已经不能使用,必须resetlogs 。

3.1.7、恢复数据库

RMAN> run 2> {

3> set until time \"to_date('12-03-15 14:40:23','yy-mm-dd hh24:mi:ss')\"; 4> recover database; 5> }

executing command: SET until clause

Starting recover at 16-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_2: starting incremental datafile backupset restore channel ORA_DISK_2: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel ORA_DISK_1: restored backup piece 1

46 / 88

RMAN增量恢复测试记录

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1MN5UGVQ_1_1 tag=TAG20120315T1347 37

channel ORA_DISK_1: restore complete

channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1NN5UGVQ_1_1 tag=TAG20120315T1347 37

channel ORA_DISK_2: restore complete

starting media recovery

channel ORA_DISK_1: starting archive log restore to default destination channel ORA_DISK_2: starting archive log restore to default destination channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=9

channel ORA_DISK_2: restoring archive log archive log thread=1 sequence=11

channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=10

channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1SN5UKHM_1_1 tag=TAG20120315T1448 18

channel ORA_DISK_2: restore complete

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1 tag=TAG20120315T1448 18

channel ORA_DISK_1: restore complete

archive log filename=F:\\ARCH\\ARC00009_0777986699.001 thread=1 sequence=9 archive log filename=F:\\ARCH\\ARC00010_0777986699.001 thread=1 sequence=10 archive log filename=F:\\ARCH\\ARC00011_0777986699.001 thread=1 sequence=11 media recovery complete Finished recover at 16-3月 -12

分析说明:由上可见在数据库修复的第一阶段会查找相应的数据文件,确认相关信息。接着,数据库才会应用第一次增量备份的数据、第二次增量备份的数据。最后检查数据文件的RBA(Redo Byte Address)信息,确认需要应用的归档日志,进行数据库的介质恢复。

3.1.8、打开数据库验证数据

SQL> alter database open resetlogs;

Database altered.

SQL> select * from user1.name;

47 / 88

RMAN增量恢复测试记录

ID NAME

---------- --------------------------------------------------- 1 zxk 2 wxh 3 zyx 4 wyk 5 zy 6 sms 7 wfq

7 rows selected.

3.1.9、恢复测试小结

可见恢复后的数据和第二次插入数据完成时的记录完全一致,而且进行增量恢复时并不需要手工的恢复第一次的全备和第一次的增备,rman 会自动按时间点去查找相应的数据文件(其实在restore阶段,只是恢复全备份时的数据)和归档日志进行恢复。在数据recover阶段,用到的归档日志为9-11,即第一次增量备份完成到第二次增量备份前插入数据时所对应的归档日志。这说明,oracle 在同时存在增量备份和归档日志的情况下,是优先选择增量备份的数据的,应用增量备份数据后,并不需要前期的归档日志。

思考问题:既然在restore 阶段执行恢复全备份时的数据文件,那么在恢复数据的时候,是不是直接restore database 就行了,时间点和scn 的限制放在recover 阶段指定就行了呢?后面我们继续研究

3.2、丢失某个增量备份集的恢复(基于时间点)

测试目的:

1、验证基于时间点的恢复,并把数据恢复到第三次增量备份的时间点 2、增量恢复在第二次增量备份数据被删除后,将会进行怎样的恢复 3、增量备份恢复数据阶段,后续增量恢复(restore)是不是会直接跳过

4、在第二次增量恢复被删除后,oracle 会不会在找不到增量备份数据的状态下,自动的去 寻找归档日志进行恢复

48 / 88

RMAN增量恢复测试记录

测试步骤:

1、恢复第三次增量备份的控制文件 2、恢复数据到第一次全备时的状态 3、删除第二次增量备份的数据

4、恢复数据到第三次增量备份时的状态 5、recover 数据库

说明:本次测试,就不模拟参数文件的丢失的恢复了,所有恢复阶段直接从恢复控制文件开始进行。

3.2.1、恢复控制文件

3.2.1.1、恢复前,确认数据库已经处在nomount状态了

SQL> startup nomount; ORACLE instance started.

Total System Global Area 171966464 bytes Fixed Size 787988 bytes Variable Size 145488364 bytes Database Buffers 25165824 bytes Redo Buffers 524288 bytes SQL>

3.2.1.2、恢复第三次增量备份时的控制文件

RMAN> restore controlfile from 'F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315 -05';

Starting restore at 19-3月 -12

using target database controlfile instead of recovery catalog allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK

channel ORA_DISK_1: restoring controlfile channel ORA_DISK_1: restore complete

output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL01.CTL

49 / 88

RMAN增量恢复测试记录

output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL02.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL03.CTL Finished restore at 19-3月 -12

3.2.2、恢复第一次全备份时的数据文件

2.2.2.1、首先,要把数据库启动到mount 状态

SQL> alter database mount;

Database altered.

2.2.2.2、恢复第一次全备时的数据文件

RMAN> run 2> {

3> set until time \"to_date('2012-03-15 13:25:19','yyyy-mm-dd hh24:mi:ss')\"; 4> restore database; 5> }

executing command: SET until clause

Starting restore at 19-3月 -12

Starting implicit crosscheck backup at 19-3月 -12 released channel: ORA_DISK_1 allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK Crosschecked 33 objects

Finished implicit crosscheck backup at 19-3月 -12

Starting implicit crosscheck copy at 19-3月 -12 using channel ORA_DISK_1 Crosschecked 1 objects

Finished implicit crosscheck copy at 19-3月 -12

searching for all files in the recovery area cataloging files... cataloging done

no files cataloged

50 / 88

RMAN增量恢复测试记录

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00002 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF restoring datafile 00003 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF restoring datafile 00005 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1GN5UFIU_1_1 tag=TAG20120315T1323 42

channel ORA_DISK_1: restore complete

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF restoring datafile 00004 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF restoring datafile 00006 to F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1FN5UFIU_1_1 tag=TAG20120315T1323 42

channel ORA_DISK_1: restore complete Finished restore at 19-3月 -12

RMAN>

分析说明:恢复时对应的piece 确实为全备份时产生的piece

3.2.3、删除第二次增量备份时的数据片,模拟第二次增备损坏

查找第二次增量备份对应的备份片为: 1、数据文件:

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1TN5UKHP_1_1 comment=NONE

2、归档日志

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1 comment=NONE

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1RN5UKHI_1_1 comment=NONE

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1SN5UKHM_1_1 comment=NONE

(可见归档日志对应了三个piece)

说明:控制文件的piece 恢复时并不使用,所以我们这里就不删除了

51 / 88

RMAN增量恢复测试记录

(把第二次增量备份对应的数据文件和归档日志片全部改名)

3.2.4、恢复数据到第三次增量备份时的状态

RMAN> run 2> {

3> set until time \"to_date('2012-03-15 16:08:43','yyyy-mm-dd hh24:mi:ss')\"; 4> restore database; 5> }

executing command: SET until clause

Starting restore at 19-3月 -12 using channel ORA_DISK_1

skipping datafile 1; already restored to file E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\O RCL\\SYSTEM01.DBF

skipping datafile 4; already restored to file E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\O

52 / 88

RMAN增量恢复测试记录

RCL\\USERS01.DBF

skipping datafile 6; already restored to file F:\\ORADATA2\\TABLESPACE1.DBF

skipping datafile 2; already restored to file E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\O RCL\\UNDOTBS01.DBF

skipping datafile 3; already restored to file E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\O RCL\\SYSAUX01.DBF

skipping datafile 5; already restored to file E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\O RCL\\EXAMPLE01.DBF

restore not done; all files readonly, offline, or already restored

Finished restore at 19-3月 -12

分析说明:由上可知,在restore 阶段,增量备份数据并不会进行附加。这是不是说明在进行restore 阶段只能进行全备份数据文件的恢复呢?或者说是即使制定时间点也是毫无用处的,主要还是在recover 阶段进行增量数据的附加和前滚呢。

3.2.5、恢复数据库

RMAN> run 2> {

3> set until time \"to_date('2012-03-15 16:08:43','yyyy-mm-dd hh24:mi:ss')\"; 4> recover database; 5> }

executing command: SET until clause

Starting recover at 19-3月 -12 using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1MN5UGVQ_1_1 tag=TAG20120315T1347 37

channel ORA_DISK_1: restore complete

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

53 / 88

RMAN增量恢复测试记录

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1NN5UGVQ_1_1 tag=TAG20120315T1347 37

channel ORA_DISK_1: restore complete

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF

RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 03/19/2012 17:01:41

ORA-19505: failed to identify file \"F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1TN5UKHP_1 _1\"

ORA-27041: unable to open file OSD-04002: unable to open file

O/S-Error: (OS 2) 系统找不到指定的文件。

分析说明:由以上信息可知,数据文件已经应用第一次增量备份时的数据,但在应用第二次增量备份时的数据时,由于我们已经把第二次增量备份的数据文件删除了,所以就恢复失败了。既然没办法恢复增量备份的数据文件,那我们只能手工的恢复归档日志,利用后面增量备份的归档日志,进行数据库的恢复了。因为我们备份时并没有指定立即删除归档,所以情况还是比较乐观的的。但是如果我们指定了立即删除归档,那岂不是在中间的某个增量备份集损坏的情况下,就会导致后续的数据都恢复不了吗。

3.2.6、恢复第一次增量备份后到第二次此增量备份完成这段时间的归档日志。

说明:这里我们并不恢复全部的归档日志,只是来研究一下,在中间某次归档日志找不到的情况,采用归档日志进行恢复,后续依然使用增量备份进行恢复

RMAN> restore archivelog from logseq 10 until logseq 13;

Starting restore at 19-3月 -12 using channel ORA_DISK_1

54 / 88

RMAN增量恢复测试记录

channel ORA_DISK_1: starting archive log restore to default destination channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=10

channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=11

channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=12

channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=13

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_21N5UP1G_1_1 tag=TAG20120315T1605 03

channel ORA_DISK_1: restore complete Finished restore at 19-3月 -12

3.2.7、再次执行恢复数据库

RMAN> run 2> {

3> set until time \"to_date('2012-03-15 16:08:43','yyyy-mm-dd hh24:mi:ss')\"; 4> recover database; 5> }

executing command: SET until clause

Starting recover at 19-3月 -12 using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF

RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 03/19/2012 17:41:53

ORA-19505: failed to identify file \"F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1TN5UKHP_1 _1\"

ORA-27041: unable to open file OSD-04002: unable to open file

55 / 88

RMAN增量恢复测试记录

O/S-Error: (OS 2) 系统找不到指定的文件。

分析:可以看到RMAN 依然是执着的要找第二次增量备份的数据文件。怎么办呢?

3.2.8、执行备份检查

RMAN> crosscheck backup;

using channel ORA_DISK_1 using channel ORA_DISK_2

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_16N5UF6O_1_1 recid=34 stam p=777993433

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_17N5UF6O_1_1 recid=35 stam p=777993433

............................... ............................... ................................... 中间略

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_25N5UP1N_1_1 recid=65 stam p=778003511

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_26N5UP2Q_1_1 recid=66 stam p=778003547

Crosschecked 29 objects

crosschecked backup piece: found to be 'EXPIRED'

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1 recid=54 stam p=777998899

crosschecked backup piece: found to be 'EXPIRED'

backup piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1RN5UKHI_1_1 recid=55 stam p=777998899

crosschecked backup piece: found to be 'EXPIRED'

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1SN5UKHM_1_1 recid=56 stam p=777998903

crosschecked backup piece: found to be 'EXPIRED'

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1TN5UKHP_1_1 recid=57 stam p=777998905

Crosschecked 4 objects

查看备份摘要

56 / 88

RMAN增量恢复测试记录

RMAN> list backup summary;

List of Backups ===============

Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag ------- -- -- - ----------- --------------- ------- ------- ---------- ---

1 B 0 A SBT_TAPE 07-2月 -12 1 1 NO TAG201202 07T125403

2 B TAG201202 07T125403

3 B TAG201202 07T125557

4 B TAG201202 07T130328

5 B TAG201202 07T131154

6 B TAG201202 07T131211

7 B TAG201202 07T131239

8 B TAG201202 07T131256

9 B TAG201202 07T131304

34 B TAG201203 15T131712

35 B TAG201203 15T131712

36 B F 15T131717

37 B F 15T131717

0 A SBT_TAPE 07-2月 -12 F A SBT_TAPE 07-2月 -12 0 A SBT_TAPE 07-2月 -12 0 A SBT_TAPE 07-2月 -12 F A SBT_TAPE 07-2月 -12 A A SBT_TAPE 07-2月 -12 F A SBT_TAPE 07-2月 -12 F A SBT_TAPE 07-2月 -12 A A DISK 15-3月 -12 A A DISK 15-3月 -12 A DISK 15-3月 -12 1 A DISK 15-3月 -12 1 57 / 88

1 1 1 1 1 1 1 1 1 1 1 YES 1 YES 1 NO 1 NO 1 NO 1 NO 1 NO 1 NO

1 NO

1 NO

1 YES

1 YES TAG201203 TAG201203 RMAN增量恢复测试记录

38 B A A DISK 15-3月 -12 1 1 YES TAG201203 15T131800

39 B F A DISK 15-3月 -12 1 1 NO TAG201203 15T131802

40 B A A DISK 15-3月 -12 1 1 YES TAG201203 15T132339 41 B TAG201203 15T132339 42 B TAG201203 15T132339 43 B TAG201203 15T132342 44 B TAG201203 15T132342 45 B TAG201203 15T132425 46 B TAG201203 15T132427

47 B TAG201203 15T134729 48 B TAG201203 15T134729 49 B TAG201203 15T134729 50 B TAG201203 15T134737 51 B TAG201203 15T134737 52 B TAG201203

A A DISK A A DISK 0 A DISK 0 A DISK A A DISK F A DISK A A DISK A A DISK A A DISK 1 A DISK 1 A DISK A A DISK 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 58 / 88

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 YES

YES

YES

YES

YES

NO

YES YES

YES

YES

YES

YES

RMAN增量恢复测试记录

15T134813

53 B F A DISK 15-3月 -12 1 1 NO TAG201203 15T134815

54 B A X DISK 15-3月 -12 1 1 YES TAG201203 15T144818

55 B A X DISK 15-3月 -12 1 1 YES TAG201203 15T144818

56 B TAG201203 15T144818

57 B 1 15T144824

58 B TAG201203 15T144824

59 B TAG201203 15T144900

60 B TAG201203 15T144902

61 B TAG201203 15T160503

62 B TAG201203 15T160503 63 B TAG201203 15T160503 64 B TAG201203 15T160510 65 B TAG201203 15T160510 66 B TAG201203 15T160546

A X DISK X DISK 1 A DISK A A DISK F A DISK A A DISK A A DISK A A DISK 1 A DISK 1 A DISK A A DISK 15-3月 -12 15-3月 -12 1 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 15-3月 -12 59 / 88

1 1 YES 1 1 1 1 1 1 1 1 1 1 YES TAG201203 1 YES 1 YES 1 NO 1 YES 1 YES 1 YES

1 YES

1 YES

1 YES

RMAN增量恢复测试记录

删除无效的备份集

RMAN> delete noprompt expired backup;

using channel ORA_DISK_1 using channel ORA_DISK_2

List of Backup Pieces

BP Key BS Key Pc# Cp# Status Device Type Piece Name ------- ------- --- --- ----------- ----------- ----------

54 54 1 1 EXPIRED DISK F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BA K_1QN5UKHI_1_1

55 55 1 1 EXPIRED DISK F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BA K_1RN5UKHI_1_1

56 56 1 1 EXPIRED DISK F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BA K_1SN5UKHM_1_1

57 57 1 1 EXPIRED DISK F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BA K_1TN5UKHP_1_1 deleted backup piece

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1 recid=54 stam p=777998899

deleted backup piece

backup piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1RN5UKHI_1_1 recid=55 stam p=777998899

deleted backup piece

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1SN5UKHM_1_1 recid=56 stam p=777998903

deleted backup piece

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1TN5UKHP_1_1 recid=57 stam p=777998905

Deleted 4 EXPIRED objects

RMAN>

再次执行交叉检查,发现已经没有无效的备份集了

RMAN> crosscheck backup;

using channel ORA_DISK_1 using channel ORA_DISK_2

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_16N5UF6O_1_1 recid=34 stam p=777993433

........................................................................ .........................................................................

60 / 88

RMAN增量恢复测试记录

...........................................................................

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_25N5UP1N_1_1 recid=65 stam p=778003511

crosschecked backup piece: found to be 'AVAILABLE'

backup piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_26N5UP2Q_1_1 recid=66 stam p=778003547

Crosschecked 29 objects

3.2.9、再次执行恢复数据库

RMAN> run 2> {

3> set until time \"to_date('2012-03-15 16:08:43','yyyy-mm-dd hh24:mi:ss')\"; 4> recover database; 5> }

executing command: SET until clause

Starting recover at 21-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1UN5UKHP_1_1 tag=TAG20120315T1448 24

(说明:对应第二次增量备份的第二个通道的数据文件备份片) channel ORA_DISK_1: restore complete

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL

61 / 88

RMAN增量恢复测试记录

\\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_25N5UP1N_1_1 tag=TAG20120315T1605 10

(说明:对应第三次增量备份的第二个通道上的数据文件备份片) channel ORA_DISK_1: restore complete

starting media recovery

archive log thread 1 sequence 10 is already on disk as file F:\\ARCH\\ARC00010_077 7986699.001

archive log thread 1 sequence 11 is already on disk as file F:\\ARCH\\ARC00011_077 7986699.001

archive log thread 1 sequence 12 is already on disk as file F:\\ARCH\\ARC00012_077 7986699.001

archive log thread 1 sequence 13 is already on disk as file F:\\ARCH\\ARC00013_077 7986699.001

channel ORA_DISK_1: starting archive log restore to default destination channel ORA_DISK_2: starting archive log restore to default destination channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=9

channel ORA_DISK_2: restoring archive log archive log thread=1 sequence=15

channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=14

channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_23N5UP1K_1_1 tag=TAG20120315T1605 03

(说明:第三次增量备份通道1归档日志所对应的piece) channel ORA_DISK_2: restore complete

channel ORA_DISK_2: starting archive log restore to default destination channel ORA_DISK_2: restoring archive log archive log thread=1 sequence=16

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_21N5UP1G_1_1 tag=TAG20120315T1605 03

(第三次增量备份,归档日志备份对应的piece) channel ORA_DISK_1: restore complete

archive log filename=F:\\ARCH\\ARC00009_0777986699.001 thread=1 sequence=9

62 / 88

RMAN增量恢复测试记录

archive log filename=F:\\ARCH\\ARC00010_0777986699.001 thread=1 sequence=10 archive log filename=F:\\ARCH\\ARC00011_0777986699.001 thread=1 sequence=11 archive log filename=F:\\ARCH\\ARC00012_0777986699.001 thread=1 sequence=12 archive log filename=F:\\ARCH\\ARC00013_0777986699.001 thread=1 sequence=13 archive log filename=F:\\ARCH\\ARC00014_0777986699.001 thread=1 sequence=14 archive log filename=F:\\ARCH\\ARC00015_0777986699.001 thread=1 sequence=15 channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_26N5UP2Q_1_1 tag=TAG20120315T1605 46

(第三次增量备份,归档日志备份对应的piece) channel ORA_DISK_2: restore complete

archive log filename=F:\\ARCH\\ARC00016_0777986699.001 thread=1 sequence=16 unable to find archive log

archive log thread=1 sequence=17

RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 03/21/2012 16:10:29

RMAN-06054: media recovery requesting unknown log: thread 1 seq 17 lowscn 640383 RMAN>

分析说明:可见,RMAN 依然找到了第二次增量备份残留的一个备份集(之前这个备份集并没有删除),但由于这个备份集并没有包含完整的增量备份数据,最后还是通过第二次增量备份时全部的归档日志进行恢复。

3.2.10、打开数据库验证数据

SQL> alter database open resetlogs;

Database altered.

SQL> select * from user1.name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx 4 wyk

63 / 88

RMAN增量恢复测试记录

5 zy 6 sms 7 wfq 8 zl 9 wys

9 rows selected.

3.2.11、恢复测试小结

通过以上测试发现,RMAN 在丢失某次增量备份集的情况下,如果不执行备份集的检查,RMAN 还是会采用原来rman 信息中记录的备份集去恢复,这样就会造成恢复的失败。如果要进行恢复,必须执行RMAN 的备份检查,清楚掉无效的备份集,然后才能正常恢复,但是这里有个前提条件就是后续的增量备份是包含丢失的增量备份集那段时间所产生的归档日志的。

思考问题:

如果在恢复第三次增量备份状态的时间点数据时,第一次备份时的归档日志全部丢失,这时能正常恢复吗?

3.3、基于SCN的恢复

测试目的:

1、验证基于SCN 的恢复,并把数据恢复到第二次增量备份事的SCN

2、再次验证RMAN增量恢复时可以利用增量恢复直接恢复数据,无需手工依次恢复相应的增量备份

测试步骤:

1、恢复第二次增量的控制文件

2、把数据恢复到第二次增量备份时的SCN(最后一次事物) 3、恢复数据库

说明:本次恢复不包括spfile 的恢复,也不在按部就班的进行了,直接采用RMAN 脚本进行

64 / 88

RMAN增量恢复测试记录

3.3.1、恢复并修复数据库

RMAN> @f:\\restore.txt

RMAN> run{

2> startup nomount;

3> allocate channel t1 type disk;

4> restore controlfile from 'F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-04 ';

5> release channel t1;

6> sql 'alter database mount'; 7> allocate channel t1 type disk; 8> allocate channel t2 type disk;

9> restore database until scn 637647; 10> recover database until scn 637647; 11> sql 'alter database open resetlogs'; 12> release channel t1; 13> release channel t2; 14> }

Oracle instance started

Total System Global Area 171966464 bytes

Fixed Size 787988 bytes Variable Size 145488364 bytes Database Buffers 25165824 bytes Redo Buffers 524288 bytes

using target database controlfile instead of recovery catalog allocated channel: t1

channel t1: sid=160 devtype=DISK

Starting restore at 25-3月 -12

channel t1: restoring controlfile channel t1: restore complete

output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL01.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL02.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL03.CTL Finished restore at 25-3月 -12

released channel: t1

65 / 88

RMAN增量恢复测试记录

sql statement: alter database mount

allocated channel: t1

channel t1: sid=160 devtype=DISK

allocated channel: t2

channel t2: sid=159 devtype=DISK

Starting restore at 25-3月 -12

Starting implicit crosscheck backup at 25-3月 -12 Crosschecked 26 objects

Finished implicit crosscheck backup at 25-3月 -12

Starting implicit crosscheck copy at 25-3月 -12 Crosschecked 1 objects

Finished implicit crosscheck copy at 25-3月 -12

searching for all files in the recovery area cataloging files... cataloging done

no files cataloged

channel t1: starting datafile backupset restore

channel t1: specifying datafile(s) to restore from backup set

restoring datafile 00002 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF restoring datafile 00003 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF restoring datafile 00005 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF channel t2: starting datafile backupset restore

channel t2: specifying datafile(s) to restore from backup set

restoring datafile 00001 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF restoring datafile 00004 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF restoring datafile 00006 to F:\\ORADATA2\\TABLESPACE1.DBF channel t1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1GN5UFIU_1_1 tag=TAG20120315T1323 42

(说明:第一次全备份时的数据文件备份片)

channel t1: restore complete

channel t2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1FN5UFIU_1_1 tag=TAG20120315T1323 42

channel t2: restore complete Finished restore at 25-3月 -12

66 / 88

RMAN增量恢复测试记录

Starting recover at 25-3月 -12

channel t1: starting incremental datafile backupset restore channel t1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF channel t2: starting incremental datafile backupset restore channel t2: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel t1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1MN5UGVQ_1_1 tag=TAG20120315T1347 37

(说明:第一次增量备份时对应的增量备份的数据文件备份片)

channel t1: restore complete

channel t2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1NN5UGVQ_1_1 tag=TAG20120315T1347 37

channel t2: restore complete

channel t1: starting incremental datafile backupset restore channel t1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF channel t2: starting incremental datafile backupset restore channel t2: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel t1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1TN5UKHP_1_1 tag=TAG20120315T1448 24

67 / 88

RMAN增量恢复测试记录

(说明:第二次增量备份时对应的增量备份的数据文件备份片)

channel t1: restore complete

channel t2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1UN5UKHP_1_1 tag=TAG20120315T1448 24

channel t2: restore complete

starting media recovery

archive log thread 1 sequence 13 is already on disk as file F:\\ARCH\\ARC00013_077 7986699.001

archive log filename=F:\\ARCH\\ARC00013_0777986699.001 thread=1 sequence=13 media recovery complete

(说明:在recover 修复阶段,只用到了第二次增量备份的最后一个归档日志)

Finished recover at 25-3月 -12

sql statement: alter database open resetlogs

released channel: t1

released channel: t2

RMAN>

3.3.2、验证数据

SQL> select * from user1.name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx 4 wyk 5 zy 6 sms 7 wfq 8 zl

8 rows selected.

68 / 88

RMAN增量恢复测试记录

3.3.3、恢复测试小结

基于SCN 的恢复能够把数据库恢复到某个精确的时间点。如果我们不知道当时的SCN值怎么办呢?没关系,可以查找备份的归档日志,归档中的Low SCN 和 Next SCN 之间的SCN值,就是该归档日志所包含的所有SCN。通过很多方法我们都可以获得oracle 相关的SCN。 例:

查询当前系统的SCN

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER ------------------------

643008

查看系统当前保存的SCN

SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE# ------------------

643006

如果此时数据库发生故障,在数据库重新启动需要修复的,就是这两个SCN之间的数据。这些数据存在redo log 中。

SQL> select group#,status,first_change# from v$log;

GROUP# STATUS FIRST_CHANGE# ---------- ---------------- -------------

1 INACTIVE 642333 2 CURRENT 643006 3 INACTIVE 643002

说明:group3 中保存的是SCN号为643002 至642333;group1 中的SCN号为642333至643006;group2 中保存的SCN为643006至643008.

把当前时间点转化为SCN:

SQL> select timestamp_to_scn(systimestamp) as scn from dual;

SCN

69 / 88

RMAN增量恢复测试记录

---------- 643315

查询归档日志的SCN:

List of Archived Logs in backup set 54

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 7 632273 15-3月 -12 632557 15-3月 -12 1 8 632557 15-3月 -12 632972 15-3月 -12 1 9 632972 15-3月 -12 632997 15-3月 -12 1 10 632997 15-3月 -12 635746 15-3月 -12

3.4、丢失中间某个增量备份归档日志的恢复(基于SCN)

测试目的:

1、验证基于SCN的恢复,把数据恢复到第二次增量备份的状态。

2、在删除第一次增量备份的全部归档日志的情况下,还能否进行正常的恢复

3、在restore 阶段不制定任何时间点或SCN,直接通过recover 是不是能够达到同样的目的

测试步骤:

1、恢复第二次增量的控制文件

2、删除第一次增量备份时对应的所有归档日志 2、恢复数据

3、恢复数据库到第二次增量时的SCN

3.4.1、恢复第二次增量备份的控制文件

SQL> startup nomount; ORACLE instance started.

Total System Global Area 171966464 bytes Fixed Size 787988 bytes Variable Size 145488364 bytes Database Buffers 25165824 bytes

70 / 88

RMAN增量恢复测试记录

Redo Buffers 524288 bytes

RMAN> restore controlfile from 'F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315 -04';

Starting restore at 26-3月 -12 using channel ORA_DISK_1

channel ORA_DISK_1: restoring controlfile channel ORA_DISK_1: restore complete

output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL01.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL02.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL03.CTL Finished restore at 26-3月 -12

3.4.2、删除第一次增量备份的归档日志

第一次增量备份归档日志序列号

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

49 270K DISK 00:00:01 15-3月 -12

BP Key: 49 Status: AVAILABLE Compressed: YES Tag: TAG20120315T134729

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1LN5UGVN_1_1

List of Archived Logs in backup set 49

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 6 632247 15-3月 -12 632273 15-3月 -12 1 7 632273 15-3月 -12 632557 15-3月 -12 1 8 632557 15-3月 -12 632972 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

52 5K DISK 00:00:01 15-3月 -12

BP Key: 52 Status: AVAILABLE Compressed: YES Tag: TAG20120315T134813

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1ON5UH0T_1_1

List of Archived Logs in backup set 52

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 9 632972 15-3月 -12 632997 15-3月 -12

71 / 88

RMAN增量恢复测试记录

第二次增量备份对应的第一次增量备份期间所产生归档日志备份片 BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

54 9M DISK 00:00:03 15-3月 -12

BP Key: 54 Status: AVAILABLE Compressed: YES Tag: TAG20120315T144818

Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1

List of Archived Logs in backup set 54

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 7 632273 15-3月 -12 632557 15-3月 -12 1 8 632557 15-3月 -12 632972 15-3月 -12 1 9 632972 15-3月 -12 632997 15-3月 -12 1 10 632997 15-3月 -12 635746 15-3月 -12

删除第一次增量备份时所产生的归档日志7-9

3.4.3、恢复数据文件

RMAN> alter database mount;

database mounted

released channel: ORA_DISK_1

RMAN> restore database;

72 / 88

RMAN增量恢复测试记录

Starting restore at 26-3月 -12

Starting implicit crosscheck backup at 26-3月 -12 allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK allocated channel: ORA_DISK_2

channel ORA_DISK_2: sid=158 devtype=DISK Crosschecked 26 objects

Finished implicit crosscheck backup at 26-3月 -12

Starting implicit crosscheck copy at 26-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2 Crosschecked 1 objects

Finished implicit crosscheck copy at 26-3月 -12

searching for all files in the recovery area cataloging files... cataloging done

no files cataloged

using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00002 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF restoring datafile 00003 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF restoring datafile 00005 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF channel ORA_DISK_2: starting datafile backupset restore

channel ORA_DISK_2: specifying datafile(s) to restore from backup set

restoring datafile 00001 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF restoring datafile 00004 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF restoring datafile 00006 to F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1GN5UFIU_1_1 tag=TAG20120315T1323 42

(说明:对应第一次全备份时数据文件备份片) channel ORA_DISK_1: restore complete

channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1FN5UFIU_1_1 tag=TAG20120315T1323 42

channel ORA_DISK_2: restore complete

73 / 88

RMAN增量恢复测试记录

Finished restore at 26-3月 -12

3.4.4、恢复数据库到第二次增量备份时的SCN

List of Archived Logs in backup set 56

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 11 635746 15-3月 -12 637566 15-3月 -12 1 12 637566 15-3月 -12 637627 15-3月 -12

List of Archived Logs in backup set 59

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 13 637627 15-3月 -12 637648 15-3月 -12

这里我们先把数据库恢复到第二次增量备份的中间的归档日志12对应的一个SCN 637600

RMAN> run 2> {

3> recover database until scn 637600; 4> alter database open resetlogs; 5> }

Starting recover at 28-3月 -12

using target database controlfile instead of recovery catalog allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK allocated channel: ORA_DISK_2

channel ORA_DISK_2: sid=158 devtype=DISK

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_2: starting incremental datafile backupset restore channel ORA_DISK_2: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL

74 / 88

RMAN增量恢复测试记录

\\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1MN5UGVQ_1_1 tag=TAG20120315T1347 37

(第一次增量备份数据文件对应的备份片) channel ORA_DISK_1: restore complete

channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1NN5UGVQ_1_1 tag=TAG20120315T1347 37

(第一次增量备份数据文件对应的备份片)

channel ORA_DISK_2: restore complete

starting media recovery

RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 03/28/2012 16:19:16

RMAN-06053: unable to perform media recovery because of missing log

RMAN-06025: no backup of log thread 1 seq 10 lowscn 632997 found to restore RMAN-06025: no backup of log thread 1 seq 9 lowscn 632972 found to restore

报错了,因为我们把归档日志序列号为9和10 对应的备份集删除了,637600 这个SCN的状态需要用到这两个归档日志。

我们再以第二次增量备份最后一个归档日志所对应的SCN 637648 进行恢复 恢复脚本: RMAN> run 2> {

3> recover database until scn 637648; 4> alter database open resetlogs; 5> }

Starting recover at 28-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

75 / 88

RMAN增量恢复测试记录

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_2: starting incremental datafile backupset restore channel ORA_DISK_2: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1TN5UKHP_1_1 tag=TAG20120315T1448 24

(说明:第二次增量备份,数据文件对应的备份集)

channel ORA_DISK_1: restore complete

channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1UN5UKHP_1_1 tag=TAG20120315T1448 24

(说明:第二次增量备份,数据文件对应的备份集) channel ORA_DISK_2: restore complete

starting media recovery

channel ORA_DISK_1: starting archive log restore to default destination channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=13

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1VN5UKIS_1_1 tag=TAG20120315T1449 00

channel ORA_DISK_1: restore complete

archive log filename=F:\\ARCH\\ARC00013_0777986699.001 thread=1 sequence=13 media recovery complete

Finished recover at 28-3月 -12

database opened

3.4.5、验证数据

SQL> select * from user1.name;

ID NAME ---------- --------------------

76 / 88

RMAN增量恢复测试记录

1 zxk 2 wxh 3 zyx 4 wyk 5 zy 6 sms 7 wfq 8 zl

8 rows selected.

3.4.6、恢复测试小结

通过测试可知,在基于增量恢复的过程中,是采用增量备份片进行恢复的,默认并不会使用归档日志,也不会去检验归档日志备份片是否存在。在恢复数据的阶段(restore阶段),其实指不指定时间和SCN值,并没有太大关系,不完全恢复时只要在数据库修复阶段(recover)指定时间和SCN等限制就可以了。

3.5、基于日志序列号的恢复

测试目的:

1、验证基于日志序列号的恢复,并把数据恢复到第二次增量备份中间的某个事物

测试步骤:

1、恢复第二次增量备份时的控制文件 2、恢复数据文件

3、按序列号恢复归档日志

3、基于日志序列号恢复数据库(recover)

3.5.1、恢复第二次增量备份的控制文件

SQL> startup nomount; ORACLE instance started.

77 / 88

RMAN增量恢复测试记录

Total System Global Area 171966464 bytes Fixed Size 787988 bytes Variable Size 145488364 bytes Database Buffers 25165824 bytes Redo Buffers 524288 bytes SQL>

RMAN> restore controlfile from 'F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315 -04';

Starting restore at 28-3月 -12

using target database controlfile instead of recovery catalog allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK

channel ORA_DISK_1: restoring controlfile channel ORA_DISK_1: restore complete

output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL01.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL02.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL03.CTL Finished restore at 28-3月 -12

3.5.2、恢复数据文件

RMAN> run 2> {

3> sql 'alter database mount'; 4> restore database; 5> }

sql statement: alter database mount

Starting restore at 28-3月 -12

Starting implicit crosscheck backup at 28-3月 -12 released channel: ORA_DISK_1 allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK Crosschecked 26 objects

Finished implicit crosscheck backup at 28-3月 -12

Starting implicit crosscheck copy at 28-3月 -12

78 / 88

RMAN增量恢复测试记录

using channel ORA_DISK_1 Crosschecked 1 objects

Finished implicit crosscheck copy at 28-3月 -12

searching for all files in the recovery area cataloging files... cataloging done

no files cataloged

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00002 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF restoring datafile 00003 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF restoring datafile 00005 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1GN5UFIU_1_1 tag=TAG20120315T1323 42

channel ORA_DISK_1: restore complete

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF restoring datafile 00004 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF restoring datafile 00006 to F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1FN5UFIU_1_1 tag=TAG20120315T1323 42

channel ORA_DISK_1: restore complete Finished restore at 28-3月 -12

3.5.3、查询恢复时间所对应的归档日志

说明:这里我们查询第一次增量备份开始时到第二次增量备份中间一次事物之间的所有的归档日志

RMAN> list backup of archivelog time between \"to_date('12-03-15 13:33:54','yy-mm -dd hh24:mi:ss')\" and \"to_date('12-03-15 14:40:23','yy-mm-dd hh24:mi:ss')\";

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

79 / 88

RMAN增量恢复测试记录

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

49 137K DISK 00:00:01 15-3月 -12

BP Key: 49 Status: AVAILABLE Compressed: NO Tag: TAG20120315T134729 Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1LN5UGVN_1_1

List of Archived Logs in backup set 49

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 8 632557 15-3月 -12 632972 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

52 5K DISK 00:00:01 15-3月 -12

BP Key: 52 Status: AVAILABLE Compressed: NO Tag: TAG20120315T134813 Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1ON5UH0T_1_1

List of Archived Logs in backup set 52

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 9 632972 15-3月 -12 632997 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

54 9M DISK 00:00:03 15-3月 -12

BP Key: 54 Status: AVAILABLE Compressed: NO Tag: TAG20120315T144818 Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1

List of Archived Logs in backup set 54

Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ---------- ---------- ---------

1 8 632557 15-3月 -12 632972 15-3月 -12 1 9 632972 15-3月 -12 632997 15-3月 -12 1 10 632997 15-3月 -12 635746 15-3月 -12

BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ---------------

56 1M DISK 00:00:01 15-3月 -12

BP Key: 56 Status: AVAILABLE Compressed: NO Tag: TAG20120315T144818 Piece Name: F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1SN5UKHM_1_1

List of Archived Logs in backup set 56

Thrd Seq Low SCN Low Time Next SCN Next Time

80 / 88

RMAN增量恢复测试记录

---- ------- ---------- ---------- ---------- ---------

1 11 635746 15-3月 -12 637566 15-3月 -12

分析说明:由以上输出可以看出,从第一次增量备份开始到第二次增量备份中间一次事物,包括的归档日志为:8-11。那么接下来我们就恢复8到11 的归档日志。

3.5.4、按日志序列号恢复归档日志

RMAN> restore archivelog from logseq 8 until logseq 11;

Starting restore at 28-3月 -12

using target database controlfile instead of recovery catalog allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK allocated channel: ORA_DISK_2

channel ORA_DISK_2: sid=158 devtype=DISK

channel ORA_DISK_1: starting archive log restore to default destination channel ORA_DISK_2: starting archive log restore to default destination channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=8

channel ORA_DISK_2: restoring archive log archive log thread=1 sequence=11

channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=9

channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=10

channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1SN5UKHM_1_1 tag=TAG20120315T1448 18

channel ORA_DISK_2: restore complete

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1 tag=TAG20120315T1448 18

channel ORA_DISK_1: restore complete Finished restore at 28-3月 -12

RMAN>

81 / 88

RMAN增量恢复测试记录

3.5.5、按日志序列号恢复数据库

RMAN> recover database until sequence 12;

Starting recover at 29-3月 -12 using channel ORA_DISK_1 using channel ORA_DISK_2

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_2: starting incremental datafile backupset restore channel ORA_DISK_2: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1MN5UGVQ_1_1 tag=TAG20120315T1347 37

(说明:第一次增量备份数据文件对应的备份片——通道1) channel ORA_DISK_1: restore complete

channel ORA_DISK_2: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1NN5UGVQ_1_1 tag=TAG20120315T1347 37

(说明:第一次增量备份数据文件对应的备份片——通道2)

channel ORA_DISK_2: restore complete

starting media recovery

archive log thread 1 sequence 9 is already on disk as file F:\\ARCH\\ARC00009_0777 986699.001

archive log thread 1 sequence 10 is already on disk as file F:\\ARCH\\ARC00010_077 7986699.001

archive log thread 1 sequence 11 is already on disk as file F:\\ARCH\\ARC00011_077 7986699.001

archive log filename=F:\\ARCH\\ARC00009_0777986699.001 thread=1 sequence=9

82 / 88

RMAN增量恢复测试记录

archive log filename=F:\\ARCH\\ARC00010_0777986699.001 thread=1 sequence=10 archive log filename=F:\\ARCH\\ARC00011_0777986699.001 thread=1 sequence=11 media recovery complete

Finished recover at 29-3月 -12

3.5.6、打开数据库,并验证数据

SQL> alter database open resetlogs;

Database altered.

SQL> select * from user1.name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx 4 wyk 5 zy 6 sms 7 wfq 8 zl

8 rows selected.

3.5.7、恢复测试小结

通过以上测试可知,数据并没有恢复到第二次增量备份的中间的那个事物的时间点,而是恢复到了第三个事物的时间点。为什么呢?因为我们中间那个事物也是包含在归档日志序列为11 的redo 中的,而基于日志序列号的恢复是会前滚到日志的末尾,所以我们看到的数据还是最后一次事物的数据状态。那我们查询一下归档日志10所对应的终止时间是多少,看看恢复到归档日志10时的数据状态是怎样的。

补充测试:

查询RMAN备份日志,确定时间: 例:

83 / 88

RMAN增量恢复测试记录

input archive log thread=1 sequence=11 recid=56 stamp=777998772

(对应时间大约为:777998772+553795200=1331793972,即当时的unix 时间戳为:1331793972,转换为北京时间就是:2012年3月15日 14:46:12,也就是说归档日志序列11生产的时间为2012年3月15日 14:46:12)

input archive log thread=1 sequence=12 recid=57 stamp=777998898 (对应时间大约为:777998898+553795200=1331793972,即当时的unix 时间戳为:1331794098,转换为北京时间就是:2012年3月15日 14:48:18)

声明:关于归档日志时间戳换算为北京时间,我并未在网上找到任何资料,以上oracle归档日志时间戳和unix 时间戳的差值553795200是我通过测试计算出来的,并非出自官方文档,仅供大家学习和研究时参考。

1)查询归档日志10所对应的时间

这里我们之间采用上面我们介绍的unix 时间戳转换方法进行转换

input archive log thread=1 sequence=10 recid=55 stamp=777996028

777996028+553795200= 1331791228,即2012年3月15日 14:00:28

其实这个时间是在第一次增量备份之后,第二次增量备份之前,如果恢复到归档日志10,那么数据对应的应该是第一次增量备份时的数据状态,我们来验证一下。

2)恢复数据库

首先启动数据库到nomount状态 SQL> startup nomount; ORACLE instance started.

Total System Global Area 171966464 bytes Fixed Size 787988 bytes Variable Size 145488364 bytes Database Buffers 25165824 bytes Redo Buffers 524288 bytes

执行RMAN 脚本,进行恢复 RMAN> @f:\\restore2.rman

RMAN> run 2> {

84 / 88

RMAN增量恢复测试记录

3> restore controlfile from 'F:\\BAK\\CTL-PF\\ORCL_CTF_BAK_C-1294617127-20120315-04 ';

4> sql 'alter database mount'; 5> set until sequence 11; 6> restore database; 7> recover database;

8> sql 'alter database open resetlogs'; 9> }

Starting restore at 29-3月 -12

using target database controlfile instead of recovery catalog allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK

channel ORA_DISK_1: restoring controlfile channel ORA_DISK_1: restore complete

output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL01.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL02.CTL output filename=E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\CONTROL03.CTL Finished restore at 29-3月 -12

sql statement: alter database mount

executing command: SET until clause

Starting restore at 29-3月 -12

Starting implicit crosscheck backup at 29-3月 -12 released channel: ORA_DISK_1 allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=159 devtype=DISK Crosschecked 24 objects

Finished implicit crosscheck backup at 29-3月 -12

Starting implicit crosscheck copy at 29-3月 -12 using channel ORA_DISK_1 Crosschecked 1 objects

Finished implicit crosscheck copy at 29-3月 -12

searching for all files in the recovery area cataloging files... cataloging done

no files cataloged

using channel ORA_DISK_1

85 / 88

RMAN增量恢复测试记录

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00002 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\UNDOTBS01.DBF restoring datafile 00003 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSAUX01.DBF restoring datafile 00005 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\EXAMPLE01.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1GN5UFIU_1_1 tag=TAG20120315T1323 42

channel ORA_DISK_1: restore complete

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\SYSTEM01.DBF restoring datafile 00004 to E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL\\USERS01.DBF restoring datafile 00006 to F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1FN5UFIU_1_1 tag=TAG20120315T1323 42

channel ORA_DISK_1: restore complete Finished restore at 29-3月 -12

Starting recover at 29-3月 -12 using channel ORA_DISK_1

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00001: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSTEM01.DBF

destination for restore of datafile 00004: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\USERS01.DBF

destination for restore of datafile 00006: F:\\ORADATA2\\TABLESPACE1.DBF channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1MN5UGVQ_1_1 tag=TAG20120315T1347 37

channel ORA_DISK_1: restore complete

channel ORA_DISK_1: starting incremental datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set

destination for restore of datafile 00002: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\UNDOTBS01.DBF

destination for restore of datafile 00003: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\SYSAUX01.DBF

destination for restore of datafile 00005: E:\\ORACLE\\PRODUCT\\10.1.0\\ORADATA\\ORCL \\EXAMPLE01.DBF

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT2\\ORCL_DATAFILE_BAK_1NN5UGVQ_1_1 tag=TAG20120315T1347

86 / 88

RMAN增量恢复测试记录

37

channel ORA_DISK_1: restore complete

starting media recovery

channel ORA_DISK_1: starting archive log restore to default destination channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=9

channel ORA_DISK_1: restoring archive log archive log thread=1 sequence=10

channel ORA_DISK_1: restored backup piece 1

piece handle=F:\\BAK\\DATA\\DT1\\ORCL_DATAFILE_BAK_1QN5UKHI_1_1 tag=TAG20120315T1448 18

channel ORA_DISK_1: restore complete

archive log filename=F:\\ARCH\\ARC00009_0777986699.001 thread=1 sequence=9 archive log filename=F:\\ARCH\\ARC00010_0777986699.001 thread=1 sequence=10 media recovery complete

Finished recover at 29-3月 -12

sql statement: alter database open resetlogs

RMAN> **end-of-file**

3)验证数据

SQL> select * from user1.name;

ID NAME ---------- -------------------- 1 zxk 2 wxh 3 zyx

说明:可见数据确实是第一次增量备份时是的数据状态

87 / 88

RMAN增量恢复测试记录

三、测试总结

通过以上测试,主要是为了说明和验证以下几点:

1、RMAN 如何进行各种方式的恢复,包括基于任意时间点、SCN、归档日志序列号等。 2、Oracle 如何通过比较SCN进行数据库的实例恢复或介质恢复。 3、如何通过RMAN日志或备份集获取备份时的SCN和时间点信息。

4、Oracle 的增量恢复时,会优先选择增量备份集去恢复,而不会去找归档日志进行恢复。 5、在某个增量备份集丢失的情况下,如何利用后续的归档日志进行数据库的恢复。

6、在数据文件的恢复阶段,可以不用指定时间点和SCN的限制,时间点和SCN的限制直接放在recover 阶段指定就行了。

7、在进行增量恢复时,即使中间某个增量备份的归档日志丢失,也能够正常的进行恢复 8、基于归档日志序列号的数据库恢复只能恢复到日志的末尾,无法恢复到中间的某次事物

88 / 88

因篇幅问题不能全部显示,请点此查看更多更全内容