---------------------------------------------------------------------------------------------------------------------------------------------------
30 8,9,10,11,12,13,14,15,16,17,18 * * * nohup /backup/script/backup_l0_l1.sh >/dev/null 2>&1 &
0 19 * * * nohup /backup/script/backup_l0_l1.sh >/dev/null 2>&1 &
vi backup_l0_l1.sh
#!/bin/bash
export recore_bk_time=$(date +%y%m%d)
export week=$(date +%w)
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=ORCL
export PATH=$ORACLE_HOME/bin:$PATH
export TZ=Asia/Shanghai
export ORACLE_TERM=xterm
export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;
export BACKUP_HOME=/backup/data
export RMAN_DEST=/backup/data/$(date +%Y)_$(date +%W)week_rman/
export LOGFILE=$BACKUP_HOME/logs/${ORACLE_SID}_rman_$recore_bk_time.log
if [ ! -d "$RMAN_DEST" ]; then
mkdir "$RMAN_DEST"
fi
#Enable incremental backup except monday
case $week in
1)
LEVEL=0 && printf "[$ORACLE_SID]:$(date):rman backup begin with incremental level $LEVEL\n" >>$LOGFILE
;;
*)
LEVEL=1 && printf "[$ORACLE_SID]:$(date):rman backup begin with incremental level $LEVEL\n" >>$LOGFILE
;;
esac
export time1=$(date +%s)
rman target / log=$LOGFILE append <<EOF
run{
backup as compressed backupset device type disk incremental level=$LEVEL format '${RMAN_DEST}/db_full_%d_%s_%p_%t' database tag='db_l_$LEVEL';
sql 'alter system archive log current';
backup as compressed backupset device type disk archivelog from time 'sysdate-14' until time 'sysdate' format '${RMAN_DEST}/arc_%d_%s_%p_%t' delete input tag='arclog';
delete noprompt obsolete recovery window of 10 days;
backup current controlfile format '${RMAN_DEST}/ctl_%d_%s_%p_%t' tag='ctl';
}
exit;
EOF
time2=$(date +%s)
runtime1=$(((time2-time1)/60))
runtime2=$(((time2-time1)%60))
echo "Total time for this backup "$runtime1"Min "$runtime2"Sec;" >> $LOGFILE
if [ $? -eq 0 ];then
printf "[$ORACLE_SID]:$(date):rman backup successfully with incremental level $LEVEL\n" >>$LOGFILE
else
printf "[$ORACLE_SID]:$(date):rman backup failed with incremental level $LEVEL,please check rman log ${ORACLE_SID}_rman.log\n" >>$LOGFILE
fi