RMan备份之SNAPSHOT CONTROLFILE(原创)

在用RMAN备份是时候,系统会自动备份一份 SNAPSHOT CONTROLFILE,我们来看看这个 SNAPSHOT CONTROLFILE 到底有什么用途,有如下文档
RMAN needs to get a consistent view of the control file when it sets out to make backup of every datafile. It only needs to know the most recent checkpoint information and file schematic information at the time backup begins. After the backup starts, RMAN needs this information to stay consistent for duration of the backup operation; in other words, it needs a read consistent view of the control file. With the constant updates from the database, this is nearly impossible - unless RMAN were to lock the control file for the duration of the backup. But that would mean the database could not advance checkpoint or switch logs or produce new archive logs. Impossible.
To get around this, RMAN uses the snapshot control file, an exact copy of your control file that is only used by RMAN during backup and resync operations. At the beginning of these operations, RMAN refreshes the snapshot control file from the actual control file, thus putting a momentary lock on the control file. Then, RMAN switches to the snapshot and uses it for the duration of the backup; in this way, it has read consistency without holding up database activity.
根据我的理解:
snapshot control file只有在同步catalog的时候用到或者在控制文件备份的时候用到,主要作用是在备份控制文件是代替控制文件,使得rman在备份控制文件时能够锁定控制文件从而保证控制文件的一致性。
----------------------------------------------------------
SNAPSHOT CONTROLFILE 的用途,顾名思义,应该是用来恢复控制文件的,下面是我的测试结果:
结论是:
1.SNAPSHOT CONTROLFILE 能直接copy成control file也能通过rman恢复为control file
2.可以通过rman,将SNAPSHOT CONTROLFILE 恢复成控制文件
3.如果数据库没有shutdown,可以直接copy SNAPSHOT CONTROLFILE 成控制文件,但仍需要恢复(因为他是旧的)
下面是演示通过copy snapshot controlfile进行控制文件恢复的测试步骤:
---------------------------------------
查看snapshot controlfile的备份设置:
RMAN> show snapshot controlfile name;
RMAN configuration parameters are:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_czmmiao.f'; # default

下面模拟控制文件丢失的恢复

$ ls
control01.ctl  example01.dbf  redo01.log  sysaux01.dbf  temp.dbf
control02.ctl  example.dbf    redo02.log  system01.dbf  undotbs01.dbf
control03.ctl  nk_tbs.dbf     redo03.log  temp01.dbf    users01.dbf
$ rm control0*
$ ls
example01.dbf  nk_tbs.dbf  redo02.log  sysaux01.dbf  temp01.dbf  undotbs01.dbf
example.dbf    redo01.log  redo03.log  system01.dbf  temp.dbf    users01.dbf

在控制文件被删除后,数据库还能正常操作:
SQL> create table test(id int);
Table created.
SQL> insert into test values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> alter system checkpoint;
System altered.

重新启动数据库:
SQL> shutdown immediate;
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/czmmiao/control01.ctl'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information:

没有了控制文件了,shutdown immediate出错
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.
Total System Global Area  373293056 bytes
Fixed Size                  1219496 bytes
Variable Size             125830232 bytes
Database Buffers          243269632 bytes
Redo Buffers                2973696 bytes
ORA-00205: error in identifying control file, check alert log for more info

没有控制文件,数据库不能mount,现在把SNAPSHOT CONTROLFILE copy到对应目录
$ cp /u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_czmmiao.f control01.ctl
$ cp control01.ctl control02.ctl
$ cp control01.ctl control03.ctl
将数据库启动到mount状态
SQL> alter database mount;
Database altered.

由于控制文件是“旧”的,所以需要恢复数据库

RMAN> recover database;
Starting recover at 31-OCT-11
Starting implicit crosscheck backup at 31-OCT-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
Crosschecked 14 objects
Finished implicit crosscheck backup at 31-OCT-11
Starting implicit crosscheck copy at 31-OCT-11
using channel ORA_DISK_1
Finished implicit crosscheck copy at 31-OCT-11
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/CZMMIAO/backupset/2011_10_29/o1_mf_ncsnf_TAG20111029T200617_7bqv39wc_.bkp
File Name: /u01/app/oracle/flash_recovery_area/CZMMIAO/archivelog/2011_10_31/o1_mf_1_16_7bwrp8ps_.arc
File Name: /u01/app/oracle/flash_recovery_area/CZMMIAO/archivelog/2011_10_31/o1_mf_1_15_7bwrp6w2_.arc
using channel ORA_DISK_1
datafile 4 not processed because file is read-only
starting media recovery
archive log thread 1 sequence 15 is already on disk as file /u01/app/oracle/flash_recovery_area/CZMMIAO/archivelog/2011_10_31/o1_mf_1_15_7bwrp6w2_.arc
archive log thread 1 sequence 16 is already on disk as file /u01/app/oracle/flash_recovery_area/CZMMIAO/archivelog/2011_10_31/o1_mf_1_16_7bwrp8ps_.arc
archive log thread 1 sequence 17 is already on disk as file /u01/app/oracle/oradata/czmmiao/redo03.log
archive log filename=/u01/app/oracle/flash_recovery_area/CZMMIAO/archivelog/2011_10_31/o1_mf_1_15_7bwrp6w2_.arc thread=1 sequence=15
archive log filename=/u01/app/oracle/flash_recovery_area/CZMMIAO/archivelog/2011_10_31/o1_mf_1_16_7bwrp8ps_.arc thread=1 sequence=16
archive log filename=/u01/app/oracle/oradata/czmmiao/redo03.log thread=1 sequence=17
media recovery complete, elapsed time: 00:00:02
Finished recover at 31-OCT-11

以resetlogs的方式打开数据库
SQL> alter database open resetlogs;
Database altered.

SQL> select * from test;
        ID
----------
         1

数据仍在,恢复成功!
如果希望采用rman方式进行控制文件的恢复,只需要执行如下命令即可

RMAN> restore controlfile from ' /u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_czmmiao.f';

 

参考至:http://jqs.itpub.net/post/140/479103

              https://forums.oracle.com/forums/thread.jspa?threadID=942113

本文原创,转载请注明出处、作者

如有错误,欢迎指正

邮箱:czmcj@163.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值