[20151117]关于增量备份.txt
SCOTT@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
RMAN> backup incremental level 0 datafile 5 format '/home/oracle/backup/inc0_example_%u.dbf' TAG='INC0';
Starting backup at 2015-11-17 10:47:42
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-11-17 10:47:42
channel ORA_DISK_1: finished piece 1 at 2015-11-17 10:47:43
piece handle=/home/oracle/backup/inc0_example_40qmfume.dbf tag=INC0 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-11-17 10:47:43
--如果我改名删除这个增量备份呢?
$ mv inc0_example_40qmfume.dbf inc0_example_40qmfume.dbf_ORG
RMAN> backup incremental level 1 datafile 5 format '/home/oracle/backup/inc1_example_%u.dbf' TAG='INC1';
Starting backup at 2015-11-17 10:52:01
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-11-17 10:52:01
channel ORA_DISK_1: finished piece 1 at 2015-11-17 10:52:02
piece handle=/home/oracle/backup/inc1_example_43qmfuuh.dbf tag=INC1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-11-17 10:52:02
--增量1级备份成功。
RMAN> list backupset ;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
120 Incr 0 68.84M DISK 00:00:00 2015-11-17 10:47:42
BP Key: 120 Status: AVAILABLE Compressed: NO Tag: INC0
Piece Name: /home/oracle/backup/inc0_example_40qmfume.dbf
List of Datafiles in backup set 120
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
5 0 Incr 1774661 2015-11-16 16:16:33 /mnt/ramdisk/book/example01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
122 Incr 1 32.00K DISK 00:00:00 2015-11-17 10:52:01
BP Key: 122 Status: AVAILABLE Compressed: NO Tag: INC1
Piece Name: /home/oracle/backup/inc1_example_43qmfuuh.dbf
List of Datafiles in backup set 122
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
5 1 Incr 1812018 2015-11-17 10:52:01 /mnt/ramdisk/book/example01.dbf
--说明备份并不是读取增量备份文件来比较的。而是通过控制文件记录的信息来确定从那个scn开始。
SELECT recid
,file#
,incremental_level
,incremental_change#
,checkpoint_change#
,datafile_blocks
,blocks_read
FROM V$BACKUP_DATAFILE;
RECID FILE# INCREMENTAL_LEVEL INCREMENTAL_CHANGE# CHECKPOINT_CHANGE# DATAFILE_BLOCKS BLOCKS_READ
---------- ---------- ----------------- ------------------- ------------------ --------------- -----------
124 5 0 0 1774661 42240 39872
126 5 1 1774661 1812018 42240 42240
--可以从BLOCKS_READ看出,0级备份仅仅读取使用的块,而1级备份读取全部的数据块。要想充分使用增量备份最好打开块跟踪。
3.打开块跟踪文件:
SCOTT@book> alter database enable block change tracking using file '/home/oracle/backup/change_tracking.dbf';
Database altered.
RMAN> backup incremental level 1 datafile 5 format '/home/oracle/backup/inc1_example_%u.dbf' TAG='INC1';
Starting backup at 2015-11-17 11:05:02
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-11-17 11:05:02
channel ORA_DISK_1: finished piece 1 at 2015-11-17 11:05:03
piece handle=/home/oracle/backup/inc1_example_44qmfvmu.dbf tag=INC1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-11-17 11:05:03
SELECT recid
,file#
,incremental_level
,incremental_change#
,checkpoint_change#
,datafile_blocks
,blocks_read
FROM V$BACKUP_DATAFILE
RECID FILE# INCREMENTAL_LEVEL INCREMENTAL_CHANGE# CHECKPOINT_CHANGE# DATAFILE_BLOCKS BLOCKS_READ
---------- ---------- ----------------- ------------------- ------------------ --------------- -----------
124 5 0 0 1774661 42240 39872
126 5 1 1774661 1812018 42240 42240
127 5 1 1812018 1812564 42240 42240
--再只执行1次增量备份就可以看出效果了。
RMAN> backup incremental level 1 datafile 5 format '/home/oracle/backup/inc1_example_%u.dbf' TAG='INC1';
Starting backup at 2015-11-17 11:06:04
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-11-17 11:06:05
channel ORA_DISK_1: finished piece 1 at 2015-11-17 11:06:06
piece handle=/home/oracle/backup/inc1_example_45qmfvot.dbf tag=INC1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015-11-17 11:06:06
RMAN>
SCOTT@book> /
RECID FILE# INCREMENTAL_LEVEL INCREMENTAL_CHANGE# CHECKPOINT_CHANGE# DATAFILE_BLOCKS BLOCKS_READ
---------- ---------- ----------------- ------------------- ------------------ --------------- -----------
124 5 0 0 1774661 42240 39872
126 5 1 1774661 1812018 42240 42240
127 5 1 1812018 1812564 42240 42240
128 5 1 1812564 1812604 42240 1
--最后一次读取量明显减少,这样可以加快1级备份的速度。
SCOTT@book> alter database disable block change tracking ;
Database altered.
$ ll /home/oracle/backup/change_tracking.dbf
ls: /home/oracle/backup/change_tracking.dbf: No such file or directory
总结:
1.使用增量备份模式,最好打开块跟踪模式。加快1级备份以及累积备份的速度。
2.注意检查0级备份是否完好,如果删除或者损坏,后果比较严重。