rman 全備份指令碼

abin1703發表於2017-05-24
#$RMAN_HOME/script/rman_full0.sh
#CONFIGURE RETENTION POLICY TO REDUNDANCY 1;  --According to you space


#-----------------------script env-----------------------
. /home/oracle/.bash_profile
RMAN_HOME=/backup/rman     #set according to your backup  directory
LOGFILE=$RMAN_HOME/log/rman_full0.log


#ONEDAY=`date +%Y%m%d`
ONEDAY=`date +%Y%m%d%H%M`
ONEDAYDIR=$RMAN_HOME/$ONEDAY
ONEDAYDATA=$ONEDAYDIR/data
ONEDAYARCH=$ONEDAYDIR/archlog
ONEDAYCTLF=$ONEDAYDIR/ctlfile
ONEDAYLOG=$ONEDAYDIR/log
ONEDAYSPFILE=$ONEDAYDIR/spfile
#---check ONEDAYDIR, if no then create them---------
if [ ! -d ${ONEDAYDIR} ];
  then mkdir ${ONEDAYDIR}
fi


if [ ! -d ${ONEDAYLOG} ];
  then mkdir ${ONEDAYLOG}
fi


if [ ! -d ${ONEDAYDATA} ];
  then mkdir ${ONEDAYDATA}
fi


if [ ! -d ${ONEDAYARCH} ];
  then mkdir ${ONEDAYARCH}
fi


if [ ! -d ${ONEDAYCTLF} ];
  then mkdir ${ONEDAYCTLF}
fi


if [ ! -d ${ONEDAYSPFILE} ];
  then mkdir ${ONEDAYSPFILE}
fi


#rman backup full database log
LOGDATE=`date +%Y-%m-%d-%H-%M`
RMANLOG=$ONEDAYDIR/log/${LOGDATE}.log


#---check the logfile, if no then create them---------
if [ ! -f ${LOGFILE} ];
  then touch ${LOGFILE}
fi


if [ ! -f ${RMANLOG} ];
  then touch ${RMANLOG}
fi
#-------------start backup-----------------


echo "-------------------------Rman full backup -------------------------" >> ${LOGFILE}
echo "backup start time:" `date +%Y-%m-%d_%H:%M:%S` >> ${LOGFILE}
echo "----------------------Rman Database backup ------------"`date +%Y-%m-%d_%H:%M:%S` >>${RMANLOG}


$ORACLE_HOME/bin/rman nocatalog target sys/oracle <<EOF >> ${RMANLOG}
run
{
delete noprompt obsolete;
allocate channel c1 type disk MAXPIECESIZE 5g;
allocate channel c2 type disk MAXPIECESIZE 5g;
allocate channel c3 type disk MAXPIECESIZE 5g;
allocate channel c4 type disk MAXPIECESIZE 5g;
backup as compressed backupset incremental level 0 database tag 'full0backup' filesperset 3 format '$ONEDAYDIR/data/db_full0_%T_%d_%t_%s_%p.rbck' include current controlfile;
backup AS COMPRESSED BACKUPSET format '$ONEDAYDIR/archlog/arch_full0_%T_%d_%t_%s_%p.rbck' archivelog all;
delete noprompt archivelog all completed before 'sysdate-15';
backup current controlfile format '$ONEDAYDIR/ctlfile/ctl_%d_%T_%s_%p_%t.rbck';
backup spfile  format='$ONEDAYDIR/spfile/spfile_%d_%I_%U_%T.bak' tag='bk_spfile';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
exit;
EOF


echo "backup finish! check in :" ${RMANLOG} >> ${LOGFILE}
echo "backup end time:" `date +%Y-%m-%d_%H:%M:%S` >> ${LOGFILE}
echo "-------------------------------end-----------------------------------" >> ${LOGFILE}
#end of file



cat celar_arch.sh  

#!/bin/sh 
. /home/oracle/.bash_profile
export BACK_DATE=`date +%Y%m%d`
export BACKUP_PATH=/home/oracle/clear_arch
echo `mkdir -p ${BACKUP_PATH}/log/${BACK_DATE}` 
$ORACLE_HOME/bin/rman msglog=$BACKUP_PATH/log/${BACK_DATE}/clear_arch_$BACK_DATE.log << EOF 
connect target /; 
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog until time 'sysdate-15';
exit;
EOF

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30345407/viewspace-2139807/,如需轉載,請註明出處,否則將追究法律責任。

相關文章