先来一段官方解释
RMAN can store backup data in a logical structure called a backup set, which is the smallest unit of an RMAN backup. A backup set contains the data from one or more datafiles, archived redo logs, control files, or server parameter file. Backup sets, which are only created and accessed through RMAN, are the only form in which RMAN can write backups to media managers such as tape drives and tape libraries.
A backup set contains one or more binary files in an RMAN-specific format. Each of these files is known as a backup piece. A backup set can contain multiple datafiles.For example, you can back up 10 datafiles into a single backup set consisting of a
single backup piece. In this case, RMAN creates one backup piece as output. The backup set contains only this backup piece.
If you specify the SECTION SIZE parameter on the BACKUP command, then RMAN produces a multisection backup. This is a backup of a single large file, produced bymultiple channels in parallel, each of which produces one backup piece. Each backup
piece contains one file section of the file being backed up.
For non-multisection backups, RMAN only records backup sets in the repository that complete successfully. There is no such thing as a partial backup set. This differs from an unsuccessful multisection backup, where it is possible for RMAN metadata to
contain a record for a partial backup set. In the latter case, you must use the DELETE command to delete the partial backup set.
我的理解就从一个例子开始说吧。
如果配置了参数MAXSETSIZE就可能遇到这个问题
RMAN-03002: failure of backup command at 01/05/2020 18:00:07 RMAN-06183: datafile or datafile copy /oracle/oradata/orcl/users01.dbf (file number 4) larger than MAXSETSIZE
这里设置了MAXSETSIZE为20G,此时的users01.dbf已经超过了20G,导致此报错。
解决方法
1、取消MAXSETSIZE;Oracle 默认值是unlimited,可以设置为 CONFIGURE MAXSETSIZE TO UNLIMITED;
2、调大MAXSETSIZE;此处是20G,可以改为CONFIGURE MAXSETSIZE TO 100G;
为什么会报这种错误?
首先从官文中理解下BACKUP SET和BACKUP PIECE:
1、BACKUP SET是个逻辑概念,是RMAN备份的最小单元;一个BACKUP SET包含一个或多个数据文件、归档日志,控制文件或者SPFILE的数据。
2、一个BACKUP SET可以包含一个或者多个BACKUP PIECE,BACKUP PIECE的数量取决于是否在备份时设置了MAXPIECESIZE(用在 ALLOCATE CHANNEL or CONFIGURE CHANNEL command);
3、BACKUP PIECE是个物理概念,存在于磁盘上;一个BACKUP PIECE可以包含一个或多个数据文件;例如当BACKUP SET只有一个BACKUP PIECE,它就包含所有的数据文件
Oracle的原理是BACKUP SET不能跨数据文件,即如果设置MAXSETSIZE,此值的最小值也要大于占用物理空间最大的数据文件的大小,
生成BACKUP SET的个数(排除控制文件及SPFILE产生的BACKUP SET)= 数据文件占用总物理空间 / MAXSETSIZE
BACKUP PIECE可以跨数据文件,一个BACKUP SET下的多个BACKUP PIECE可能来自一个较大的数据文件,也可能一个BACKUP PIECE包含来自两个数据文件的数据。
以下来自测试环境:
先看数据文件大小,手动添加test表空间并指定1G大小数据文件test01.dbf
[oracle@orcl orcl]$ ls -lh
total 3.0G
-rw-r----- 1 oracle oinstall 9.6M Dec 24 06:00 control01.ctl
-rw-r----- 1 oracle oinstall 347M Dec 24 05:40 example01.dbf
-rw-r----- 1 oracle oinstall 51M Dec 24 05:34 redo01.log
-rw-r----- 1 oracle oinstall 51M Dec 24 06:00 redo02.log
-rw-r----- 1 oracle oinstall 51M Dec 24 05:34 redo03.log
-rw-r----- 1 oracle oinstall 601M Dec 24 05:57 sysaux01.dbf
-rw-r----- 1 oracle oinstall 761M Dec 24 05:59 system01.dbf
-rw-r----- 1 oracle oinstall 30M Dec 24 05:35 temp01.dbf
-rw-r----- 1 oracle oinstall 1.1G Dec 24 05:59 test01.dbf
-rw-r----- 1 oracle oinstall 101M Dec 24 05:59 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5.1M Dec 24 05:39 users01.dbf
执行rman备份后,查看BACKUP SET,此时的MAXSETSIZE设置为1G,MAXPIECESIZE无限制
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
55 Full 1.03M DISK 00:00:00 24-DEC-19
BP Key: 66 Status: AVAILABLE Compressed: NO Tag: TAG20191224T060127
Piece Name: /u01/app/oracle/oradata/Backup/oradb_ORCL_124_1.bak
List of Datafiles in backup set 55
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 1757455 24-DEC-19 /u01/app/oracle/oradata/orcl/test01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
56 Full 519.12M DISK 00:00:09 24-DEC-19
BP Key: 67 Status: AVAILABLE Compressed: NO Tag: TAG20191224T060127
Piece Name: /u01/app/oracle/oradata/Backup/oradb_ORCL_125_1.bak
List of Datafiles in backup set 56
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
2 Full 1757457 24-DEC-19 /u01/app/oracle/oradata/orcl/sysaux01.dbf
5 Full 1757457 24-DEC-19 /u01/app/oracle/oradata/orcl/example01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
57 Full 652.44M DISK 00:00:38 24-DEC-19
BP Key: 68 Status: AVAILABLE Compressed: NO Tag: TAG20191224T060127
Piece Name: /u01/app/oracle/oradata/Backup/oradb_ORCL_126_1.bak
List of Datafiles in backup set 57
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1757469 24-DEC-19 /u01/app/oracle/oradata/orcl/system01.dbf
3 Full 1757469 24-DEC-19 /u01/app/oracle/oradata/orcl/undotbs01.dbf
4 Full 1757469 24-DEC-19 /u01/app/oracle/oradata/orcl/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
58 Full 9.64M DISK 00:00:01 24-DEC-19
BP Key: 69 Status: AVAILABLE Compressed: NO Tag: TAG20191224T060127
Piece Name: /u01/app/oracle/oradata/Backup/oradb_ORCL_127_1.bak
SPFILE Included: Modification time: 24-DEC-19
SPFILE db_unique_name: ORCL
Control File Included: Ckp SCN: 1757510 Ckp time: 24-DEC-19
查看BACKUP PIECE大小
-rw-r----- 1 oracle oinstall 1.1M Dec 24 06:01 oradb_ORCL_124_1.bak
--1G的数据文件生成的BACKUP PIECE只有1.1M,证明RMAN只备份USED的数据块
-rw-r----- 1 oracle oinstall 520M Dec 24 06:01 oradb_ORCL_125_1.bak
-rw-r----- 1 oracle oinstall 653M Dec 24 06:02 oradb_ORCL_126_1.bak
-rw-r----- 1 oracle oinstall 9.7M Dec 24 06:02 oradb_ORCL_127_1.bak
手动设置MAXPIECESIZE为300M,MAXSETSIZE依然为1G,再次执行备份
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
59 Full 1.03M DISK 00:00:00 24-DEC-19
BP Key: 70 Status: AVAILABLE Compressed: NO Tag: TAG20191224T061050
Piece Name: /u01/app/oracle/oradata/Backup/oradb_ORCL_128_1.bak
List of Datafiles in backup set 59
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 1758274 24-DEC-19 /u01/app/oracle/oradata/orcl/test01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
60 Full 519.14M DISK 00:00:36 24-DEC-19
List of Datafiles in backup set 60
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
2 Full 1758276 24-DEC-19 /u01/app/oracle/oradata/orcl/sysaux01.dbf
5 Full 1758276 24-DEC-19 /u01/app/oracle/oradata/orcl/example01.dbf
Backup Set Copy #1 of backup set 60
Device Type Elapsed Time Completion Time Compressed Tag
----------- ------------ --------------- ---------- ---
DISK 00:00:36 24-DEC-19 NO TAG20191224T061050
List of Backup Pieces for backup set 60 Copy #1
BP Key Pc# Status Piece Name
------- --- ----------- ----------
71 1 AVAILABLE /u01/app/oracle/oradata/Backup/oradb_ORCL_129_1.bak
72 2 AVAILABLE /u01/app/oracle/oradata/Backup/oradb_ORCL_129_2.bak
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
61 Full 652.58M DISK 00:00:34 24-DEC-19
List of Datafiles in backup set 61
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1758319 24-DEC-19 /u01/app/oracle/oradata/orcl/system01.dbf
3 Full 1758319 24-DEC-19 /u01/app/oracle/oradata/orcl/undotbs01.dbf
4 Full 1758319 24-DEC-19 /u01/app/oracle/oradata/orcl/users01.dbf
Backup Set Copy #1 of backup set 61
Device Type Elapsed Time Completion Time Compressed Tag
----------- ------------ --------------- ---------- ---
DISK 00:00:34 24-DEC-19 NO TAG20191224T061050
List of Backup Pieces for backup set 61 Copy #1
BP Key Pc# Status Piece Name
------- --- ----------- ----------
73 1 AVAILABLE /u01/app/oracle/oradata/Backup/oradb_ORCL_130_1.bak
74 2 AVAILABLE /u01/app/oracle/oradata/Backup/oradb_ORCL_130_2.bak
75 3 AVAILABLE /u01/app/oracle/oradata/Backup/oradb_ORCL_130_3.bak
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
62 Full 9.64M DISK 00:00:01 24-DEC-19
BP Key: 76 Status: AVAILABLE Compressed: NO Tag: TAG20191224T061050
Piece Name: /u01/app/oracle/oradata/Backup/oradb_ORCL_131_1.bak
SPFILE Included: Modification time: 24-DEC-19
SPFILE db_unique_name: ORCL
Control File Included: Ckp SCN: 1758361 Ckp time: 24-DEC-19
查看生成的BACKUP PIECE大小,发现被按照最大300M分割成多个文件
-rw-r----- 1 oracle oinstall 1.1M Dec 24 06:10 oradb_ORCL_128_1.bak
-rw-r----- 1 oracle oinstall 300M Dec 24 06:11 oradb_ORCL_129_1.bak
-rw-r----- 1 oracle oinstall 220M Dec 24 06:11 oradb_ORCL_129_2.bak
-rw-r----- 1 oracle oinstall 300M Dec 24 06:11 oradb_ORCL_130_1.bak
-rw-r----- 1 oracle oinstall 300M Dec 24 06:11 oradb_ORCL_130_2.bak
-rw-r----- 1 oracle oinstall 53M Dec 24 06:12 oradb_ORCL_130_3.bak
-rw-r----- 1 oracle oinstall 9.7M Dec 24 06:12 oradb_ORCL_131_1.bak
结论:
1、BACKUP SET设置不能小于最大占用物理空间的数据文件大小
2、不根据是否使用块判断,只根据占用的物理空间判断分成多少BACKUP SET,当前数据文件总量大约2.7G,根据1G的MAXSETSIZE将全部数据文件备份为3个BACKUP SET
3、RMAN只备份已经使用的块
4、概念不要混淆,MAXSETSIZE指的是BACKUPSET大小,MAXPIECESIZE指的是BACKUP PIECE大小