備份主備庫都能用的指令碼(zt)

tingsheng發表於2011-07-29

#!/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/7734298/viewspace-703523/,如需轉載,請註明出處,否則將追究法律責任。

相關文章