oracle11g Rman 备份脚本

 

1、Rman备份脚本 

备份策略:周天0级备份,其他时候1级备份 

########################################################################
##   kfc_incremental_hot_database_backup.sh  ##
##   created by  NBU TEMP                    ##
##        2012-3-8                           ##
#########################################################################

#!/bin/ksh

export LANG=en_US
BACKUP_DATE=`date +%d`
RMAN_LOG_FILE=/home/oracle/backup/log/backupinfo.out
TODAY=`date`
USER=`id|cut -d "(" -f2|cut -d ")" -f1`
echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE

ORACLE_HOME=/opt/oracle/product/11.2.0/dbhome_1
export ORACLE_HOME

RMAN=$ORACLE_HOME/bin/rman
export RMAN

ORACLE_SID=kfsjora
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

#touch $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE

WEEK_DAILY=`date +%a`

case  "$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=1
            ;;
       "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 TARGET sys/qhyc_pass CATALOG kfcrman/kfcrman@kfcrman  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='/opt/kfsjora_backup/orcl_lev"$BAK_LEVEL"_%U_%T'  tag='orcl_lev"$BAK_LEVEL"' ;

  sql 'alter system archive log current';

  backup archivelog all tag='arc_bak' format='/opt/kfsjora_backup/arch_%U_%T' skip inaccessible  filesperset 5 not  backed up 1 times  delete input;

  backup current controlfile tag='bak_ctlfile' format='/opt/kfsjora_backup/ctl_file_%U_%T';

  backup spfile tag='spfile' format='/opt/kfsjora_backup/ORCL_spfile_%U_%T';

  release channel c2;
  release channel c1;
}

report obsolete;
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
list backup summary;
resync catalog;
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 " [email protected] < $RMAN_LOG_FILE
exit $RSTAT


 

2、删除归档备份和oracle trc等文件的脚本

#!/bin/ksh
# ##################################################################
#
#   delete_archvivelog_backup_and_trc_trm_file.sh
#
#
# ##################################################################
PATH=/usr/bin:/usr/ucb:/etc:.:/usr/X/bin:/bin
export PATH
#find /opt/kfsjora_backup -mtime +15 -name "arch_*" -exec rm "{} /;"
find /opt/kfsjora_backup -mtime +15 -name "arch_*" -exec rm {} \;
find /opt/oracle/admin/kfsjora/adump/ -mtime +15 -name "*.aud" -exec rm {} \;
find /opt/oracle/diag/rdbms/kfsjora/kfsjora/cdump/ -mtime +15 -name "*" -exec rm -fr {} \;
find /opt/oracle/diag/rdbms/kfsjora/kfsjora/trace/ -mtime +15 -name "*.tr?" -exec rm {} \;


 

3、导出Rman catalog数据 的脚本

#!/bin/ksh
# ##################################################################
#
#   exprman.sh
#
#
# ##################################################################
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1; export ORACLE_HOME
PATH=/usr/bin:/usr/ucb:/etc:.:/usr/X/bin:/bin:$ORACLE_HOME/bin:/usr/sbin
export PATH
EXP_BASE=/home/oracle/backup/exprman
export EXP_BASE
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export NLS_LANG

if [ -s  "$EXP_BASE/kfcrman_new.dmp" ];then
  rm $EXP_BASE/kfcrman_old.dmp
  mv $EXP_BASE/kfcrman_new.dmp $EXP_BASE/kfcrman_old.dmp
fi
exp kfcrman/kfcrman@kfcrman tablespaces=KFC3850 file=$EXP_BASE/kfcrman_new.dmp >>$EXP_BASE/../log/expkfcrman.log 2>&1


4、设置 crontab 定期执行上述脚本

$crontab -e

加入如下内容

00 1 * * * /home/oracle/backup/script/kfc_incremental_hot_database_backup.sh &
00 2 * * * /home/oracle/backup/script/delete_archvivelog_backup_and_trc_trm_file.sh >/home/oracle/backup/log/log_delete_archvivelog_backup_and_trc_trm_file.log 2>&1 &
00 5 1 * * /home/oracle/backup/script/expkfcrman.sh


 

 


 

 

你可能感兴趣的:(oracle,Date,command,File,database,oracle11g)