2013年(350)
分类: Oracle
2013-04-10 11:32:11
===========================================================================
对于备份集(或备份片段),RMAN直接提供了方式支持定义备份片段的文件名、备份片段大小及备份集标签。
默认情况下执行 BACKUP 命令进行备份时不需要为备份片段指定名称,RMAN会自动为每个备份片段生成一个唯一的名称,相当先进是吧,其实RMAN没有这么智能,之所于默认情况下也能确保生成的文件名唯一,是因为RMAN默认通道分配时指定了一个参数值为%F的FORMAT参数。
FORMAT 参数的使用也非常灵活,你既可以分配通道时指定该参数,也可以在执行备份命令时指定,例如:
分配通道时指定备份片段命名格式:
RMAN> RUN {
2> ALLOCATE CHANNEL C1 DEVICE TYPE DISK FORMAT ' f:\oracle\backup\cn_%U ' ;
3> BACKUP TABLESPACE USERS;
4> }
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=142 devtype=DISK
Starting backup at 14-APR-09
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
input datafile fno=00004 name=F:\ORACLE\ORADATA\JSSBOOK\USERS01.DBF
channel c1: starting piece 1 at 14-APR-09
channel c1: finished piece 1 at 14-APR-09
piece handle=F:\ORACLE\BACKUP\CN_0UKCFQH7_1_1 tag=TAG20090414T205047 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:02
Finished backup at 14-APR-09
released channel: c1
执行备份命令时指定备份片段命名格式:
RMAN> BACKUP TABLESPACE USERS FORMAT 'f:\oracle\backup\cn_%U' ;
Starting backup at 15-APR-09
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00004 name=F:\ORACLE\ORADATA\JSSWEB\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 15-APR-09
channel ORA_DISK_1: finished piece 1 at 15-APR-09
piece handle=F:\ORACLE\BACKUP\CN_07KCHO6S_1_1 tag=TAG20090415T142324 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-APR-09友情提示:更多关于FORMAT参数的详细说明请参考本章外传。
备份时可以直接给备份集指定一个名称,RMAN管这个叫TAG,实际上每个备份集都有TAG标签,不过这个东西并不是必须指定,如果你在执行备份操作时没有指定TAG,RMAN会按照自己的规则为该备份集生成TAG标签(默认格式为:TAG yyyymmdd T hhmmss ,TAG和T是固定字符, yyyymmddhhmmss 对应执行备份操作的时间)。
当然自己指定也可以,语法非常简单,执行备份命令时指定 TAG 关键字后跟一个名字,注意名称的长度不要超过30个字符,例如:
RMAN> BACKUP TABLESPACE USERS TAG TBS_USERSBAK;
Starting backup at 14-APR-09
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=149 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00004 name=F:\ORACLE\ORADATA\JSSBOOK\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 14-APR-09
channel ORA_DISK_1: finished piece 1 at 14-APR-09
piece handle=F:\ORACLE\BACKUP\BAK_0SKCELJ9_1_1 tag=TBS_USERSBAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 14-APR-09TAG 标签也可以视为备份集的别名,如果你的备份策略设计得足够用心,并且你对其也足够熟悉,理论上TAG还是能起到一定作用,比如执行RESTORE/CHANGE命令时就可以通过指定TAG标签来限定具体的备份集了。
在默认情况下,一种类型的文件在备份集中都会存成一个备份片段。不过考虑到如果文件较大,生成的备份片段可能也较大,甚至超出操作系统限制(不稀奇,比如Windows平台下FAT32文件系统,单个文件最大不能超过4GB),鉴于一名优秀DBA必须具备的全面考虑问题的能力,在你真正创建备份策略之前,备份片段文件大小显然也得在考虑范围之内。
RMAN 在分配通道时有一个参数MAXPIECESIZE,就是专门用来指定备份片段大小的,例如,备份SYSTEM表空间,指定单个备份片段最大不能超过10MB:
RMAN> RUN {
2> ALLOCATE CHANNEL C1 DEVICE TYPE DISK MAXPIECESIZE =10m FORMAT ' f:\oracle\backup\bak_%U ' ;
3> BACKUP TABLESPACE SYSTEM;
4> }
allocated channel: c1
channel c1: sid=140 devtype=DISK
Starting backup at 13-APR-09
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
input datafile fno=00001 name=F:\ORACLE\ORADATA\JSSBOOK\SYSTEM01.DBF
channel c1: starting piece 1 at 13-APR-09
channel c1: finished piece 1 at 13-APR-09
piece handle=F:\ORACLE\BACKUP\BAK_0QKCDDGU_1_1 tag=TAG20090413T225630 comment=NONE
channel c1: starting piece 2 at 13-APR-09
channel c1: finished piece 2 at 13-APR-09
piece handle=F:\ORACLE\BACKUP\BAK_0QKCDDGU_2_1 tag=TAG20090413T225630 comment=NONE
channel c1: starting piece 3 at 13-APR-09
channel c1: finished piece 3 at 13-APR-09
......
channel c1: starting piece 13 at 13-APR-09
channel c1: finished piece 13 at 13-APR-09
piece handle=F:\ORACLE\BACKUP\BAK_0QKCDDGU_13_1 tag=TAG20090413T225630 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:22
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel c1: starting piece 1 at 13-APR-09
channel c1: finished piece 1 at 13-APR-09
piece handle=F:\ORACLE\BACKUP\BAK_0RKCDDHK_1_1 tag=TAG20090413T225630 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:02
Finished backup at 13-APR-09
released channel: c1在F:\oracle\backup 目录中查看会发现共生成了14个文件,其中1个为自动创建的控制文件备份,其他13个就是 SYSTEM 表空间的备份片段实际指向文件,每个文件均不超过10MB。
使用 LIST BACKUP OF TABLESPACE 命令查看,也能确认这点:
RMAN> LIST BACKUP OF TABLESPACE SYSTEM;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
23 Full 129.36M DISK 00:00:20 13-APR-09
List of Datafiles in backup set 23
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 719880 13-APR-09 F:\ORACLE\ORADATA\JSSBOOK\SYSTEM01.DBF
Backup Set Copy #1 of backup set 23
Device Type Elapsed Time Completion Time Compressed Tag
----------- ------------ --------------- ---------- ---
DISK 00:00:20 13-APR-09 NO TAG20090413T225630
List of Backup Pieces for backup set 23 Copy #1
BP Key Pc# Status Piece Name
------- --- ----------- ----------
35 1 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_1_1
36 2 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_2_1
37 3 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_3_1
38 4 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_4_1
39 5 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_5_1
40 6 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_6_1
41 7 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_7_1
42 8 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_8_1
43 9 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_9_1
44 10 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_10_1
45 11 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_11_1
46 12 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_12_1
47 13 AVAILABLE F:\ORACLE\BACKUP\BAK_0QKCDDGU_13_1不仅能够指定备份片段的大小,甚至连备份集的大小也可以指定,单个备份集的最大值可以在执行备份命令(或分配通道)时通过 MAXSETSIZE 参数指定,比如:
MAXSETSIZE 参数指定的是单个备份集的最大值,与备份片段无关,不过默认情况下,一个备份集对应一个备份片段,因此也相当于指定了备份片段的大小,但是直接指定 MAXSETSIZE 参数限定备份集大小并非在所有情况下都适用,如果要备份的数据文件中,任意一个数据文件超出了指定参数值,则备份就会失败(前面示例命令执行肯定失败,因为默认情况下 SYSTEM 表空间数据文件就接近300MB)。因此,对于在实际应用中需要限制生成文件大小的情况,更多还是会通过 MAXPIECESIZE 参数限制备份片段,而不会直接限制备份集。
=================================================