【脚本】备份数据库




  • 1.shell脚本:startrman.sh

    #!/bin/bash
    # Created date: 2006-04-21 12:00
    # Author : dbstyle
    # Name : startrman.sh
    # Description:
    # Backup database by rman

    # MODIFIED (MM/DD/YYYY)
    # dbstyle 04-21-2006 create script

    #------------------------------------------------------------------------------------------------------------
    #Environment variable setting
    #------------------------------------------------------------------------------------------------------------
    . /opt/oracle/.profile
    SH_HOME=/opt/oracle/dbmon/dbstyle/rmanbak
    export SH_HOME
    RM_COMMAND=/bin/rm
    MAIL_COMMAND=/bin/mail
    DBA="dbstyle@gmail.com"
    DATE=`date +"%Y%m%d"`
    week=`date +"%w"`
    #-----------------------------------------------------------------------
    #Confirm whether the oracle is runing
    #-----------------------------------------------------------------------
    sqlplus -s "/as sysdba"<<EOF
    whenever sqlerror exit 1
    whenever oserror exit 1
    select sysdate from dual;
    exit
    EOF

    if [ $? -gt 0 ]; then
    exit
    fi

    #-----------------------------------------------------------------------
    #Begin to backup
    #-----------------------------------------------------------------------
    if [ $week = "1" ] || [ $week = "4" ] ; then
    rman target / @$SH_HOME/fullback.sql log=$SH_HOME/log/rmanfullback`date +"%Y%m%d"`.log
    $MAIL_COMMAND -s "$ORACLE_SID : RMAN FULL BACKUP $IP" $DBA<$SH_HOME/log/rmanfullback`date +"%Y%m%d"`.log
    more $SH_HOME/log/rmanfullback`date +"%Y%m%d"`.log | grep 'RMAN-'>$SH_HOME/log/rmanerror.log
    else
    rman target / @$SH_HOME/archback.sql log=$SH_HOME/log/rmanarchback`date +"%Y%m%d"`.log
    $MAIL_COMMAND -s "$ORACLE_SID : RMAN ARCHIVELOG BACKUP $IP" $DBA<$SH_HOME/log/rmanarchback`date +"%Y%m%d"`.log
    more $SH_HOME/log/rmanarchback`date +"%Y%m%d"`.log | grep 'RMAN-' >$SH_HOME/log/rmanerror.log
    fi
    #-----------------------------------------------------------------------
    #Mail Error Infor to DBA
    #-----------------------------------------------------------------------
    if [ `cat $SH_HOME/log/rmanerror.log|wc -l` -gt 0 ]; then
    $MAIL_COMMAND -s "$ORACLE_SID : RMAN BACKUP ERROR $IP" $DBA <$SH_HOME/log/rmanerror.log
    fi

    #-----------------------------------------------------------------------
    #Delete obsolete file
    #-----------------------------------------------------------------------
    find $SH_HOME/log -name "*.log" -mtime +730 -exec rm {} \;

     

     

    2.全备脚本:fullback.sql

    run{
    backup full tag 'smsapreg' database include current controlfile format '/rgback/oracle/rmanback/smsapregfullback_%d_%T_%s' plus archivelog format '/rgback/oracle/rmanback/smsapregarch_%d_%T_%s' delete all input;
    crosscheck backup;
    delete expired backup;
    delete obsolete;
    }

     

    3.备份归档:archback.sql

    run{
    backup archivelog all format '/rgback/oracle/rmanback/smsapregarch_%d_%T_%s' delete all input;
    }

    Speak Your Mind

    *

    京ICP备14059771号-2