使用RMAN进行备份时,系统会自动为我们分配一个Channel。Channel的相关属性由两个默认的配置决定。
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
第一个参数用来控制Channel的类型,默认写到磁盘。第二个参数用来控制默认分配几个Channel,也就是控制备份的并行度。
我们调整下PARALLELISM的值,看看备份期间发生了什么变化。
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; 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> BACKUP DATABASE; Starting backup at 2015/07/08 23:34:54 using channel ORA_DISK_1 using channel ORA_DISK_2 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=/u01/app/oracle/oradata/devdb/system01.dbf input datafile file number=00006 name=/u01/app/oracle/oradata/devdb/idx01.dbf input datafile file number=00005 name=/u01/app/oracle/oradata/devdb/example01.dbf channel ORA_DISK_1: starting piece 1 at 2015/07/08 23:34:54 channel ORA_DISK_2: starting full datafile backup set channel ORA_DISK_2: specifying datafile(s) in backup set input datafile file number=00002 name=/u01/app/oracle/oradata/devdb/sysaux01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/devdb/undotbs01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/devdb/users01.dbf channel ORA_DISK_2: starting piece 1 at 2015/07/08 23:34:55 channel ORA_DISK_2: finished piece 1 at 2015/07/08 23:36:20 piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_08/o1_mf_nnndf_TAG20150708T233454_bstjrz44_.bkp tag=TAG20150708T233454 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:01:25 channel ORA_DISK_2: starting full datafile backup set channel ORA_DISK_2: specifying datafile(s) in backup set including current control file in backup set channel ORA_DISK_2: starting piece 1 at 2015/07/08 23:36:21 channel ORA_DISK_2: finished piece 1 at 2015/07/08 23:36:23 piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_08/o1_mf_ncnnf_TAG20150708T233454_bstjvp4j_.bkp tag=TAG20150708T233454 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:02 channel ORA_DISK_2: starting full datafile backup set channel ORA_DISK_2: specifying datafile(s) in backup set including current SPFILE in backup set channel ORA_DISK_2: starting piece 1 at 2015/07/08 23:36:23 channel ORA_DISK_2: finished piece 1 at 2015/07/08 23:36:24 piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_08/o1_mf_nnsnf_TAG20150708T233454_bstjvqgc_.bkp tag=TAG20150708T233454 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: finished piece 1 at 2015/07/08 23:36:48 piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_08/o1_mf_nnndf_TAG20150708T233454_bstjrz3q_.bkp tag=TAG20150708T233454 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:54 Finished backup at 2015/07/08 23:36:48
Oracle为我们分配了两个Channel来完成备份工作。
除了修改配置文件来控制Channel,我们还可以手工的分配Channel。
我们先看看ALLOCATE CHANNEL的语法结构图
AUXILIARY关键字用来指定RMAN到辅助数据库的一个连接。这个我们后续再讨论。
CHANNEL ‘channel_id’用来指定RMAN到target 数据库实例之间的连接。channel_id表示Channel的名称,可以随便起。
DEVICE TYPE 用来指定设备的类型,常用的就是DISK、SBT.
其他的属性由allocOperandList子句指定。语句如下
我们最常用到的参数有FORMAT、MAXPIECESIZE、RATE、MAXOPENFILES
FORMAT:用来指定备份文件存储的路径及文件名命名规则。
MAXPIECESIZE:用来指定一个备份片的大小。
RATE:rman备份时最大的读取速率。
MAXOPENFILES:任意时刻backup命令能打开的最大输入文件个数。
例如
RUN { ALLOCATE CHANNEL c1 DEVICE TYPE disk MAXOPENFILES 20 RATE 2M MAXPIECESIZE 800M; BACKUP DATABASE; }
RUN { ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS="SBT_LIBRARY=?/lib/mm_lib2.so"; BACKUP DATABASE; }
FORMAT字符串替代变量
使用FORMAT参数时可使用的各种替换变量,如下:
%c:备份片的拷贝数(从1开始编号);
%d:数据库名称;
%D:位于该月中的天数 (DD);
%M:位于该年中的月份 (MM);
%F:一个基于DBID 唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII 为该数据库的DBID,YYYYMMDD 为日期,QQ 是一个1-256 的序列;
%n:数据库名称,并且会在右侧用x字符进行填充,使其保持长度为8;
%u:是一个由备份集编号和建立时间压缩后组成的8字符名称。利用%u可以为每个备份集生成一个唯一的名称;
%p:表示备份集中备份片段的编号,从1 开始编号;
%U:是%u_%p_%c的简写形式,利用它可以为每一个备份片段(即磁盘文件)生成一个唯一名称,这是最常用的命名方式;
%s:备份集的号;
%t:备份集时间戳;
%T:年月日格式(YYYYMMDD);s
注:如果在BACKUP命令中没有指定FORMAT选项,则RMAN默认使用%U为备份片段命名。
FORMAT关键字也可以跟在BACKUP命令后面,如果BACKUP命令也指定了format,那么将会覆盖CONFIGURE CHANNEL
或者
ALLOCATE CHANNEL
的format参数。
RUN { ALLOCATE CHANNEL c1 DEVICE TYPE disk format '/backup/full_%d_%T_%s_%p'; BACKUP DATABASE; }