ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 在主备库上统一的Rman备份脚本

在主备库上统一的Rman备份脚本

原创 Linux操作系统 作者:thompsun 时间:2011-04-11 14:42:47 0 删除 编辑

crontab配置如下:

0 3 * * 3,7 sh /home/oracle/shell/rman_mytest.sh >/home/oracle/shell/log/rman_mytest_`date +\%Y\%m\%d-\%H-\%M-\%S`.log 2>&1

rman_mytest.sh脚本如下:

#!/bin/bash
. ~/.bash_profile

export ORACLE_SID=mytest
export BACKUP_HOME='/oracle/backup_rman';
export DATABASE_ROLE_LOG='/tmp/des_temp.log';
export DATABASE_ROLE='';

sqlplus -S "/as sysdba" >$DATABASE_ROLE_LOG  <set feedback off
set head off
select  DATABASE_ROLE from v\$database;
exit
EOF

DATABASE_ROLE="`cat $DATABASE_ROLE_LOG |sed  '/^$/d'`";

if [ "$DATABASE_ROLE" == "PRIMARY" ]; then
   echo "################BACKUP THE $DATABASE_ROLE DATABASE################";

rman target / <run{
CONFIGURE RETENTION POLICY TO REDUNDANCY 4;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$BACKUP_HOME/%F.ctl';
allocate channel v1 type disk;
allocate channel v2 type disk;
crosscheck copy;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired copy;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
backup database format '$BACKUP_HOME/%d_full_%s_%p_%c_%T.bak';
backup current controlfile format '$BACKUP_HOME/%d_control_%s_%c_%p_%T.ctl';
backup archivelog all format '$BACKUP_HOME/%d_arch_%s_%c_%p_%T.bak';
release channel v1;
release channel v2;}
exit;
EOF

elif [ "$DATABASE_ROLE" == "PHYSICAL STANDBY" ]; then
   echo "################BACKUP THE $DATABASE_ROLE DATABASE################";

sqlplus "/as sysdba" <recover managed standby database cancel;
exit;
EOF

rman target / <run{
CONFIGURE CONTROLFILE AUTOBACKUP on;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$BACKUP_HOME/%F.ctl';
allocate channel v1 type disk;
allocate channel v2 type disk;
crosscheck copy;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired copy;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
backup database format '$BACKUP_HOME/%d_full_%s_%p_%c_%T.bak';
backup current controlfile format '$BACKUP_HOME/%d_control_%s_%c_%p_%T.ctl';
backup archivelog all format '$BACKUP_HOME/%d_arch_%s_%c_%p_%T.bak';
release channel v1;
release channel v2;}
exit;
EOF

sqlplus "/as sysdba" <recover managed standby database disconnect;
exit;
EOF

else
   echo "ORA-################";
fi;

find /home/oracle/shell/log -name "rman_$ORACLE_SID_*log" -mtime +30 -print -exec rm {} \;

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11134237/viewspace-692222/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-01-11

  • 博文量
    96
  • 访问量
    252013