码迷,mamicode.com
首页 > 数据库 > 详细

oracle备份策略

时间:2015-07-29 06:48:34      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:备份策略

RMAN>  CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
RMAN>  CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
启用控制文件自动备份及备份存放位置配置
RMAN> configure controlfile autobackup on;
查看配置信息
RMAN> show all;


-------------------------------------------------
--创建文件夹
$mkdir /home/oracle/backup
mkdir /home/oracle/backup/script
mkdir /home/oracle/backup/log
mkdir /home/oracle/backup/export

--备份目的地
mkdir /home/oracle/rman_backup

创建备份表空间

create tablespace rman_tbs datafile ‘/u01/app/oracle/oradata/orcl11g/rman_tbs01.dbf‘
size 1024M autoextend on next 50M maxsize 10240M
extent management local segment space management auto;

创建备份用户
create user rman identified by rman default tablespace rman_tbs temporary tablespace temp;


     grant connect,resource ,recovery_catalog_owner to rman;
SQL> grant unlimited tablespace to rman;
SQL> grant sysdba to rman;

 

rman catalog rman/rman
create catalog tablespace rman_tbs;
connect target sys/Oracle123@orcl11g
register database;
report schema;


-------------------------------------------------------

--倒出RMAN用户数据脚本exp_rman.par (即备份catalog库)


userid=rman/rman
file=/home/oracle/backup/export/rman.dmp
log=/home/oracle/backup/log/rman.log


-- 倒出RMAN数据SHELL脚本exp_rman.sh
#!/bin/bash
cd $HOME
. .bash_profile
cd $HOME/backup/script
exp parfile=exp_rman.par

--------------

---零级备份RMAN脚本level0_backup.rcv
connect catalog rman/rman
connect target sys/Oracle123@orcl11g
run { 
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format ‘/home/oracle/rman_backup/level0_%d_%s_%p_%u.bak‘
tag=‘level 0‘ include current controlfile;
sql ‘alter system archive log current‘;
backup archivelog all format ‘/home/oracle/rman_backup/arc_%d_%s_%p_%u.bak‘ ;
release channel d2;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt archivelog all completed before ‘sysdate-15‘;
resync catalog;

--零级备份SHELL脚本的level0_backup.sh
#!/bin/bash
backtime=`date +"%y%m%d%H"`
#cd $HOME
. /home/oracle/.bash_profile
cd $HOME/backup/script
rman cmdfile=level0_backup.rcv msglog=$HOME/backup/log/level0_${backtime}.log
. /home/oracle/backup/script/exp_rman.sh

 

一级差异增量备份RMAN脚本 level1_backup.rcv
connect catalog rman/rman
connect target sys/Oracle123@orcl11g
run {
allocate channel d1 type disk;
backup incremental level 1 format ‘/home/oracle/rman_backup/level1_%d_%s_%p_%u.bak‘ tag = ‘level 1‘cumulative database;
sql ‘alter system archive log current‘;
backup archivelog all format ‘/home/oracle/rman_backup/log_%d_%s_%p_%u.bak‘ ;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt archivelog all completed before ‘sysdate-15‘;
resync catalog;

--一级差异增量备份SHELL脚本level1_backup.sh

#!/bin/bash
backtime=`date +"%y%m%d%H"`
#cd $HOME
. /home/oracle/.bash_profile
cd /home/oracle/backup/script
rman cmdfile=level1_backup.rcv msglog=$HOME/backup/log/level1_${backtime}.log
. /home/oracle/backup/script/exp_rman.sh


linux下定时执行备份脚本

crontab -e -u oracle
SHELL=/bin/bash --以下脚本在bash下执行
MAILTO=oracle --执行日志以邮件形式邮给oracle用户,可以/var/spool/mail/oracle下查收
5 12 * * 1 nohup /home/oracle/backup/script/level0_backup.sh >/home/oracle/backup/cron.log 2>&1 &
5 12 * * 3 /home/oracle/backup/script/level1_backup.sh
5 12 * * 5 /home/oracle/backup/script/level1_backup.sh

 

一周差异备份策略:
备份目标库和catalog库
周一0级全备,周三周五为1级。
每天12点5分开始备份

 

 

 

 

 

 

oracle备份策略

标签:备份策略

原文地址:http://askjoey.blog.51cto.com/7594056/1679274

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!