ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle 备份脚本

oracle 备份脚本

原创 Linux操作系统 作者:kidking2010 时间:2012-01-12 13:55:38 0 删除 编辑

a、用oracle用户建立备份目录
b、 crontab -e
在linux下编辑时间任务(root用户)
写入如下
0 4 * * 0-6 su - oracle -c /home/oracle/oraclebackup/backupSH/logicbackup.sh
30 4 * * 0-6  su - oracle -c /home/oracle/oraclebackup/backupSH/hotbackup.sh
0 5 1 * * su - oracle -c /home/oracle/oraclebackup/backupSH/coldbackup.sh


备份脚本1 logicbackup.sh
#!/bin/sh
backuppath=/home/oracle/oraclebackup/backupData/logicData
current_month=`date +%Y_%m`
current_day=`date +%Y_%m_%d`
mkdir -p ${backuppath}/${current_month}/${current_day}
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
/u01/oracle/10g/bin/exp userid=gdeii/gdeii123@sch206 file=${backuppath}/${current_month}/${current_day}/logic_${current_day}.dmp log=${backuppath}/${current_month}/${current_day}

备份脚本2hotbackup.sh
#!/bin/ksh 

export LANG=en_US

BACKUP_DATE=`date +%d`

backupDIR=/home/oracle/oraclebackup/backupData/hotData
current_month=`date +%Y_%m`
current_day=`date +%Y_%m_%d`
export rman_back_dir=$backupDIR/$current_month/$current_day
mkdir -p $rman_back_dir

RMAN_LOG_FILE=${rman_back_dir}/rmanlog_${current_day}.log

TODAY=`date`

USER=`id|cut -d "(" -f2|cut -d ")" -f1`

echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE

ORACLE_HOME=/u01/oracle/10g

export ORACLE_HOME

RMAN=$ORACLE_HOME/bin/rman

export RMAN

ORACLE_SID=sch206

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 target sys/gdeii123 catalog catalog/catalog@sch206  msglog $RMAN_LOG_FILE append <

run

{
allocate channel c1 type disk;
allocate channel c2 type disk;

backup incremental level $BAK_LEVEL Database format='${rman_back_dir}/dbk_level${BAK_LEVEL}_%U_%T.dbf'  tag='orcl_lev"$BAK_LEVEL"';
sql 'alter system archive log current';
backup archivelog all tag='arc_bak' format='${rman_back_dir}/archlog_level${BAK_LEVEL}_%U_%T';
backup current controlfile tag='bak_ctlfile' format='${rman_back_dir}/ctl__level${BAK_LEVEL}_%U_%T';
backup spfile tag='spfile' format='${rman_back_dir}/orcl_spfile_level${BAK_LEVEL}_%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 ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE 

echo >> $RMAN_LOG_FILE 

3 coldbackup.sh 冷备份脚本
#!/bin/bash
srcPath=/u01/oracle/oradata/sch206
srcdbs=/u01/oracle/10g/dbs

thedate=`date +%Y_%m_%d`

backuppath=/home/oracle/oraclebackup/backupData/coldData/$thedate/
backupdbs=/home/oracle/oraclebackup/backupData/coldData/$thedate/dbs/

mkdir -p $backuppath/dbs

$ORACLE_HOME/bin/sqlplus "/as sysdba" <
shutdown immediate

!cp $srcPath/*.dbf $backuppath
!cp $srcPath/*.ctl $backuppath
!cp $srcPath/*.log $backuppath
!cp $srcdbs/* $backupdbs

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23141985/viewspace-714816/,如需转载,请注明出处,否则将追究法律责任。

上一篇: oracle 备份脚本
下一篇: 自动开机
请登录后发表评论 登录
全部评论

注册时间:2011-02-27

  • 博文量
    108
  • 访问量
    303482