[oracle@test exp_bak]$ more /home/backup/rman_incremental_backup.sh
#!/bin/ksh
export LANG=en_US
BACKUP_DATE=`date +%d`
#RMAN_LOG_FILE=${0}.out
TODAY=`date`
USER=`id|cut -d "(" -f2|cut -d ")" -f1`
rq=`date +%Y%m%d`
RMAN_LOG_FILE=`pwd`'/'rman_${rq}.log
#MAN_LOG_FILE=/home/backup/rman_${rq}.log
echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE
ORACLE_HOME=/home/app/oracle/product/10.2.0/db_1
export ORACLE_HOME
RMAN=$ORACLE_HOME/bin/rman
export RMAN
ORACLE_SID=orcl
export ORACLE_SID
ORACLE_USER=oracle
export ORACLE_USER
echo "ORACLE_SID: $ORACLE_SID">>$RMAN_LOG_FILE
echo "ORACLE_HOME:$ORACLE_HOME">>$RMAN_LOG_FILE
echo "ORACLE_USER:$ORACLE_USER">>$RMAN_LOG_FILE
echo "==========================================">>$RMAN_LOG_FILE
echo "BACKUP DATABASE BEGIN......">>$RMAN_LOG_FILE
echo " ">>$RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
WEEK_DAILY=`date +%a`
case "$WEEK_DAILY" in
"Mon")
BAK_LEVEL=2
;;
"Tue")
BAK_LEVEL=2
;;
"Wed")
BAK_LEVEL=2
;;
"Thu")
BAK_LEVEL=1
;;
"Fri")
BAK_LEVEL=2
;;
"Sat")
BAK_LEVEL=2
;;
"Sun")
BAK_LEVEL=0
;;
"*")
BAK_LEVEL=error
esac
export BAK_LEVEL=$BAK_LEVEL
echo "Today is : $WEEK_DAILY incremental level= $BAK_LEVEL">>$RMAN_LOG_FILE
RUN_STR="
BAK_LEVEL=$BAK_LEVEL
export BAK_LEVEL
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
#$RMAN nocatalog TARGET sys/oracle msglog $RMAN_LOG_FILE <
$RMAN nocatalog TARGET sys/oracle msglog $RMAN_LOG_FILE <
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level= $BAK_LEVEL database format='/home/backup/orcl_lev"$BAK_LEVEL"%d_%s_%T.bak' tag='orcl_lev"$BAK_LEVEL"' ;
sql 'alter system archive log current';
backup archivelog all tag='arc_bak' format='/home/backup/arch_%d_%s_%T.bak' delete input;
backup current controlfile tag='bak_ctlfile' format='/home/backup/ctl_file_%d_%s_%T.bak';
backup spfile tag='bak_spfile' format='/home/backup/ORCL_spfile_%d_%s_%T.bak';
release channel c2;
release channel c1;
}
report obsolete;
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
list backup summary;
EOF
"
# Initiate the command string
if [ "$CUSER" = "root" ]
then
echo "Root Command String: $RUN_STR" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$RUN_STR" >> $RMAN_LOG_FILE
RSTAT=$?
else
echo "User Command String: $RUN_STR" >> $RMAN_LOG_FILE
/bin/sh -c "$RUN_STR" >> $RMAN_LOG_FILE
RSTAT=$?
fi
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------
if [ "$RSTAT" = "0" ]
then
LOGMSG="ended successfully"
else
LOGMSG="ended in error"
fi
echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
/bin/mailx -s "RMAN Backup SID " douyaqiang123@163.com < $RMAN_LOG_FILE
exit $RSTAT
阅读(1631) | 评论(0) | 转发(0) |