backup命令用来生成备份,可以在执行backup时为备份指定很多属性。官方文档上backup命令语法功能非常丰富,但是没有必要一一的掌握。先要了解一些基本用法,特殊的参数,用到的时候临时抱佛脚就行了。
下面我们挑一些常用的参数,做以说明。
BACKUP参数选项full服务器会话将所有块都复制到备份集中,只跳过从未使用过的数据文
件块。在备份归档重做日志或控制文件时,服务器会话不会跳过任何块。完全备份不是增量备份。
incremental
level
integer服务器会话复制自上次n 级增量备份以来更改过的数据块,其中n 是从1 到4 之间的任意整数。要执行大于0 级的增量备份时,服务器进程会在BACKUP 命令中检查每个数据文件的0 级备份或0 级副本是否存在。如果指定增量,则必须在备份说明中设置以下参数之一:DATA FILE、DATA FILECOPY、TABLESPACE 或DATABASE。恢复管理器不支持控制文件、归档重做日志或备份集的增量备份。
filesperset
integer如果指定了FILESPERSET 参数,恢复管理器就会将FILESPERSET值与计算的值(备份的文件数与通道数的比值)进行比较,并采用两者中的较小值,从而确保使用所有的通道。如果不指定FILESPERSET,恢复管理器就会将计算的值(文件数与分配的通道数的比值)与缺省值64 进行比较并采用两者中的较小值。当通道多于要备份的文件时,多余的通道将保持空闲。输入文件不能在通道之间进行分割。
skip指定该参数可将某些数据文件或归档重做日志排除在备份集之外。该参数具有以下选项:
offline:将脱机数据文件排除在备份集之外。
readonly:排除属于只读表空间的数据文件。
inaccessible:排除由于I/O 错误而无法读取的数据文件或归档重
做日志。
maxsetsize
integer以字节(缺省)、千字节(K)、兆字节(M) 或千兆字节(G) 来指定备份集的最大大小。恢复管理器会尽量将所有的备份集限制为指定的大小。
delete
input在成功创建备份集后删除输入文件。仅当备份归档重做日志、数据文
件副本或备份集时才指定该选项。它相当于对所有输入文件执行
CHANGE . . . DELETE 命令。
include
current
controlfile创建当前控制文件的快照并将其放置在该子句生成的各备份集中。
Format输出名称的格式。可以单独使用或组合使用格式参数。
PLUS ARCHIVELOG连带ARCHIVELOG一起备份
COPIESinteger多重备份,即备份集写多份。integer 取值(1-4),默认是1
下面演示一下skip、filesperset、maxsetsize、COPIES等用法skip 跳过只读文件SQL> ALTER TABLESPACE IDX READ ONLY;
Tablespace altered.
RMAN> BACKUP DATABASE SKIP READONLY;
Starting backup at 2015/07/09 03:39:49
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
skipping read-only file 6
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=00002 name=/u01/app/oracle/oradata/devdb/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/devdb/example01.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_1: starting piece 1 at 2015/07/09 03:39:49
channel ORA_DISK_1: finished piece 1 at 2015/07/09 03:41:45
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T033949_bstz45xk_.bkp tag=TAG20150709T033949 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:56
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 2015/07/09 03:41:46
channel ORA_DISK_1: finished piece 1 at 2015/07/09 03:41:47
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_ncsnf_TAG20150709T033949_bstz7toh_.bkp tag=TAG20150709T033949 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015/07/09 03:41:47FILEPERSET 限制备份集最多包含文件个数。RMAN> BACKUP DATABASE filesperset 2;
Starting backup at 2015/07/09 03:45:11
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=00001 name=/u01/app/oracle/oradata/devdb/system01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/devdb/idx01.dbf
channel ORA_DISK_1: starting piece 1 at 2015/07/09 03:45:11
channel ORA_DISK_1: finished piece 1 at 2015/07/09 03:45:46
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T034511_bstzg7tn_.bkp tag=TAG20150709T034511 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/devdb/sysaux01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/devdb/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2015/07/09 03:45:46
channel ORA_DISK_1: finished piece 1 at 2015/07/09 03:46:11
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T034511_bstzhc17_.bkp tag=TAG20150709T034511 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/devdb/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/devdb/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 2015/07/09 03:46:12
channel ORA_DISK_1: finished piece 1 at 2015/07/09 03:46:27
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T034511_bstzj460_.bkp tag=TAG20150709T034511 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
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 2015/07/09 03:46:28
channel ORA_DISK_1: finished piece 1 at 2015/07/09 03:46:29
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_ncsnf_TAG20150709T034511_bstzjnbx_.bkp tag=TAG20150709T034511 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015/07/09 03:46:29maxsetsize 设置备份集最大大RMAN> backup database maxsetsize 200M;
Starting backup at 2015/07/09 03:52:02
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 07/09/2015 03:52:02
RMAN-06183: datafile or datafile copy /u01/app/oracle/oradata/devdb/system01.dbf (file number 1) larger than MAXSETSIZE
备份集的最大大小不能小于任意一个数据文件的大小。RMAN> backup database maxsetsize 1G;
Starting backup at 2015/07/09 03:58:47
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/devdb/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/devdb/example01.dbf
channel ORA_DISK_1: starting piece 1 at 2015/07/09 03:58:48
channel ORA_DISK_1: finished piece 1 at 2015/07/09 03:59:23
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T035847_bsv07r5l_.bkp tag=TAG20150709T035847 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
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=00003 name=/u01/app/oracle/oradata/devdb/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/devdb/users01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/devdb/idx01.dbf
channel ORA_DISK_1: starting piece 1 at 2015/07/09 03:59:23
channel ORA_DISK_1: finished piece 1 at 2015/07/09 03:59:58
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T035847_bsv08vcs_.bkp tag=TAG20150709T035847 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
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 2015/07/09 03:59:59
channel ORA_DISK_1: finished piece 1 at 2015/07/09 04:00:00
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_ncsnf_TAG20150709T035847_bsv09zlm_.bkp tag=TAG20150709T035847 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015/07/09 04:00:00SQL> select name,bytes/1024/1024||'MB' from v$datafile;
NAME BYTES/1024/1024||'MB'
-------------------------------------------------- --------------------------------------
/u01/app/oracle/oradata/devdb/system01.dbf 770MB
/u01/app/oracle/oradata/devdb/sysaux01.dbf 580MB
/u01/app/oracle/oradata/devdb/undotbs01.dbf 95MB
/u01/app/oracle/oradata/devdb/users01.dbf 16.25MB
/u01/app/oracle/oradata/devdb/example01.dbf 345.625MB
/u01/app/oracle/oradata/devdb/idx01.dbf 10MB
COPIESRMAN> backup copies 2 database format '/backup/full_%U';
Starting backup at 2015/07/09 04:06:29
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=00001 name=/u01/app/oracle/oradata/devdb/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/devdb/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/devdb/example01.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
input datafile file number=00006 name=/u01/app/oracle/oradata/devdb/idx01.dbf
channel ORA_DISK_1: starting piece 1 at 2015/07/09 04:06:29
channel ORA_DISK_1: finished piece 1 at 2015/07/09 04:08:04 with 2 copies and tag TAG20150709T040629
piece handle=/backup/full_3bqbj5m5_1_1 comment=NONE
piece handle=/backup/full_3bqbj5m5_1_2 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35
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 2015/07/09 04:08:05
channel ORA_DISK_1: finished piece 1 at 2015/07/09 04:08:06 with 2 copies and tag TAG20150709T040629
piece handle=/backup/full_3cqbj5p4_1_1 comment=NONE
piece handle=/backup/full_3cqbj5p4_1_2 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015/07/09 04:08:06
如果备份集放到默认的fast recovery area中,是不允许使用copies参数的RMAN> backup copies 2 database;
Starting backup at 2015/07/09 04:11:37
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=00001 name=/u01/app/oracle/oradata/devdb/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/devdb/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/devdb/example01.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
input datafile file number=00006 name=/u01/app/oracle/oradata/devdb/idx01.dbf
channel ORA_DISK_1: starting piece 1 at 2015/07/09 04:11:37
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/09/2015 04:11:38
ORA-19806: cannot make duplex backups in recovery area
continuing other job steps, job failed will not be re-run
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 2015/07/09 04:11:39
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/09/2015 04:11:40
ORA-19806: cannot make duplex backups in recovery area