你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle RMAN 备份一例

[日期:2017-08-08] 来源:Linux社区  作者:jyzhao [字体: ]
Oracle RMAN备份一例:
Solaris 10 + Oracle 11.2.0.3
Shell:csh,安装有bash,脚本调用bash
备份策略:周日0级备份,周一~周六1级备份,每6小时备份归档日志,每天清理历史文件夹.
--0级备份脚本:
#!/bin/bash
#db0 level backup
foldername=`date +%Y%m%d`
cd /oradata1/backup
if [ -d $foldername ]
then
        echo    'go on'
else
        echo    'need mkdir'
        mkdir $foldername
fi
 
export ORACLE_BASE=/opt/app/oracle/
export ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1/
export ORACLE_SID=SHIRNOP
export NLS_LANG="simplified chinese_china.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
export PATH=/bin:/usr/bin:/usr/ucb:/etc:$ORACLE_HOME/bin:.
 
rman target /  log=/oradata1/backup/$foldername/full_LOG.log << RMAN_BACKUP
run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/oradata1/backup/$foldername/controlfile%F';
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup incremental level 0 tag 'db0' database format '/oradata1/backup/$foldername/db0_%d_%T_%s' include current controlfile;
delete noprompt obsolete;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
RMAN_BACKUP
 
--1级备份脚本:
 
#!/bin/bash
#db1 level backup
foldername=`date +%Y%m%d`
cd /oradata1/backup
if [ -d $foldername ]
then
        echo    'go on'
else
        echo    'need mkdir'
        mkdir $foldername
fi
 
export ORACLE_BASE=/opt/app/oracle/
export ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1/
export ORACLE_SID=SHIRNOP
export NLS_LANG="simplified chinese_china.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
export PATH=/bin:/usr/bin:/usr/ucb:/etc:$ORACLE_HOME/bin:.
 
rman target /  log=/oradata1/backup/$foldername/incr_LOG.log << RMAN_BACKUP
run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/oradata1/backup/$foldername/controlfile%F';
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
backup incremental level 1 tag 'db1' database format '/oradata1/backup/$foldername/db1_%d_%T_%s' include current controlfile;
delete noprompt obsolete;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
RMAN_BACKUP
 
--归档备份
 
#!/bin/bash
#arch backup
foldername=`date +%Y%m%d`
cd /oradata1/backup
if [ -d $foldername ]
then
        echo    'go on'
else
        echo    'need mkdir'
        mkdir $foldername
fi
 
export ORACLE_BASE=/opt/app/oracle/
export ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1/
export ORACLE_SID=SHIRNOP
export NLS_LANG="simplified chinese_china.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
export PATH=/bin:/usr/bin:/usr/ucb:/etc:$ORACLE_HOME/bin:.
 
rman target /  log=/oradata1/backup/$foldername/arch_LOG.log << RMAN_BACKUP
run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
allocate channel c1 device type disk;
allocate channel c2 device type disk;
sql 'alter system archive log current';
backup archivelog all delete input format '/oradata1/backup/$foldername/arch_%d_%T_%s';
release channel c1;
release channel c2;
}
crosscheck archivelog all;
delete expired archivelog all;
RMAN_BACKUP
 
--系统级别删除过期备份的空文件夹
 
#!/bin/bash
#del old folders
cd /oradata1/backup
find . -mtime +10 | xargs rm -rf
 
--crontab调度
crontab -l
 
0 1 * * 0 /oradata1/backupsh/db0_backup.rman > /dev/null 2&>1#
0 1 * * 1-6 /oradata1/backupsh/db1_backup.rman > /dev/null 2&>1#
0 6,12,18 * * * /oradata1/backupsh/arch_backup.rman > /dev/null 2&>1#
0 3 * * * /oradata1/backupsh/del_old.sh > /dev/null 2&>1#

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-08/146099.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款