1.RMAN备份环境
RMAN备份与恢复至少有以下两部分组成:
Component |
Description |
Target database |
主要备份数据文件、控制文件、归档日志文件 |
RMAN client |
主要完成对Target Database的备份和恢复,通过ORACLE NET实现与Target Database的连接 |
2.RMAN分配通道
RMAN支持两种备份设备:SBT和DISK,分配通道都是基于设备做分配,RMAN通道实质是一个到存储设备的数据流。
1)RMAN手动分配通道
ALLOCATE CHANNEL命令在RUN块中执行,在执行BACK UP、RESTORE等需要进行磁盘I/O操作的命令时,可以将他们放在一个RUN块中执行,ALLOCATE CHANNEL为它们分配通道。
示例: RMAN>RUN{ 2>ALLOCATE CHANNEL C1 DEVICE TYPE DISK FORMAT '/u01/app/RMAN_BK/cn_%u'; 3>BACKUP TABLESPACE USERS; } |
批注:RMAN中执行的每一条BACKUP、RECOVER等命令都至少要求使用一个通道,通道数决定了这些操作执行的并行度,每条ALLOCATE CHANNEL命令对应一个通道,如果需要多个通道,执行多条ALLOCATE CHANNEL。
2)RMAN自动分配通道
RMAN分配根据这些命令中的设置自动通道:
示例:如果没有手动分配通道,RMAN将会自动分配通道,如下: RMAN>BACKUP DATAFILE 3; RMAN>RESTORE TABLESPACE users; |
3.Automatic Channel Device Configuration and Parallelism(自动通道配置和并行度)
使用SHOW DEVICE TYPE查看默认通道并行度,如下:
RMAN> SHOW DEVICE TYPE; using target database control file instead of recovery catalog RMAN configuration parameters are: CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default |
配置默认设备SBT,如下:
RMAN> CONFIGURE DEFAULT DEVICE TYPE TO sbt; new RMAN configuration parameters: CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE'; new RMAN configuration parameters are successfully stored RMAN> SHOW DEVICE TYPE; RMAN configuration parameters are: CONFIGURE DEVICE TYPE SBT_TAPE PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default |
通过自动分配通道运行CONFIGUREDEFAULT
DEVICE
TYPE
指定默认设备类型。例如可以将大部分时间备份到磁盘,偶尔备份到磁带。
示例: RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 1; RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 2; RMAN> CONFIGURE DEFAULT DEVICE TYPE TO DISK; RMAN> show DEVICE TYPE; RMAN configuration parameters are: CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; CONFIGURE DEVICE TYPE 'SBT_TAPE' PARALLELISM 2 BACKUP TYPE TO BACKUPSET; |
设置完成之后,RMAN将使用磁盘通道进行备份数据,如下:
RMAN> BACKUP TABLESPACE users; Starting backup at 30-DEC-13 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=124 devtype=DISK channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00004 name=/u01/app/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 30-DEC-13 channel ORA_DISK_1: finished piece 1 at 30-DEC-13 piece handle=/u01/app/flash_recovery_area/ORCL/backupset/2013_12_30/o1_mf_nnndf_TAG20131230T055611_9d16mvjn_.bkp tag=TAG20131230T055611 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07 Finished backup at 30-DEC-13 |
4.Image Copies(镜像拷贝)
Image Copies是指使用操作系统命令精确的拷贝单个的数据文件、归档日志文件或控制文件。RMAN可以使用Image Copies修复和恢复操作。
1)Using RMAN-Created Image Copies
如果需要执行修复命令,通过将映像副本拷贝到原先控制文件或数据文件的位置。如果存在当前的数据文件映像副本在磁盘上,那么将不需要将映像副本放入原先的位置,可以使用映像副本直接对数据文件进行修复。
2)User-Managed Image Copies
RMAN可以使用RMAN以外的机制管理映像副本,如本地操作系统文件复制命令或第三方工具。
3)Proxy Copies(代理拷贝)
Proxy copy can be used with datafiles or archived redo logs, as shown in these examples:
BACKUP DEVICE TYPE sbt PROXY DATAFILE 3; BACKUP DEVICE TYPE sbt PROXY ONLY DATABASE; BACKUP DEVICE TYPE sbt PROXY ONLY ARCHIVELOG ALL; |
5.Storage of Backups on Disk and Tape(存储备份数据)
Backups of Archived Logs(备份归档日志)
1)Backup Failover for Archived Redo Logs(备份失效归档日志)
RMAN的归档重做日志故障转移允许RMAN完成备份,即使一些归档日志文件丢失或损坏。
2)Multiplexed Backup Sets(复用备份)
RMAN中提供了三种方式实现Duplexed方式备份:
CONFIGURE... BACKUP COPIES命令可以为指定的设备类型设置默认的备份复制数量。这个配置仅适用于数据文件与归档重做日志文件和备份,并且,只有在使用自动分配的通道时才能够使用CONFIGURE... BACKUP COPIES命令设置的配置,如下:
RMAN> CONFIGURE DEFAULT DEVICE TYPE TO DISK; RMAN> CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2; RMAN> CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 2; |
批注:上述命令将DISK设备上的数据文件与归档文件的复制数量设置为2,当再次执行BACKUP DATABASE命令时,如果没有通过ALLCOATE CHANNEL分配通道,那么创建的备份集会自动生成2份备份集。
在RUN{}命令块中利用SET BACKUP COPIES命令为该命令块中所有的BACKUP命令设置Duplexed方式,如下:
RMAN> RUN { 2> SET BACKUP COPIES 2; 3> BACKUP DEVICE TYPE DISK TABLESPACE USERS FORMAT '/u01/app/RMAN_BK/USER01_%U','/u01/app/RMAN_BK/USER02_%U'; 4> } executing command: SET BACKUP COPIES Starting backup at 30-DEC-13 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=/u01/app/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 30-DEC-13 channel ORA_DISK_1: finished piece 1 at 30-DEC-13 with 2 copies and tag TAG20131230T102638 piece handle=/u01/app/RMAN_BK/USER01_1uosq6uv_1_1 comment=NONE piece handle=/u01/app/RMAN_BK/USER02_1uosq6uv_1_2 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 Finished backup at 30-DEC-13 |
在RMAN中执行BACKUP命令时显式指定COPIES参数,如下:
RMAN> BACKUP DEVICE TYPE DISK COPIES 3 DATAFILE 4 FORMAT '/u01/app/RMAN_BK/bk1_%u','/u01/app/RMAN_BK/bk2_%u','/u01/app/RMAN_BK/bk3_%U'; Starting backup at 30-DEC-13 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=/u01/app/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 30-DEC-13 channel ORA_DISK_1: finished piece 1 at 30-DEC-13 with 3 copies and tag TAG20131230T102010 piece handle=/u01/app/RMAN_BK/bk1_1tosq6iq comment=NONE piece handle=/u01/app/RMAN_BK/bk2_1tosq6iq comment=NONE piece handle=/u01/app/RMAN_BK/bk3_1tosq6iq_1_3 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25 Finished backup at 30-DEC-13 |
3)Backups of Backup Sets(设置备份集)
RMAN默认通道分配时指定了一个参数值为%F的FORMAT参数。
分配通道时指定备份片段名格式,示例如下:
RMAN> RUN { 2> ALLOCATE CHANNEL C1 DEVICE TYPE DISK FORMAT '/u01/app/RMAN_BK/BACKUP_%U'; 3> BACKUP TABLESPACE USERS; 4> } released channel: ORA_DISK_1 allocated channel: C1 channel C1: sid=124 devtype=DISK Starting backup at 30-DEC-13 channel C1: starting full datafile backupset channel C1: specifying datafile(s) in backupset input datafile fno=00004 name=/u01/app/oradata/orcl/users01.dbf channel C1: starting piece 1 at 30-DEC-13 channel C1: finished piece 1 at 30-DEC-13 with 2 copies and tag TAG20131230T104049 piece handle=/u01/app/RMAN_BK/BACKUP_1vosq7ph_1_1 comment=NONE piece handle=/u01/app/RMAN_BK/BACKUP_1vosq7ph_1_2 comment=NONE channel C1: backup set complete, elapsed time: 00:00:15 Finished backup at 30-DEC-13 released channel: C1 |
备份时可以直接给备份集指定一个名称(TAG),RMAN默认生成TAG格式为TAGyyyymmddThhmmss,其中TAG和T是固定字符,yyyymmddhhmmss对应执行备份操作的时间。
可以自己为备份集指定标签,示例如下:
RMAN> BACKUP TABLESPACE USERS TAG TBS_USRESBAK FORMAT '/u01/app/RMAN_BK/USER_%U'; Starting backup at 30-DEC-13 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=/u01/app/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 30-DEC-13 channel ORA_DISK_1: finished piece 1 at 30-DEC-13 with 2 copies and tagTBS_USRESBAK piece handle=/u01/app/RMAN_BK/USER_21osq86r_1_1 comment=NONE piece handle=/u01/app/RMAN_BK/USER_21osq86r_1_2 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07 Finished backup at 30-DEC-13 |
批注:TAG标签也可以视为备份集的别名。
RMAN在分配通道时有一个参数MAXPIECESIZE,用来指定备份片段的大小。示例,备份SYSTEM表空间,指定单个备份片段最大不能超过100M,如下:
RMAN> RUN { 2> ALLOCATE CHANNEL C2 DEVICE TYPE DISK MAXPIECESIZE=100M FORMAT '/u01/app/RMAN_BK/SYSTEM_%U'; 3> BACKUP TABLESPACE SYSTEM; 4> } released channel: ORA_DISK_1 allocated channel: C2 channel C2: sid=124 devtype=DISK Starting backup at 30-DEC-13 channel C2: starting full datafile backupset channel C2: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oradata/orcl/system01.dbf channel C2: starting piece 1 at 30-DEC-13 channel C2: finished piece 1 at 30-DEC-13 with 2 copies and tag TAG20131230T105541 piece handle=/u01/app/RMAN_BK/SYSTEM_22osq8ld_1_1 comment=NONE piece handle=/u01/app/RMAN_BK/SYSTEM_22osq8ld_1_2 comment=NONE channel C2: starting piece 2 at 30-DEC-13 channel C2: finished piece 2 at 30-DEC-13 with 2 copies and tag TAG20131230T105541 piece handle=/u01/app/RMAN_BK/SYSTEM_22osq8ld_2_1 comment=NONE piece handle=/u01/app/RMAN_BK/SYSTEM_22osq8ld_2_2 comment=NONE channel C2: starting piece 3 at 30-DEC-13 channel C2: finished piece 3 at 30-DEC-13 with 2 copies and tag TAG20131230T105541 piece handle=/u01/app/RMAN_BK/SYSTEM_22osq8ld_3_1 comment=NONE piece handle=/u01/app/RMAN_BK/SYSTEM_22osq8ld_3_2 comment=NONE channel C2: starting piece 4 at 30-DEC-13 channel C2: finished piece 4 at 30-DEC-13 with 2 copies and tag TAG20131230T105541 piece handle=/u01/app/RMAN_BK/SYSTEM_22osq8ld_4_1 comment=NONE piece handle=/u01/app/RMAN_BK/SYSTEM_22osq8ld_4_2 comment=NONE channel C2: backup set complete, elapsed time: 00:00:45 channel C2: starting full datafile backupset channel C2: specifying datafile(s) in backupset including current control file in backupset including current SPFILE in backupset channel C2: starting piece 1 at 30-DEC-13 channel C2: finished piece 1 at 30-DEC-13 with 2 copies and tag TAG20131230T105541 piece handle=/u01/app/RMAN_BK/SYSTEM_23osq8mq_1_1 comment=NONE piece handle=/u01/app/RMAN_BK/SYSTEM_23osq8mq_1_2 comment=NONE channel C2: backup set complete, elapsed time: 00:00:03 Finished backup at 30-DEC-13 released channel: C2 查看备份目录,生成了如下备份文件: [oracle@myCentOS01 RMAN_BK]$ ll -rw-r-----. 1 oracle oinstall 104857600 Dec 30 10:55 SYSTEM_22osq8ld_1_1 (104857600/1024/1024=100M) -rw-r-----. 1 oracle oinstall 104857600 Dec 30 10:55 SYSTEM_22osq8ld_1_2 -rw-r-----. 1 oracle oinstall 104857600 Dec 30 10:56 SYSTEM_22osq8ld_2_1 -rw-r-----. 1 oracle oinstall 104857600 Dec 30 10:56 SYSTEM_22osq8ld_2_2 -rw-r-----. 1 oracle oinstall 104857600 Dec 30 10:56 SYSTEM_22osq8ld_3_1 -rw-r-----. 1 oracle oinstall 104857600 Dec 30 10:56 SYSTEM_22osq8ld_3_2 -rw-r-----. 1 oracle oinstall 74563584 Dec 30 10:56 SYSTEM_22osq8ld_4_1 -rw-r-----. 1 oracle oinstall 74563584 Dec 30 10:56 SYSTEM_22osq8ld_4_2 -rw-r-----. 1 oracle oinstall 7208960 Dec 30 10:56 SYSTEM_23osq8mq_1_1 -rw-r-----. 1 oracle oinstall 7208960 Dec 30 10:56 SYSTEM_23osq8mq_1_2 |
不仅可以指定备份片段的大小,也可以指定备份集的大小,单个备份集的最大值可以在执行备份命令(或分配通道)时通过MAXSETSIZE参数指定,示例如下:
RMAN> BACKUP DATABASE MAXSETSIZE=100M; |
MAXSETSIZE参数指定的是单个备份集的最大值,与备份片段无关,不过默认情况下,一个备份集对应一个备份片段,因此也相当于指定了备份片段的大小,但是直接指定MAXSETSIZE参数限定备份集大小并非在所有情况下都实用,如果要备份的数据文件中,任意一个数据文件超出了指定参数值,则备份就会失败。对于实际应用中,需要限制生成文件大小的情况,更多会通过MAXSETSIZE参数限制备份片段,而不会直接限制备份集。
4)是否使用RMAN恢复目录(Recovery Catalog)
当没有恢复目录时,RMAN相关的备份信息,比如归档文件路径、备份集路径等均存储在目标数据库的控制文件中。RMAN提供了CREATE CATALOG命令,再创建恢复目录之前,需要对为该目录创建一个独立表空间和对应的SCHEMA,步骤如下:
1.创建一个独立表空间 SQL> CREATE TABLESPACE RMANTBS DATAFILE '/u01/app/oradata/RMANDB/rmantbs01.dbf' size 100M; Tablespace created.
批注:不要把恢复目录创建在要备份的目录数据库 2.创建一个独立的SCHEMA,用来记录备份信息,并授予相关权限 SQL> GRANT CONNECT,RESOURCE,RECOVERY_CATALOG_OWNER TO RMANCT IDENTIFIED BY RMANCT; Grant succeeded.
3.通过RMAN连接到新创建的恢复目录中 [oracle@myCentOS01 ~]$ rman catalog rmanct/rmanct Recovery Manager: Release 10.2.0.1.0 - Production on Mon Dec 30 11:56:44 2013 Copyright (c) 1982, 2005, Oracle. All rights reserved. connected to recovery catalog database RMAN>
4.在RMAN中创建catalog RMAN> CREATE CATALOG TABLESPACE RMANTBS; recovery catalog created 这样恢复目录就创建完了,一个恢复目录数据库可以同时为多个目标数据库提供服务,不要要使用恢复目录执行备份操作前,首先需要在恢复目录中注册该数据库。 注册数据库步骤如下: 1.首先以catalog模式连接到目标数据库和恢复目录 [oracle@myCentOS01 ~]$ rman target / catalog rmanct/rmanct@orcl Recovery Manager: Release 10.2.0.1.0 - Production on Mon Dec 30 12:01:37 2013 Copyright (c) 1982, 2005, Oracle. All rights reserved. connected to target database: ORCL (DBID=1362151472) connected to recovery catalog database
2.通过如下命令注册数据库 RMAN> REGISTER DATABASE; database registered in recovery catalog starting full resync of recovery catalog full resync complete
之后进行的操作,比如创建备份等操作信息都会存入恢复目录中。 批注:若要将已经注册到catalog中的数据库取消注册,如下操作: RMAN> UNREGISTER DATABASE; database name is "ORCL" and DBID is 1362151472 Do you really want to unregister the database (enter YES or NO)? YES database unregistered from the recovery catalog |
参考与《涂抹ORACLE》、ORACLE10g官方文档