RMAN备份类:
1)backupset:只备份datafile里已经使用过的块( segment HWM以下)、可以实现增量备份(可以备份到disk和tape)。如果只启用一个channel,默认会把所有备份的datafile放入到一个backupset里,并且生成一个备份片(backup piece,在OS下看到的备份文件)恢复时速度慢,需要从备份集里先释放数据文件
backup piece :由backupset 生成的备份文件,保存在os下
2) copy(immage 镜像):实际上和手工cp 是类似的,备份datafile 所有的数据块,不能实现增量备份(但可以作为增量备份的0级备份),只能备份到disk ,不能备份到tape,恢复时速度快 ,不需要做restore。
RMAN备份命名方式:
RMAN备份文件可以自定义各种各样的格式,如下:
%c 备份片的拷贝数
%D 位于该月中的第几天 (DD)
%M 位于该年中的第几月 (MM)
%F 一个基于DBID 唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,
%d 数据库名称其中IIIIIIIIII 为该数据库的DBID,YYYYMMDD 为日期,QQ 是一个1-256 的序列
%n 数据库名称,向右填补到最大八个字符
%u 一个八个字符的名称代表备份集与创建时间
%p 该备份集中的备份片号,从1 开始到创建的文件数
%U 一个唯一的文件名,代表%u_%p_%c
%s 备份集的号
%t 备份集时间戳
%T 年月日格式(YYYYMMDD)
增量备份:只备份发生变化的block(rman通过在备份时记录datablock的scn,下次备份时通过比较上次备份的数据块上的scn来确定数据块是否发生变化)
1)差异增量备份(Differential incremental backup):下次备份时比较上次以来同级别或低级别的备份,为备份基础
2)累积增量备份的区别:只比较比自己级别低的作为备份基础
实验一:
在归档模式下对数据库进行level 0全备:
RMAN> run{ 2> sql ‘alter system archive log current‘; 3> allocate channel c1 type disk; 4> allocate channel c2 type disk; 5> backup incremental level 0 database format ‘/ora_data/prod/full_bk_L0_%c%U.dbf‘; 6> release channel c1; 7> release channel c2; 8> } sql statement: alter system archive log current released channel: ORA_DISK_1 allocated channel: c1 channel c1: SID=17 device type=DISK allocated channel: c2 channel c2: SID=22 device type=DISK Starting backup at 01-JUL-15 channel c1: starting incremental level 0 datafile backup set channel c1: specifying datafile(s) in backup set input datafile file number=00001 name=/u01/app/oracle/oradata/prod/system01.dbf input datafile file number=00006 name=/u01/app/oracle/oradata/prod/test02.dbf input datafile file number=00007 name=/u01/app/oracle/oradata/prod/test1.dbf channel c1: starting piece 1 at 01-JUL-15 channel c2: starting incremental level 0 datafile backup set channel c2: specifying datafile(s) in backup set input datafile file number=00002 name=/u01/app/oracle/oradata/prod/sysaux01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/prod/undotbs01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/prod/users01.dbf input datafile file number=00005 name=/u01/app/oracle/oradata/test01_new.dbf channel c2: starting piece 1 at 01-JUL-15 channel c1: finished piece 1 at 01-JUL-15 piece handle=/ora_data/prod/full_bk_L0_12tqav7h3_1_1.dbf tag=TAG20150701T143515 comment=NONE channel c1: backup set complete, elapsed time: 00:00:45 channel c2: finished piece 1 at 01-JUL-15 piece handle=/ora_data/prod/full_bk_L0_12uqav7h3_1_1.dbf tag=TAG20150701T143515 comment=NONE channel c2: backup set complete, elapsed time: 00:00:45 Finished backup at 01-JUL-15 Starting Control File and SPFILE Autobackup at 01-JUL-15 piece handle=/ora_data/rman/ctl_bk_c-293516844-20150701-00.dbf comment=NONE Finished Control File and SPFILE Autobackup at 01-JUL-15 released channel: c1 released channel: c2
备份归档日志,删除备份后的日志
RMAN> run{ 2> allocate channel c1 type disk; 3> allocate channel c2 type disk; 4> backup archivelog all delete all input format ‘/ora_data/prod/archbak_L0_%d_%T_%U.arc‘; 5> release channel c1; 6> release channel c2; 7> } allocated channel: c1 channel c1: SID=17 device type=DISK allocated channel: c2 channel c2: SID=22 device type=DISK Starting backup at 01-JUL-15 current log archived channel c1: starting archived log backup set channel c1: specifying archived log(s) in backup set input archived log thread=1 sequence=2 RECID=1 STAMP=883542071 input archived log thread=1 sequence=3 RECID=2 STAMP=883542302 input archived log thread=1 sequence=4 RECID=3 STAMP=883542338 input archived log thread=1 sequence=5 RECID=4 STAMP=883562459 input archived log thread=1 sequence=6 RECID=5 STAMP=883564921 channel c1: starting piece 1 at 01-JUL-15 channel c2: starting archived log backup set channel c2: specifying archived log(s) in backup set input archived log thread=1 sequence=7 RECID=6 STAMP=883923635 input archived log thread=1 sequence=8 RECID=7 STAMP=883924495 input archived log thread=1 sequence=9 RECID=8 STAMP=883924514 input archived log thread=1 sequence=10 RECID=9 STAMP=883924896 input archived log thread=1 sequence=11 RECID=10 STAMP=883924897 input archived log thread=1 sequence=12 RECID=11 STAMP=883924899 input archived log thread=1 sequence=13 RECID=12 STAMP=883924899 input archived log thread=1 sequence=14 RECID=13 STAMP=883924899 channel c2: starting piece 1 at 01-JUL-15 channel c2: finished piece 1 at 01-JUL-15 piece handle=/ora_data/prod/archbak_L0_PROD_20150701_31qav7td_1_1.arc tag=TAG20150701T144149 comment=NONE channel c2: backup set complete, elapsed time: 00:00:03 channel c2: deleting archived log(s) archived log file name=/oracle/arch1/1_7_883536782.dbf RECID=6 STAMP=883923635 archived log file name=/oracle/arch1/1_8_883536782.dbf RECID=7 STAMP=883924495 archived log file name=/oracle/arch1/1_9_883536782.dbf RECID=8 STAMP=883924514 archived log file name=/oracle/arch1/1_10_883536782.dbf RECID=9 STAMP=883924896 archived log file name=/oracle/arch1/1_11_883536782.dbf RECID=10 STAMP=883924897 archived log file name=/oracle/arch1/1_12_883536782.dbf RECID=11 STAMP=883924899 archived log file name=/oracle/arch1/1_13_883536782.dbf RECID=12 STAMP=883924899 archived log file name=/oracle/arch1/1_14_883536782.dbf RECID=13 STAMP=883924899 channel c2: starting archived log backup set channel c2: specifying archived log(s) in backup set input archived log thread=1 sequence=15 RECID=14 STAMP=883924899 input archived log thread=1 sequence=16 RECID=15 STAMP=883924905 input archived log thread=1 sequence=17 RECID=16 STAMP=883924908 channel c2: starting piece 1 at 01-JUL-15 channel c1: finished piece 1 at 01-JUL-15 piece handle=/ora_data/prod/archbak_L0_PROD_20150701_30qav7td_1_1.arc tag=TAG20150701T144149 comment=NONE channel c1: backup set complete, elapsed time: 00:00:04 channel c1: deleting archived log(s) archived log file name=/oracle/arch1/1_2_883536782.dbf RECID=1 STAMP=883542071 archived log file name=/oracle/arch1/1_3_883536782.dbf RECID=2 STAMP=883542302 archived log file name=/oracle/arch1/1_4_883536782.dbf RECID=3 STAMP=883542338 archived log file name=/oracle/arch1/1_5_883536782.dbf RECID=4 STAMP=883562459 archived log file name=/oracle/arch1/1_6_883536782.dbf RECID=5 STAMP=883564921 channel c2: finished piece 1 at 01-JUL-15 piece handle=/ora_data/prod/archbak_L0_PROD_20150701_32qav7th_1_1.arc tag=TAG20150701T144149 comment=NONE channel c2: backup set complete, elapsed time: 00:00:00 channel c2: deleting archived log(s) archived log file name=/oracle/arch1/1_15_883536782.dbf RECID=14 STAMP=883924899 archived log file name=/oracle/arch1/1_16_883536782.dbf RECID=15 STAMP=883924905 archived log file name=/oracle/arch1/1_17_883536782.dbf RECID=16 STAMP=883924908 Finished backup at 01-JUL-15 Starting Control File and SPFILE Autobackup at 01-JUL-15 piece handle=/ora_data/rman/ctl_bk_c-293516844-20150701-01.dbf comment=NONE Finished Control File and SPFILE Autobackup at 01-JUL-15 released channel: c1 released channel: c2
检查备份有效性
RMAN> crosscheck backup; allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=17 device type=DISK crosschecked backup piece: found to be ‘AVAILABLE‘ backup piece handle=/ora_data/prod/full_bk_L0_12uqav7h3_1_1.dbf RECID=79 STAMP=883924515 crosschecked backup piece: found to be ‘AVAILABLE‘ backup piece handle=/ora_data/prod/full_bk_L0_12tqav7h3_1_1.dbf RECID=80 STAMP=883924515 crosschecked backup piece: found to be ‘AVAILABLE‘ backup piece handle=/ora_data/rman/ctl_bk_c-293516844-20150701-00.dbf RECID=81 STAMP=883924561 crosschecked backup piece: found to be ‘AVAILABLE‘ backup piece handle=/ora_data/prod/archbak_L0_PROD_20150701_31qav7td_1_1.arc RECID=82 STAMP=883924909 crosschecked backup piece: found to be ‘AVAILABLE‘ backup piece handle=/ora_data/prod/archbak_L0_PROD_20150701_30qav7td_1_1.arc RECID=83 STAMP=883924909 crosschecked backup piece: found to be ‘AVAILABLE‘ backup piece handle=/ora_data/prod/archbak_L0_PROD_20150701_32qav7th_1_1.arc RECID=84 STAMP=883924913 crosschecked backup piece: found to be ‘AVAILABLE‘ backup piece handle=/ora_data/rman/ctl_bk_c-293516844-20150701-01.dbf RECID=85 STAMP=883924913 Crosschecked 7 objects
对数据库进行level 2备份
RMAN> run{ 2> allocate channel c1 type disk; 3> allocate channel c2 type disk; 4> backup incremental level 2 database format ‘/ora_data/prod/prod_bk_L2_%d_%U.dbf‘; 5> release channel c1 ; 6> release channel c2; 7> } released channel: ORA_DISK_1 allocated channel: c1 channel c1: SID=17 device type=DISK allocated channel: c2 channel c2: SID=22 device type=DISK Starting backup at 01-JUL-15 channel c1: starting incremental level 2 datafile backup set channel c1: specifying datafile(s) in backup set input datafile file number=00001 name=/u01/app/oracle/oradata/prod/system01.dbf input datafile file number=00006 name=/u01/app/oracle/oradata/prod/test02.dbf input datafile file number=00007 name=/u01/app/oracle/oradata/prod/test1.dbf channel c1: starting piece 1 at 01-JUL-15 channel c2: starting incremental level 2 datafile backup set channel c2: specifying datafile(s) in backup set input datafile file number=00002 name=/u01/app/oracle/oradata/prod/sysaux01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/prod/undotbs01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/prod/users01.dbf input datafile file number=00005 name=/u01/app/oracle/oradata/test01_new.dbf channel c2: starting piece 1 at 01-JUL-15 channel c1: finished piece 1 at 01-JUL-15 piece handle=/ora_data/prod/prod_bk_L2_PROD_34qav8d1_1_1.dbf tag=TAG20150701T145008 comment=NONE channel c1: backup set complete, elapsed time: 00:00:25 channel c2: finished piece 1 at 01-JUL-15 piece handle=/ora_data/prod/prod_bk_L2_PROD_35qav8d1_1_1.dbf tag=TAG20150701T145008 comment=NONE channel c2: backup set complete, elapsed time: 00:00:25 Finished backup at 01-JUL-15 Starting Control File and SPFILE Autobackup at 01-JUL-15 piece handle=/ora_data/rman/ctl_bk_c-293516844-20150701-02.dbf comment=NONE Finished Control File and SPFILE Autobackup at 01-JUL-15 released channel: c1 released channel: c2
当数据库crash后可以用RMAN备份片恢复数据库到数据库宕机状态。