http://www.dbabeta.com/2010/a-note-on-oracle-incremental-backup.html
看过《Backup and Recovery User’s Guide》的人都应该很清楚Oracle的增量备份,增量备份指的是Oracle可以做到只备份上次备份完成之后数据库发生变更的数据块,当然在这里的“上次备份”到底值得是那次却是很值得考究的。
Oracle中,增量备份时分等级的,级别从0开始,一级一级递增,不过实际上用的最多的也就是0级和1级了,0级增量备份是后面级别的增量备份的基础,0级备份实际上就是一个完全备份,与普通的完全备份唯一的不同点是0级备份可以作为其他级别增量备份的基础,而普通的完全备份是不能的。
从级别1开始,Oracle的增量备份分为差异增量备份和积累增量备份两种,其中差异增量备份备份的是自上一次同级别的差异备份或者是上一次更高级别的备份完成之后的数据库发生改变的数据块;而积累增量备份则是备份的自上一次上一级增量备份完成以来数据库发生改变的数据块。在《Backup and Recovery User’s Guide》的“增量备份”一节中有两幅图很形象的描述了这两个增量备份之间的异同,这里链接如下:
 |
| 差异增量备份图示,来自Oracle文档 |
 |
| 积累增量备份图示,来自Oracle文档 |
有了图的帮助我们是很容易就能理解这两个不同的增量备份的概念的,但是问题就在于如果没有做0级备份的时候,这个时候做1级或者更低级别的增量备份会怎么样呢?对此,《Backup and Recovery User’s Guide》一书中也是有说明(Oracle版本11gR2版本)的:
If no level 0 backup is available in either the current or parent incarnation, then the behavior. varies with the compatibility mode setting. If compatibility is >=10.0.0, RMAN copies all blocks that have been changed since the file was created. Otherwise, RMAN behaves as it did in previous releases, by generating a level 0 backup.
然后经过进一步查看却发现个很有意思的地方,上面的文章中只说了当兼容性设置大于等于10.0.0时,RMAN会备份所有的数据块,其实就是相当于一个完全备份,否则就会生成一个0级的备份,在这里没有说明当兼容性设置大于等于10.0.0是产生的完全备份可以用来做什么,能否当成一个0级备份使用。
于是又回头查了查10gR2和9iR2两份备份文档中的说明,这里先给出10gR2的说明:
If no level 0 backup is available, then the behavior. depends upon the compatibility mode setting. If compatibility is >=10.0.0, RMAN copies all blocks changed since the file was created, and stores the results as a level 1 backup. In other words, the SCN at the time the incremental backup is taken is the file creation SCN. If compatibility <10.0.0, RMAN generates a level 0 backup of the file contents at the time of the backup, to be consistent with the behavior. in previous releases.
这里说的很明确了,当兼容性大于等于10时,产生的备份虽然相当于完全备份,但是却是标记为1级的。
再看看9iR2的文档说明:
If no level 0 backup exists when you run a level 1 or higher backup, RMAN makes a level 0 backup automatically to serve as the base.
和上面两份文档没有其别,确定9i及之前的版本当做1级备份之前不存在0级备份时会产生一个0级的备份。
现在,最要紧的一点就是要确定当数据库兼容性设置大于等于10.0.0的时候,在没有进行0级备份的情况下实施1级备份,这时候产生的标记为1级备份的完全备份是否能够作为后续增量备份的基础备份呢?下面就是通过实验来验证一下,考虑到差异增量备份的追溯上次备份可以是同级的,无法验证1级全备是否可以用作基础备份,在这里备份都是使用的积累增量备份。
实验之前先说明下实验的环境:
| 2 |
SQL> SELECT * FROM V$VERSION; |
| 5 |
-------------------------------------------------------------------------------- |
| 6 |
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production |
| 7 |
PL/SQL Release 11.1.0.7.0 - Production |
| 8 |
CORE 11.1.0.7.0 Production |
| 9 |
TNS for Linux: Version 11.1.0.7.0 - Production |
| 10 |
NLSRTL Version 11.1.0.7.0 - Production |
| 15 |
Recovery Manager: Release 11.1.0.7.0 - Production on Mon Apr 12 03:31:43 2010 |
| 17 |
Copyright (c) 1982, 2007, Oracle. All rights reserved. |
| 19 |
connected to target database: ORCL (DBID=961654692) |
首先进行一个1级的积累增量备份,在这之前没有进行过0级的增量备份(为方便起见,所有的备份都只备份一个数据文件):
| 1 |
RMAN> backup as compressed backupset |
| 2 |
2> incremental level 1 cumulative datafile 1 |
| 3 |
3> format '/data/backup/system-%d-%s-%t.bkp'; |
| 5 |
Starting backup at 12-APR-10 |
| 6 |
using channel ORA_DISK_1 |
| 7 |
channel ORA_DISK_1: starting compressed incremental level 1 datafile backup set |
| 8 |
channel ORA_DISK_1: specifying datafile(s) in backup set |
| 9 |
input datafile file number=00001 name=databases/orcl/system-01.dbf |
| 10 |
channel ORA_DISK_1: starting piece 1 at 12-APR-10 |
| 11 |
channel ORA_DISK_1: finished piece 1 at 12-APR-10 |
| 12 |
piece handle=/data/backup/system-ORCL-203-716096188.bkp tag=TAG20100412T033628 comment=NONE |
| 13 |
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 |
| 14 |
channel ORA_DISK_1: starting compressed incremental level 1 datafile backup set |
| 15 |
channel ORA_DISK_1: specifying datafile(s) in backup set |
| 16 |
including current control file in backup set |
| 17 |
including current SPFILE in backup set |
| 18 |
channel ORA_DISK_1: starting piece 1 at 12-APR-10 |
| 19 |
channel ORA_DISK_1: finished piece 1 at 12-APR-10 |
| 20 |
piece handle=/data/backup/system-ORCL-204-716096204.bkp tag=TAG20100412T033628 comment=NONE |
| 21 |
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 |
| 22 |
Finished backup at 12-APR-10 |
备份结果如下,这里产生的备份是1级备份,但是看文件大小可以看出来备份的整个数据文件:
| 1 |
RMAN> list backupset 166; |
| 4 |
BS Key Type LV Size Device Type Elapsed Time Completion Time |
| 5 |
------- ---- -- ---------- ----------- ------------ --------------- |
| 6 |
166 Incr 1 37.59M DISK 00:00:12 12-APR-10 |
| 7 |
BP Key: 167 Status: AVAILABLE Compressed: YES Tag: TAG20100412T033628 |
| 8 |
Piece Name: /data/backup/system-ORCL-203-716096188.bkp |
| 9 |
List of Datafiles in backup set 166 |
| 10 |
File LV Type Ckp SCN Ckp Time Name |
| 11 |
---- -- ---- ---------- --------- ---- |
| 12 |
1 1 Incr 4011928 12-APR-10 databases/orcl/system-01.dbf |
在磁盘上面的文件:
| 3 |
-rw-r----- 1 oracle dba 1.2M Apr 12 03:36 system-ORCL-204-716096204.bkp |
| 4 |
-rw-r----- 1 oracle dba 38M Apr 12 03:36 system-ORCL-203-716096188.bkp |
让后同样命令再跑一次,等到的结果如下:
| 1 |
RMAN> list backupset 168; |
| 4 |
BS Key Type LV Size Device Type Elapsed Time Completion Time |
| 5 |
------- ---- -- ---------- ----------- ------------ --------------- |
| 6 |
168 Incr 1 37.59M DISK 00:00:12 12-APR-10 |
| 7 |
BP Key: 169 Status: AVAILABLE Compressed: YES Tag: TAG20100412T034101 |
| 8 |
Piece Name: /data/backup/system-ORCL-205-716096461.bkp |
| 9 |
List of Datafiles in backup set 168 |
| 10 |
File LV Type Ckp SCN Ckp Time Name |
| 11 |
---- -- ---- ---------- --------- ---- |
| 12 |
1 1 Incr 4012076 12-APR-10 databases/orcl/system-01.dbf |
很明显的看到备份结果的大小是没有变化的,因为在两次备份之间数据库的system数据文件基本就没有变化,如果上次的1级的完全备份可以当成0级使用的话这次备份的数据文件应该是非常的小才对。同样的备份结果的大小也可以通过ls命令看到:
| 3 |
-rw-r----- 1 oracle dba 1.2M Apr 12 03:41 system-ORCL-206-716096476.bkp |
| 4 |
-rw-r----- 1 oracle dba 38M Apr 12 03:41 system-ORCL-205-716096461.bkp |
| 5 |
-rw-r----- 1 oracle dba 1.2M Apr 12 03:36 system-ORCL-204-716096204.bkp |
| 6 |
-rw-r----- 1 oracle dba 38M Apr 12 03:36 system-ORCL-203-716096188.bkp |
当然这个时候不能满足于这个结论,我们还需要进一步的验证这里的1级的全备就是1级,为此我们做一个2级的积累差异备份看看:
| 1 |
RMAN> backup as compressed backupset |
| 2 |
2> incremental level 2 cumulative datafile 1 |
| 3 |
3> format '/data/backup/system-%d-%s-%t.bkp'; |
| 5 |
Starting backup at 12-APR-10 |
| 6 |
using channel ORA_DISK_1 |
| 7 |
channel ORA_DISK_1: starting compressed incremental level 2 datafile backup set |
| 8 |
channel ORA_DISK_1: specifying datafile(s) in backup set |
| 9 |
input datafile file number=00001 name=databases/orcl/system-01.dbf |
| 10 |
channel ORA_DISK_1: starting piece 1 at 12-APR-10 |
| 11 |
channel ORA_DISK_1: finished piece 1 at 12-APR-10 |
| 12 |
piece handle=/data/backup/system-ORCL-207-716096761.bkp tag=TAG20100412T034601 comment=NONE |
| 13 |
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 |
| 14 |
channel ORA_DISK_1: starting compressed incremental level 2 datafile backup set |
| 15 |
channel ORA_DISK_1: specifying datafile(s) in backup set |
| 16 |
including current control file in backup set |
| 17 |
including current SPFILE in backup set |
| 18 |
channel ORA_DISK_1: starting piece 1 at 12-APR-10 |
| 19 |
channel ORA_DISK_1: finished piece 1 at 12-APR-10 |
| 20 |
piece handle=/data/backup/system-ORCL-208-716096763.bkp tag=TAG20100412T034601 comment=NONE |
| 21 |
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 |
| 22 |
Finished backup at 12-APR-10 |
再看看备份结果:
| 1 |
RMAN> list backupset 170; |
| 4 |
BS Key Type LV Size Device Type Elapsed Time Completion Time |
| 5 |
------- ---- -- ---------- ----------- ------------ --------------- |
| 6 |
170 Incr 2 40.00K DISK 00:00:01 12-APR-10 |
| 7 |
BP Key: 171 Status: AVAILABLE Compressed: YES Tag: TAG20100412T034601 |
| 8 |
Piece Name: /data/backup/system-ORCL-207-716096761.bkp |
| 9 |
List of Datafiles in backup set 170 |
| 10 |
File LV Type Ckp SCN Ckp Time Name |
| 11 |
---- -- ---- ---------- --------- ---- |
| 12 |
1 2 Incr 4012219 12-APR-10 databases/orcl/system-01.dbf |
再看看实际生成的文件:
| 3 |
-rw-r----- 1 oracle dba 1.2M Apr 12 03:46 system-ORCL-208-716096763.bkp |
| 4 |
-rw-r----- 1 oracle dba 48K Apr 12 03:46 system-ORCL-207-716096761.bkp |
| 5 |
-rw-r----- 1 oracle dba 1.2M Apr 12 03:41 system-ORCL-206-716096476.bkp |
| 6 |
-rw-r----- 1 oracle dba 38M Apr 12 03:41 system-ORCL-205-716096461.bkp |
| 7 |
-rw-r----- 1 oracle dba 1.2M Apr 12 03:36 system-ORCL-204-716096204.bkp |
| 8 |
-rw-r----- 1 oracle dba 38M Apr 12 03:36 system-ORCL-203-716096188.bkp |
的确很小了,是有48k,这才是真正的增量备份了。
因此在这里我们可以得出结论:当数据库兼容性设置为大于等于10.0.0时,尽管在没有0级备份情况做1级的增量备份实际上是一个全备,但是这个全备也是1级的,不能用作1级积累增量备份的基础备份,这个是在设计备份策略的时候要注意的问题,这也是和9i及之前版本不同的地方。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/16568460/viewspace-669803/
,如需转载,请注明出处,否则将追究法律责任。