ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 无处不在的Oracle数据库控制文件备份

无处不在的Oracle数据库控制文件备份

原创 Linux操作系统 作者:尛样儿 时间:2012-05-03 12:17:06 0 删除 编辑
        Oracle数据库控制文件的存在对于Oracle数据库恢复来说是很重要的,基于此Oracle控制文件的备份是无处不在的。下面我们来详细讨论Oracle控制文件存在的备份:

1.RMAN自动备份控制文件。

1).启用控制文件自动备份:

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

2).控制文件自动备份:
RMAN> backup device type disk format '/tmp/%U' datafile 4;

Starting backup at 2012-01-13 09:50:40
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA1/ractest/datafile/users.259.769378773
channel ORA_DISK_1: starting piece 1 at 2012-01-13 09:50:40
channel ORA_DISK_1: finished piece 1 at 2012-01-13 09:50:41
piece handle=/tmp/0bn0lb3g_1_1 tag=TAG20120113T095040 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-01-13 09:50:41

Starting Control File and SPFILE Autobackup at 2012-01-13 09:50:41
piece handle=/u01/app/oracle/product/11.2.0/db_1/dbs/c-3297696735-20120113-01 comment=NONE
Finished Control File and SPFILE Autobackup at 2012-01-13 09:50:48

        c-3297696735-20120113-01文件是RMAN自动备份的控制文件,该文件位于$ORACLE_HOME/dbs目录下,存放在该目录下能够避免存储的损坏带来的所有备份控制文件的丢失。该文件的名称中c是control的缩写,3297696735是DBID,20120113是日期,01是序号:
SQL> select dbid from v$database;

      DBID
----------
3297696735

SQL> select to_char(sysdate,'yyyymmdd') from dual;

TO_CHAR(
--------
20120113

        控制文件的备份是非常小的,打开RMAN对控制文件的自动备份基本不会带来问题。

2.控制文件快照。
1).执行备份操作:
RMAN> backup device type disk format '/tmp/%U' datafile 4;

Starting backup at 2012-01-13 10:21:52
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA1/ractest/datafile/users.259.769378773
channel ORA_DISK_1: starting piece 1 at 2012-01-13 10:21:53
channel ORA_DISK_1: finished piece 1 at 2012-01-13 10:21:54
piece handle=/tmp/0kn0lcu0_1_1 tag=TAG20120113T102152 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-01-13 10:21:54

Starting Control File and SPFILE Autobackup at 2012-01-13 10:21:54
piece handle=/u01/app/oracle/product/11.2.0/db_1/dbs/c-3297696735-20120113-03 comment=NONE
Finished Control File and SPFILE Autobackup at 2012-01-13 10:22:01

2).查看控制文件快照的生成时间:
[oracle@rhel1 dbs]$ ls sna* --full-time|awk '{print $6,$7}'
2012-01-13 10:21:57.000000000
       
        从上面的输出可以看出在控制文件和SPFILE备份的时候会产生一个新的控制文件快照,控制文件快照同样可用于数据库的恢复。


3.无处不在的控制文件快照。
       
        下面的操作是在关闭了RMAN控制文件自动备份的情况下执行的。

1).使用RMAN执行备份操作:
RMAN> backup device type disk format '/tmp/%U' database skip offline;

Starting backup at 2012-01-13 10:11:56
using channel ORA_DISK_1
skipping offline file 7
RMAN-06060: WARNING: skipping datafile compromises tablespace TEST recoverability
RMAN-06060: WARNING: skipping datafile compromises tablespace TEST recoverability
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA1/ractest/datafile/system.256.769378761
input datafile file number=00002 name=+DATA1/ractest/datafile/sysaux.257.769378769
input datafile file number=00003 name=+DATA1/ractest/datafile/undotbs1.258.769378771
input datafile file number=00005 name=+DATA1/ractest/datafile/undotbs2.264.769379825
input datafile file number=00004 name=+DATA1/ractest/datafile/users.259.769378773
input datafile file number=00006 name=+OCR_DATA2/ractest/datafile/test.256.771175117
channel ORA_DISK_1: starting piece 1 at 2012-01-13 10:11:57
channel ORA_DISK_1: finished piece 1 at 2012-01-13 10:14:30
piece handle=/tmp/0hn0lcbd_1_1 tag=TAG20120113T101156 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:33
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2012-01-13 10:14:33
channel ORA_DISK_1: finished piece 1 at 2012-01-13 10:14:34
piece handle=/tmp/0in0lcg6_1_1 tag=TAG20120113T101156 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-01-13 10:14:34

2).查看控制文件快照生成的时间:
[oracle@rhel1 dbs]$ ls sna* --full-time|awk '{print $6,$7}'
2012-01-13 10:14:33.000000000

       在对database执行备份的时候,即使没有打开RMAN对控制文件的自动备份,RMAN也会自动备份控制文件和SPFILE到备份片,但是该备份片与备份存放在一起,而非存放在$ORACLE_HOME/dbs目录下,且在备份控制文件和SPFILE文件前会新生成一个控制文件快照。
         
         请注意,如果打开了RMAN对控制文件的自动备份,那么在对database执行备份的时候就不会再像上面那样自动备份控制文件和SPFILE文件到备份片。


总结:
        从上面的例子可以看出,Oracle控制文件真是无处不在,丢失控制文件的情况可以说很难发生,即使丢失我们也可以通过其他方法来恢复数据库,请参考文章:http://space.itpub.net/23135684/viewspace-711883。另外,在数据结构发生变化或备份脚本中使用ALTER DATABASE BACKUP CONTROLFILE命令备份控制文件也是可以考虑的方法。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23135684/viewspace-722617/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
Oracle数据库管理员,Oracle数据库系统构架员;2012年7月出版《构建最高可用Oracle数据库系统:Oracle 11gR2 RAC管理、维护与性能优化》一书;Oracle 10g OCM。

注册时间:2010-01-05

  • 博文量
    483
  • 访问量
    5239867