http://blog.itpub.net/29119536/viewspace-1131999/
Oracle中,增量备份时分等级的,级别从0开始,一级一级递增,不过实际上用的最多的也就是0级和1级了,0级增量备份是后面级别的增量备份的 基础,0级备份实际上就是一个完全备份,与普通的完全备份唯一的不同点是0级备份可以作为其他级别增量备份的基础,而普通的完全备份是不能的。
从级别1开始,Oracle的增量备份分为差异增量备份和积累增量备份两种,其中差异增量备份备份的是自上一次同级别的差异备份或者是上一次更高级 别的备份完成之后的数据库发生改变的数据块;而积累增量备份则是备份的自上一次上一级增量备份完成以来数据库发生改变的数据块。在《Backup and Recovery User’s Guide》的“增量备份”一节中有两幅图很形象的描述了这两个增量备份之间的异同:
差异增量备份图示
积累增量备份图示
------------------------------------------------------------------------------------->>
rman 全备与0、1级增量备份
1、简单来说, rman全库备份只需要backup database;(未压缩),或者 backup as compressed backupset database; (压缩)。即可完全备份,如下:
RMAN> backup database; Starting backup at 08-OCT-13 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=34 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=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 08-OCT-13 channel ORA_DISK_1: finished piece 1 at 08-OCT-13 piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_nnndf_TAG20131008T221828_95851ofr_.bkp tag=TAG20131008T221828 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55 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 08-OCT-13 channel ORA_DISK_1: finished piece 1 at 08-OCT-13 piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_ncsnf_TAG20131008T221828_95853fmr_.bkp tag=TAG20131008T221828 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-OCT-13 RMAN>
可以看出备份集以及备份保存路径等信息,这部分信息都在show all;的参数中进行设置,这里都是默认的参数;
由于是nocatalog模式,备份信息都存在控制文件中.可以使用操作系统命令查看相关的控制文件信息:
[oracle@oracledba ~]$strings /u01/app/oracle/oradata/orcl/control01.ctl DISK /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_nnndf_TAG20131008T221828_95851ofr_.bkp TAG20131008T221828 DISK /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_ncsnf_TAG20131008T221828_95853fmr_.bkp TAG20131008T221828 DISK /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_nnndf_TAG20131008T221828_95851ofr_.bkp TAG20131008T221828
使用list backupset;命令查看备份信息:
RMAN> list backupset; using target database control file instead of recovery catalog List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 1 Full 1.03G DISK 00:00:50 08-OCT-13 BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20131008T221828 Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_nnndf_TAG20131008T221828_95851ofr_.bkp List of Datafiles in backup set 1 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---- 1 Full 1059012 08-OCT-13 /u01/app/oracle/oradata/orcl/system01.dbf 2 Full 1059012 08-OCT-13 /u01/app/oracle/oradata/orcl/sysaux01.dbf 3 Full 1059012 08-OCT-13 /u01/app/oracle/oradata/orcl/undotbs01.dbf 4 Full 1059012 08-OCT-13 /u01/app/oracle/oradata/orcl/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 2 Full 9.36M DISK 00:00:01 08-OCT-13 BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20131008T221828 Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_ncsnf_TAG20131008T221828_95853fmr_.bkp SPFILE Included: Modification time: 08-OCT-13 SPFILE db_unique_name: ORCL Control File Included: Ckp SCN: 1059037 Ckp time: 08-OCT-13 RMAN>
可以看出有两个备份集,每个备份集有一个备份片,恢复的时候需要用到这两个备份,可以把文件拷贝到其他目录或者磁带上保存,需要恢复的时候拷贝到原始备份的目录(即控制文件中记录的目录)即可恢复!
如果需要压缩备份全库及归档日志可以执行如下命令:
backup as compressed backupset database plus archivelog;
2、rman 0级增量备份:
其实全备和0级增量备份都是全备,但是也是有区别的,0级增量备份可以用于增量备份恢复的基础,而单独的全备不能用于增量备份的恢复基础!0级增量备份的命令如下:
RMAN> backup incremental level 0 database;
或者
RMAN> backup incremental level= 0 database;
RMAN> backup incremental level 0 database; Starting backup at 08-OCT-13 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=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 08-OCT-13 channel ORA_DISK_1: finished piece 1 at 08-OCT-13 piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_nnnd0_TAG20131008T225334_95873gfh_.bkp tag=TAG20131008T225334 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45 channel ORA_DISK_1: starting incremental level 0 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 08-OCT-13 channel ORA_DISK_1: finished piece 1 at 08-OCT-13 piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_ncsn0_TAG20131008T225334_95874wqs_.bkp tag=TAG20131008T225334 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-OCT-13 RMAN> list backupset; List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 4 Incr 0 1.03G DISK 00:00:43 08-OCT-13 BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20131008T225334 Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_nnnd0_TAG20131008T225334_95873gfh_.bkp List of Datafiles in backup set 4 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---- 1 0 Incr 1060153 08-OCT-13 /u01/app/oracle/oradata/orcl/system01.dbf 2 0 Incr 1060153 08-OCT-13 /u01/app/oracle/oradata/orcl/sysaux01.dbf 3 0 Incr 1060153 08-OCT-13 /u01/app/oracle/oradata/orcl/undotbs01.dbf 4 0 Incr 1060153 08-OCT-13 /u01/app/oracle/oradata/orcl/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 5 Incr 0 9.36M DISK 00:00:01 08-OCT-13 BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20131008T225334 Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_ncsn0_TAG20131008T225334_95874wqs_.bkp SPFILE Included: Modification time: 08-OCT-13 SPFILE db_unique_name: ORCL Control File Included: Ckp SCN: 1060170 Ckp time: 08-OCT-13
list backupset结果可以看出,全备和0级增量备份在type上的区别!
同理,可以对数据库做1级增量备份,命令如下:
RMAN> backup incremental level 1 database;
此时rman需要对比0级增量备份后到执行1级增量备份时候的数据变化情况,备份出来的备份大小由数据更改的多少而定!
RMAN> backup incremental level 1 database; Starting backup at 08-OCT-13 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=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 08-OCT-13 channel ORA_DISK_1: finished piece 1 at 08-OCT-13 piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_nnnd1_TAG20131008T230442_9587rd4t_.bkp tag=TAG20131008T230442 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35 channel ORA_DISK_1: starting incremental level 1 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 08-OCT-13 channel ORA_DISK_1: finished piece 1 at 08-OCT-13 piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_ncsn1_TAG20131008T230442_9587shm2_.bkp tag=TAG20131008T230442 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-OCT-13 RMAN> list backupset; List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 4 Incr 0 1.03G DISK 00:00:43 08-OCT-13 BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20131008T225334 Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_nnnd0_TAG20131008T225334_95873gfh_.bkp List of Datafiles in backup set 4 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---- 1 0 Incr 1060153 08-OCT-13 /u01/app/oracle/oradata/orcl/system01.dbf 2 0 Incr 1060153 08-OCT-13 /u01/app/oracle/oradata/orcl/sysaux01.dbf 3 0 Incr 1060153 08-OCT-13 /u01/app/oracle/oradata/orcl/undotbs01.dbf 4 0 Incr 1060153 08-OCT-13 /u01/app/oracle/oradata/orcl/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 5 Incr 0 9.36M DISK 00:00:01 08-OCT-13 BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20131008T225334 Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_ncsn0_TAG20131008T225334_95874wqs_.bkp SPFILE Included: Modification time: 08-OCT-13 SPFILE db_unique_name: ORCL Control File Included: Ckp SCN: 1060170 Ckp time: 08-OCT-13 BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 6 Incr 1 8.53M DISK 00:00:26 08-OCT-13 BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20131008T230442 Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_nnnd1_TAG20131008T230442_9587rd4t_.bkp List of Datafiles in backup set 6 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---- 1 1 Incr 1060699 08-OCT-13 /u01/app/oracle/oradata/orcl/system01.dbf 2 1 Incr 1060699 08-OCT-13 /u01/app/oracle/oradata/orcl/sysaux01.dbf 3 1 Incr 1060699 08-OCT-13 /u01/app/oracle/oradata/orcl/undotbs01.dbf 4 1 Incr 1060699 08-OCT-13 /u01/app/oracle/oradata/orcl/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 7 Incr 1 9.36M DISK 00:00:01 08-OCT-13 BP Key: 7 Status: AVAILABLE Compressed: NO Tag: TAG20131008T230442 Piece Name: /u01/app/oracle/fast_recovery_area/ORCL/backupset/2013_10_08/o1_mf_ncsn1_TAG20131008T230442_9587shm2_.bkp SPFILE Included: Modification time: 08-OCT-13 SPFILE db_unique_name: ORCL Control File Included: Ckp SCN: 1060711 Ckp time: 08-OCT-13 RMAN>
以上3种备份生成的文件,可以通过list backupset命令查看相关区别!同样备份信息可以在控制文件中查看!
--------------------------------------------->> 一个增量备份的例子 脚本#!/bin/bash
# incremental level 0 backup script
source /home/oracle/.bash_profile
current_day=`date +%Y%m%d`
incr_day=102_incr_$current_day
mkdir /data/oracle/ora_backup/$incr_day
echo '-------------------------------------'
echo "-- Begin Increment Backup of DB 10.103.23.102 DateTime: `date` --"
echo '-------------------------------------'
rman target / <<EOF
run
{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/data/oracle/ora_backup/$incr_day/PID-%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 4;
crosscheck backup;
delete noprompt obsolete;
delete noprompt expired backup;
allocate channel dev1 type disk maxpiecesize=30720M;
allocate channel dev2 type disk maxpiecesize=30720M;
allocate channel dev3 type disk maxpiecesize=30720M;
allocate channel dev4 type disk maxpiecesize=30720M;
backup as compressed backupset incremental level 1 tag='db1'
format '/data/oracle/ora_backup/$incr_day/%n_%T_%U' database;
sql 'alter system archive log current';
backup archivelog all format '/data/oracle/ora_backup/$incr_day/arc_%n_%T_%U' delete all input;
release channel dev1;
release channel dev2;
release channel dev3;
release channel dev4;
}
EOF
echo '------------------------------------'
echo "-- End Increment Backup of DB 10.103.23.102 DateTime: `date` --"
echo '------------------------------------'
scp -l 51200 -r /data/oracle/ora_backup/$incr_day oracle@10.103.23.103:/data/oracle/ora_backup102 &
wait
echo '------------------------------------'
echo "-- End of Send file to 10.103.23.103 DateTime: `date` --"
echo '------------------------------------'
echo ''
echo ''
----------------------------------------结束,谢谢-----------------------------------------