2013年(350)
分类: Oracle
2013-04-27 17:06:26
基本上,RAC下创建备份任务,备份语句是不需要做什么修改的,只要前面的准备工作都做好了(主要是归档文件),那么备份是会很顺畅的。
首先来举个例子,默认情况下直接执行备份,通过连接到任意结点执行,这里我们在节点2端执行备份操作:
[oracle@jssdbn 2 ~]$ rman target /
Recovery Manager: Release 10.2.0.4.0 - Production on T hu Jan 2 11: 1 4:19 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: JSSDB (DBID=953576437)
RMAN> run{
2> allocate channel c0 device type disk format ¨/data/%U¨;
3> backup database plus archivelog ;
4> }
allocated channel: c0
channel c0: sid=146 instance=jssdbn2 devtype=DISK
.............................
.............................
RMAN-03002: failure of backup plus archivelog command at 01/28/2010 11:17:07
RMAN-06059: expected archived log not found, lost of archived log compromises recoverability
ORA-19625: error identifying file /data/oradata/jssdbn1/archivelog/1_214_703671669.dbf
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3从提示信息可以清晰的看出,错误的原因是找不到指定的归档文件。实际上这里的缺少不是没有,而是说执行备份的节点上找不到这个归档,遇到这种问题,就可以按照1.2小节中提示的方法进行处理。
问题处理完之后,再次执行相同的备份脚本:
RMAN> run{
2> allocate channel c0 device type disk format ¨/data/backup/%U¨;
3> backup database plus archivelog ;
4> }
using target database control file instead of recovery catalog
allocated channel: c0
channel c0: sid=147 instance=jssdbn2 devtype=DISK
Starting backup at 28-JAN-10
current log archived
archived log /data/oradata/jssdbn1/archivelog/1_214_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 214
archived log /data/oradata/jssdbn1/archivelog/1_215_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 215
archived log /data/oradata/jssdbn1/archivelog/1_216_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 216
archived log /data/oradata/jssdbn1/archivelog/1_217_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 217
archived log /data/oradata/jssdbn1/archivelog/1_218_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 218
archived log /data/oradata/jssdbn1/archivelog/1_219_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 219
archived log /data/oradata/jssdbn1/archivelog/1_220_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 220
archived log /data/oradata/jssdbn1/archivelog/1_221_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 221
archived log /data/oradata/jssdbn1/archivelog/1_222_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 222
archived log /data/oradata/jssdbn1/archivelog/2_80_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 2, sequence 80
channel c0: starting archive log backupset
channel c0: specifying archive log(s) in backup set
input archive log thread=1 sequence=214 recid=15 stamp=709470986
input archive log thread=1 sequence=215 recid=16 stamp=709470986
input archive log thread=1 sequence=216 recid=17 stamp=709470986
input archive log thread=1 sequence=217 recid=18 stamp=709470986
input archive log thread=1 sequence=218 recid=10 stamp=709386699
input archive log thread=1 sequence=219 recid=8 stamp=709377003
input archive log thread=1 sequence=220 recid=13 stamp=709470839
input archive log thread=1 sequence=221 recid=20 stamp=709471027
input archive log thread=1 sequence=222 recid=24 stamp=709471178
input archive log thread=2 sequence=80 recid=22 stamp=709471126
input archive log thread=2 sequence=81 recid=6 stamp=709351223
input archive log thread=2 sequence=82 recid=11 stamp=709423258
input archive log thread=2 sequence=83 recid=12 stamp=709470834
input archive log thread=2 sequence=84 recid=19 stamp=709471026
input archive log thread=2 sequence=85 recid=23 stamp=709471176
channel c0: starting piece 1 at 28-JAN-10
channel c0: finished piece 1 at 28-JAN-10
piece handle=/data/backup/01l4jaui_1_1 tag=TAG20100128T111946 comment=NONE
channel c0: backup set complete, elapsed time: 00:00:16
Finished backup at 28-JAN-10
Starting backup at 28-JAN-10
channel c0: starting full datafile backupset
channel c0: specifying datafile(s) in backupset
input datafile fno=00003 name=+ASMDISK1/jssdb/datafile/sysaux.266.703671697
input datafile fno=00001 name=+ASMDISK1/jssdb/datafile/system.260.703671683
input datafile fno=00002 name=+ASMDISK1/jssdb/datafile/undotbs1.259.703671695
input datafile fno=00004 name=+ASMDISK1/jssdb/datafile/undotbs2.258.703671705
input datafile fno=00006 name=+ASMDISK1/jssdb/datafile/jsstbs.269.703779631
input datafile fno=00005 name=+ASMDISK1/jssdb/datafile/users.257.703671709
channel c0: starting piece 1 at 28-JAN-10
channel c0: finished piece 1 at 28-JAN-10
piece handle=/data/backup/02l4jav5_1_1 tag=TAG20100128T112005 comment=NONE
channel c0: backup set complete, elapsed time: 00:00:25
channel c0: starting full datafile backupset
channel c0: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel c0: starting piece 1 at 28-JAN-10
channel c0: finished piece 1 at 28-JAN-10
piece handle=/data/backup/03l4javu_1_1 tag=TAG20100128T112005 comment=NONE
channel c0: backup set complete, elapsed time: 00:00:03
Finished backup at 28-JAN-10
Starting backup at 28-JAN-10
current log archived
archived log /data/oradata/jssdbn1/archivelog/1_223_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 223
channel c0: starting archive log backupset
channel c0: specifying archive log(s) in backup set
input archive log thread=1 sequence=223 recid=26 stamp=709471235
input archive log thread=2 sequence=86 recid=28 stamp=709471236
channel c0: starting piece 1 at 28-JAN-10
channel c0: finished piece 1 at 28-JAN-10
piece handle=/data/backup/04l4jb05_1_1 tag=TAG20100128T112037 comment=NONE
channel c0: backup set complete, elapsed time: 00:00:02
Finished backup at 28-JAN-10
released channel: c0一切顺利,备份集创建成功。
不过,这里隐含一个问题,通常我们习惯于在备份完归档之后删除原归档文件,以释放相应的磁盘空间,不过在当前这个情况下,如果你尝试清除归档的话,如无意外肯定会报错,例如:
RMAN> delete archivelog sequence 214 thread 1;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=134 instance=jssdbn2 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - --------- ----
15 1 214 A 24-JAN-10 /data/oradata/jssdbn2/archivelog/1_214_703671669.dbf
1 1 214 A 24-JAN-10 /data/oradata/jssdbn1/archivelog/1_214_703671669.dbf
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archive log
archive log filename=/data/oradata/jssdbn2/archivelog/1_214_703671669.dbf recid=15 stamp=709470986
Deleted 1 objects
RMAN-06207: WARNING: 1 objects could not be deleted for DISK channel(s) due
RMAN-06208: to mismatched status. Use CROSSCHECK command to fix status
RMAN-06210: List of Mismatched objects
RMAN-06211: ==========================
RMAN-06212: Object Type Filename/Handle
RMAN-06213: --------------- ---------------------------------------------------
RMAN-06214: Archivelog /data/oradata/jssdbn1/archivelog/1_214_703671669.dbf节点2端的归档成功删除,可是节点1端生成的归档删除报错,觉着奇怪吗?其实如果你稍稍开动一下脑筋,随便动用几十万亿个脑细胞就肯定能想明白这个事儿,没错,这里报错的原来就是节点2上操作不了节点1中的" /data/oradata/jssdbn1/archivelog/1_214_703671669.dbf " 这个文件,你想说到节点1端去删除?那也会有问题,因为节点1又操作不了节点2上的" /data/oradata/jssdbn2/archivelog/1_214_703671669.dbf " 这个文件,咋整?我有办法,用家乐浓汤宝吧,三碗水,一个鸡汤口味。。。。Oo对不起对不起,最近广告看多了。我真正想说的是,用RMAN中的通道吧。
插播内容:配置多通道连接不同实例,认真看,不是广告。
可以通过configure预配置几个通道(一般有几个实例就配几个通道),用来连接相应的实例,命令行如下:
RMAN> configure channel 1 device type disk connect ¨sys/123456@jssdbn1¨;
new RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK CONNECT ¨*¨;
new RMAN configuration parameters are successfully stored
released channel: ORA_DISK_1
RMAN> configure channel 2 device type disk connect ¨sys/123456@jssdbn2¨;
new RMAN configuration parameters:
CONFIGURE CHANNEL 2 DEVICE TYPE DISK CONNECT ¨*¨;
new RMAN configuration parameters are successfully storedConfigure channel 大家应该看着眼熟,有不认识的建议重温"" ,或者浏览"" ,关于connect子句简单解释两句,后跟目标实例的用户名密码及网络服务名,这个网络服务名要确保执行备份的节点中确实进行了配置哟,不然该通道连接时肯定就会报错了。
配置完成之后,查看当前通道配置情况,应显示如下:
RMAN> show channel;
RMAN configuration parameters are:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK CONNECT ¨*¨;
CONFIGURE CHANNEL 2 DEVICE TYPE DISK CONNECT ¨*¨;而且这种方式还有一个好处,就是RMAN能够智能的对备份中出现"问题"的任务进行再分配,比如说通道1和通道2同时执行备份,其中通道1备份数据文件134,通道2备份数据文件2和5,假如通道2执行过程中由于某些原因崩溃,RMAN可以自动将任务放回到通道1上执行。
接下来,还有很重要的一步,启动并行,并且至少要启动"节点数量"个并行度。这样的目的是为了RMAN在分配任务时,自动至少启动多个通道并连接到相应的实例上,操作如下,例如我们这里的双节点RAC,就配置2个并行度:
RMAN> configure device type disk parallelism 2;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored
released channel: ORA_DISK_1这样,当执行RMAN任务时,它就会根据任务所需,自动分配通道连接到适当实例,执行适当的操作。例如,再将从节点2端删除214序号的归档文件,操作如下:
RMAN> delete archivelog sequence 214;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=130 instance=jssdbn1 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=152 instance=jssdbn2 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - --------- ----
1 1 214 A 24-JAN-10 /data/oradata/jssdbn1/archivelog/1_214_703671669.dbf
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archive log
archive log filename=/data/oradata/jssdbn1/archivelog/1_214_703671669.dbf recid=1 stamp=709219728
Deleted 1 objects成功删除,这个成功也体现了分配通道后RMAN的智能,它会根据配置给不同的通道分配不同的任务,这样也就不用担心节点路径不同导致删除任务的失败了。
路障基本扫除,下面综合来测试一下,执行脚本如下:
RMAN> run{
allocate channel c0 device type disk format ¨/data/backup/%U¨;
backup database plus archivelog;
release channel c0;
}
allocated channel: c0
channel c0: sid=144 instance=jssdbn2 devtype=DISK
Starting backup at 03-FEB-10
current log archived
archived log /data/oradata/jssdbn1/archivelog/1_224_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 224
archived log /data/oradata/jssdbn1/archivelog/1_225_703671669.dbf not found or out of sync with catalog
.....................
........................
trying alternate file for archivelog thread 1, sequence 237
archived log /data/oradata/jssdbn1/archivelog/2_88_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 2, sequence 88
channel c0: starting archive log backupset
channel c0: specifying archive log(s) in backup set
input archive log thread=1 sequence=224 recid=64 stamp=709997627
input archive log thread=1 sequence=225 recid=65 stamp=709997630
............................
...............................
input archive log thread=2 sequence=97 recid=66 stamp=709997682
channel c0: starting piece 1 at 03-FEB-10
channel c0: finished piece 1 at 03-FEB-10
piece handle=/data/backup/05l53d3s_1_1 tag=TAG20100203T133451 comment=NONE
channel c0: backup set complete, elapsed time: 00:00:36
Finished backup at 03-FEB-10
Starting backup at 03-FEB-10
channel c0: starting full datafile backupset
channel c0: specifying datafile(s) in backupset
input datafile fno=00003 name=+ASMDISK1/jssdb/datafile/sysaux.266.703671697
input datafile fno=00001 name=+ASMDISK1/jssdb/datafile/system.260.703671683
input datafile fno=00002 name=+ASMDISK1/jssdb/datafile/undotbs1.259.703671695
input datafile fno=00004 name=+ASMDISK1/jssdb/datafile/undotbs2.258.703671705
input datafile fno=00006 name=+ASMDISK1/jssdb/datafile/jsstbs.269.703779631
input datafile fno=00005 name=+ASMDISK1/jssdb/datafile/users.257.703671709
channel c0: starting piece 1 at 03-FEB-10
channel c0: finished piece 1 at 03-FEB-10
piece handle=/data/backup/06l53d53_1_1 tag=TAG20100203T133531 comment=NONE
channel c0: backup set complete, elapsed time: 00:00:25
channel c0: starting full datafile backupset
channel c0: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel c0: starting piece 1 at 03-FEB-10
channel c0: finished piece 1 at 03-FEB-10
piece handle=/data/backup/07l53d5s_1_1 tag=TAG20100203T133531 comment=NONE
channel c0: backup set complete, elapsed time: 00:00:03
Finished backup at 03-FEB-10
Starting backup at 03-FEB-10
current log archived
archived log /data/oradata/jssdbn1/archivelog/1_238_703671669.dbf not found or out of sync with catalog
trying alternate file for archivelog thread 1, sequence 238
channel c0: starting archive log backupset
channel c0: specifying archive log(s) in backup set
input archive log thread=1 sequence=238 recid=70 stamp=709997762
input archive log thread=2 sequence=98 recid=69 stamp=709997760
channel c0: starting piece 1 at 03-FEB-10
channel c0: finished piece 1 at 03-FEB-10
piece handle=/data/backup/08l53d64_1_1 tag=TAG20100203T133604 comment=NONE
channel c0: backup set complete, elapsed time: 00:00:02
Finished backup at 03-FEB-10
released channel: c0然后执行命令删除所有已备份过的归档文件,因为有默认通道的存在,因此这里可以不用再分配通道了,直接执行如下:
RMAN> delete noprompt archivelog all backed up 1 times to device type disk;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=127 instance=jssdbn1 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=128 instance=jssdbn2 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - --------- ----
64 1 224 A 28-JAN-10 /data/oradata/jssdbn2/archivelog/1_224_703671669.dbf
.......................................
.........................................
66 2 97 A 03-FEB-10 /data/oradata/jssdbn2/archivelog/2_97_703671669.dbf
69 2 98 A 03-FEB-10 /data/oradata/jssdbn2/archivelog/2_98_703671669.dbf
deleted archive log
archive log filename=/data/oradata/jssdbn1/archivelog/1_224_703671669.dbf recid=30 stamp=709542410
deleted archive log
archive log filename=/data/oradata/jssdbn1/archivelog/1_225_703671669.dbf recid=32 stamp=709542491
.......................................
.........................................
deleted archive log
archive log filename=/data/oradata/jssdbn2/archivelog/2_97_703671669.dbf recid=66 stamp=709997682
deleted archive log
archive log filename=/data/oradata/jssdbn2/archivelog/2_98_703671669.dbf recid=69 stamp=709997760
Deleted 27 objects竣工!其它就不说了,上述执行的脚本为RMAN备份的最核心脚本,实际使用时可在此基本上进行相应的补充,比如增加备份类型、通道的设置、验证备份集、清除过期备份、日志输出等等操作。这部分相关知识已有专门论述,在此不再重复,感兴趣的朋友可以参考三思的著作“” 一书第七章和第八章。