一、备份恢复前的一些准备工作
alter system set control_file_record_keep_time=30;
控制文件中备份记录保存时间(单位:天)
二、创建一个存放archive log的目录
mkdir c:\oracle\archdata
alter system set log_archive_dest_1='location=c:\oracle\archdata' scope=both;
select dest_name,destination,status,error from v$archive_dest where dest_name='LOG_ARCHIVE_DEST_1';
三、RMAN环境变量
configure channel device type disk format 'c:\oracle\backup\DB_%U';
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to 'c:\oracle\backup\control\f_%F';
configure retention policy to recovery window of 7 days;
四、命令说明
backup archivelog all delete all input ;
第一个all ,备份全部归档日志;第二个all,删除所有归档目录下已经备份的归档日志,当归档目录只有一个的时候,可以不指定第二个all。
五、备份实例
run{
backup full database
format 'c:\oracle\backup\full_bk1_%u%p%s.rmn'
include current controlfile
plus archivelog format 'c:\oracle\backup\arch_bk1_%u%p%s.rmn'
delete all input;
}
六、增量备份
下面开始创建0级 1级 2级备份脚本
0级备份脚本
vim rman_bk_level0.sh
------0级备份----------------
#! /bin/bash
export ORACLE_SID=orcl
export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'
/u01/app/oracle/11.2.0/dbhome_1/bin/rman target / <<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format '/u01/app/oracle/level0_%d_%s_%p_%u.bkp';
sql 'alter system archive log current';
backup archivelog all delete input format '/u01/app/oracle/log_%d_%s_%p_u%.bkp';
release channel d1;
release channel d2;
crosscheck backup;
delete noprompt obsolete;
}
exit;
<<EOF
------------------
1级备份脚本
vim rman_bk_level1.sh
---------1级增量备份---------------
#! /bin/bash
export ORACLE_SID=orcl
export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'
/u01/app/oracle/11.2.0/dbhome_1/bin/rman target / <<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 1 database format '/u01/app/oracle/level1_%d_%s_%p_%u.bkp';
sql 'alter system archive log current';
backup archivelog all delete input format '/u01/app/oracle/log_%d_%s_%p_u%.bkp';
release channel d1;
release channel d2;
crosscheck backup;
delete noprompt obsolete;
}
exit;
<<EOF
2级备份脚本
vim rman_bk_level2.sh
---------2级增量备份---------------
#! /bin/bash
export ORACLE_SID=orcl
export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK'
/u01/app/oracle/11.2.0/dbhome_1/bin/rman target / <<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 2 database format '/u01/app/oracle/level2_%d_%s_%p_%u.bkp';
sql 'alter system archive log current';
backup archivelog all delete input format '/u01/app/oracle/log_%d_%s_%p_u%.bkp';
release channel d1;
release channel d2;
crosscheck backup;
delete noprompt obsolete;
}
exit;
<<EOF
加入到crontab中
crontab -e
-----------
#周日0级备份
00 23 * * 0 /u01/backup_shell/rman_bk_level0.sh
#周一、二、四、五、六2级增量备份
00 23 * * 1,2,4,5,6 /u01/backup_shell/rman_bk_level2.sh
#周三1级增量备份
00 23 * * 3 /u01/backup_shell/rman_bk_level1.sh
-------------
结束!
本文转自 pgmia 51CTO博客,原文链接:http://blog.51cto.com/heyiyi/1282917