####------------------------------------------------------------------------------####
######################################################################################
## shell db_incremental_database_backup.sh ##
## author zongziheng ##
## date 2019.06.20 ##
## func The path and date are set as required ##
## use meth ./rmanbackup_lev_sjz.sh BACKUP_DEST ORACLE_HOME ORACLE_SID ##
######################################################################################
#!/bin/ksh
export LANG=en_US
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
backtime=`date +"20%y%m%d%H%M%S"`
RMAN_BACKUP_DATA_DEST=$1
RMAN_LOG_FILE=${RMAN_BACKUP_DATA_DEST}/rmanback_lev_${backtime}.log
BACKUP_DATE=`date +%d`
TODAY=`date`
CURRENT_USER=`id|cut -d "(" -f2|cut -d ")" -f1`
echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE
export ORACLE_HOME=$2
export RMAN=${ORACLE_HOME}/bin/rman
export ORACLE_SID=$3
export ORACLE_USER=oracle
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
#touch $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
CURRENT_WEEK_DAILY=`date +%a`
case "$CURRENT_WEEK_DAILY" in
"Mon")
BAK_LEVEL=1
;;
"Tue")
BAK_LEVEL=1
;;
"Wed")
BAK_LEVEL=1
;;
"Thu")
BAK_LEVEL=1
;;
"Fri")
BAK_LEVEL=1
;;
"Sat")
BAK_LEVEL=0
;;
"Sun")
BAK_LEVEL=1
;;
"*")
BAK_LEVEL=error
esac
export BAK_LEVEL=$BAK_LEVEL
echo "Today is : $CURRENT_WEEK_DAILY incremental level= $BAK_LEVEL">>$RMAN_LOG_FILE
RUN_SHELL="
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 append <<EOF
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level= $BAK_LEVEL skip inaccessible filesperset 5 Database format='"$RMAN_BACKUP_DATA_DEST"/"$ORACLE_SID"_lev_"$BAK_LEVEL"_%U_%T' tag='"$ORACLE_SID"_lev_"$BAK_LEVEL"';
sql 'alter system archive log current';
backup archivelog all tag='arc_bak' format='"$RMAN_BACKUP_DATA_DEST"/arch_%U_%T' skip inaccessible filesperset 5 not backed up 1 times delete input;
backup current controlfile tag='ctlfile_bak' format='"$RMAN_BACKUP_DATA_DEST"/ctl_file_%U_%T';
backup spfile tag='spfile_bak' format='"$RMAN_BACKUP_DATA_DEST"/spfile_%U_%T';
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_SHELL" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$RUN_SHELL" >> $RMAN_LOG_FILE
STATUS=$?
else
echo "User Command String: $RUN_SHELL" >> $RMAN_LOG_FILE
/bin/sh -c "$RUN_SHELL" >> $RMAN_LOG_FILE
STATUS=$?
fi
# ---------------------------------------------------------------------------
# Log the completion script.
# ---------------------------------------------------------------------------
if [ "$STATUS" = "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
exit $STATUS
####------------------------------------------------------------------------------####
来源:oschina
链接:https://my.oschina.net/u/4377703/blog/4268151