⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oraback.sh

📁 oracle数据库备份脚本
💻 SH
📖 第 1 页 / 共 3 页
字号:
  Log_error $? "Did not find a tracefile in $DUMPDEST."  cp $TRACEFILE $CWD/recreate-controlfile.txt  Log_error $? "Could not copy $TRACEFILE to $CWD/recreate-controlfile.txt."  rm -f $DUMPDEST/tracefile.timefile.empty  Log_error $? "Could not remove $CWD/recreate-controlfile.txt." else    Log_error 1 "$CWD/$DUMPDEST_LIST: File not found" fi if [ -n "$TAPE" ] ; then      #Send disk b/u's to tape   CT=`cat $TMP/$X.CT`   echo `expr $CT + 1` > $TMP/$X.CT   echo "  ${CT}- Tar file of $CWD." |$TLOG   cd $CWD   tar cvf $TAPE ./*  fi}Copy_online_redologs() { [ "$DEBUG" = Y ] && set -x  echo "  Copying online redo logs:  " |$TLOG  cat $CWD/$REDOLOGS_LIST |sed 's/^/   /' |sed 's/  *$//'| $TLOG    cat $CWD/$REDOLOGS_LIST | \  while read REDOLOG  do    LOGBASE=`echo $REDOLOG|sed 's-/-_-g'|sed 's/_//'`    dd if=$REDOLOG bs=64k 2>/dev/null| $COMPRESS -c >$CWD/$LOGBASE.$Z    [ $? -ne 0 ] && Log_error 1 "Error compressing $REDOLOG to $CWD/LOGBASE.$Z"  done}Shutdown_instance() { [ "$DEBUG" = Y ] && set -x echo "  (Shutting down $ORACLE_SID `date` )" |$TLOG Preshut                         #Pre-Shutdown function#I get a lot of questions about the following section.  This way of shutting#down is to ease the concerns of those who believe that a shutdown immediate#is "harsh."  This is what Oracle support advised me to do.  Shutdown immed.,#startup restrict, then shutdown normal.  The sleeps are just to make#sure that it's completely done before starting up/shutting down again. $SVRMGR<<EOF_SID >$TMP/$ORACLE_SID.shut.out 2>&1connect internal;shutdown immediate;host sleep 2startup restrict;host sleep 2shutdown;exit;EOF_SID Error_chk $TMP/$ORACLE_SID.shut.out}Startup_instance() { [ "$DEBUG" = Y ] && set -x echo "  (Starting up $ORACLE_SID `date` )" |$TLOG $SVRMGR<<EOF_STARTUP >$TMP/$ORACLE_SID.start.out 2>&1connect internal;startup;exit;EOF_STARTUP Error_chk $TMP/$ORACLE_SID.start.out Poststart                       #Post-startup function}Throttle() {#This function is used to make sure that no more that $SIMULT datafiles#are being backed up at once. [ "$DEBUG" = Y ] && set -x sleep 2 DDNUM=`ls $TMP/$X.*.*.files.* 2>/dev/null|wc -l|sed 's/ //g'` while [ "$DDNUM" -ge $SIMULT ] do  #Sleep if there are enough files being copied  sleep 10  DDNUM=`ls $TMP/$X.*.*.files.* 2>/dev/null|wc -l|sed 's/ //g'` done}Mail_dba() { [ "$DEBUG" = Y ] && set -x #$X.Mail will only have stuff in it if there were errors somewhere if [ -s $TMP/$X.Mail ] ; then  #If there were errors, mail them to the dba  $L_MAIL $L_S "$MESS" $DBAS < $TMP/$X.Mail else #If there were no errors, check SUCCESSMAIL variable  #If SUCCESSMAIL is set to Y, then notify them of successful backup   if [ "$SUCCESSMAIL" = Y ] ; then    $L_MAIL $L_S "Oracle backup on $HOST successful" $DBAS < $LOG   fi fi}Copy_config_files() {if [ -n "$IFILE" ] ; then if [ -f "$IFILE" ] ; then  echo "  Backing up $IFILE" | $TLOG  cp $IFILE $CWD else  Log_error 1 "Ifile (${IFILE}) not found." fifiif [ -n "$PFILE" ] ; then if [ -f "$PFILE" ] ; then  echo "  Backing up $PFILE " | $TLOG  cp $PFILE $CWD else  Log_error 1 "Pfile (${PFILE}) not found." fifiif [ -n "$TNSNAMES" ] ; then if [ -f $TNSNAMES ] ; then  echo "  Backing up $TNSNAMES" | $TLOG  cp $TNSNAMES $CWD else  Log_error 1 "Pfile (${TNSNAMES}) not found." fifiif [ -n "$SQLNET" ] ; then if [ -f $SQLNET ] ; then  echo "  Backing up $SQLNET" | $TLOG  cp $SQLNET $CWD else  Log_error 1 "Pfile (${SQLNET}) not found." fifiif [ -n "$LISTENER" ] ; then if [ -f $LISTENER ] ; then  echo "  Backing up $LISTENER" | $TLOG  cp $LISTENER $CWD else  Log_error 1 "Pfile (${LISTENER}) not found." fifi}Check_bkmode() { [ "$DEBUG" = Y ] && set -x$SVRMGR << EOF > $TMP/$X.ckbkmode 2>&1connect internal;select * from v\$backup where status = 'ACTIVE';exit;EOF ACTIVE=`awk '{print $2}' $TMP/$X.ckbkmode|grep ACTIVE` [ -z "$ACTIVE" ] || Log_error 1 "Some files are still in backup mode!"}# Check to see if this program was called by another, and should not rewind the tapeif [ "$1" = norewind ] ; then      NOREWIND=Y	shiftfi#Setup log and global variables in case localpath.sh barfsL_MAIL=mail ; L_S='' ; MESS='' ; export L_MAIL L_S MESSif [ -f $BINDIR/config.guess ] ; then LOCAL_OSnR=`$BINDIR/config.guess` export LOCAL_OSnRelse Log_error 1 "NO $BINDIR/config.guess - ABORTING BACKUP" exitfi. $BINDIR/localpath.shMESS="ORACLE BACKUP ERROR!" ; export MESSif [ ! -s $ORATAB ]; then Log_error 1 "NO $ORATAB - ABORTING BACKUP" exitfiLOG=$PERMLOG.tmpcp /dev/null $LOGLog_error $? "Unable to create $LOG" exitchown $ORACLE $LOGLog_error $? "Unable to chown owner to $ORACLE $LOG" exitTLOG="tee -a $LOG"X=$$LOGFILE_LIST=logfile.listCONTROLFILE_LIST=controlfile.listREDOLOGS_LIST=redologs.listTBLSPACE_LIST=tablespace.listDUMPDEST_LIST=dumpdest.listexport X LOGFILE_LIST CONTROLFILE_LIST TBLSPACE_LIST REDOLOGS_LISTexport DUMPDEST_LISTHOST=`uname -n|awk -F'.' '{print $1}'`[ -n "$HOST" ] || HOST=`hostname|awk -F'.' '{print $1}' `if [ -z "$HOST" ] ; then Log_error 1 "Unable to obtain hostname!" exitfiSKIP=`grep "^$HOST.master:" $ORACONF | awk -F':' '{print $2}' `COLD=`grep "^$HOST.master:" $ORACONF | awk -F':' '{print $3}' ` [ "$COLD" -gt 0 ] 2>/dev/null  &&  DAY=`date +%d`  ||  DAY=`date +%a` [ "$COLD" = '*' ]  &&  COLD=$DAY if [ "$DAY" = "$COLD" ] ; then  TYPE=COLD  TIME=`grep "^$HOST.master:" $ORACONF  | awk -F':' '{print $4}' ` else  TYPE=HOT  TIME=`grep "^$HOST.master:" $ORACONF  | awk -F':' '{print $5}' ` fiTAPE=`grep "^$HOST.master:" $ORACONF  | awk -F':' '{print $6}' `USERS=`grep "^$HOST.master:" $ORACONF | awk -F':' '{print $7}' ` [ -z "$USERS" ]  &&  USERS=$ORACLESIMULT=`grep "^$HOST.master:" $ORACONF | awk -F':' '{print $8}' `BACKUPDIR=`grep "^$HOST.master:" $ORACONF |awk -F':' '{print $9}' `if [ ! -d "$BACKUPDIR" ] ; then echo "Backup directory $BACKUPDIR does not exist!  Exiting..." ; exit 1fiif [ -n "$TAPE" -a -n "$SIMULT" ] ; then echo "Simultaneous backups not supported for" |$TLOG echo "tape devices.  (Will do serially.) " |$TLOG SIMULT=''  ;  export SIMULTfiCOMP=`grep "^$HOST.master:" $ORACONF | awk -F':' '{print $10}' `DBAS=`grep "^$HOST.master:" $ORACONF |awk -F':' '{print $11}' `#This section is to let users know if they need to change the format#of $ORACONF, since the MAIL command is now figured out in localpath.shif [ -n "`echo $DBAS|grep '[Mm]ailx* '`" ] ; then DBAS=`echo $DBAS|sed 's/.* //'` echo "WARNING: You need to change to the format of field 11 in oraback.conf.It now only needs to contain the mail id's that will get the mail.It has been changed to $DBAS for this run of $0,but you will need to change it in $ORACONFto make the change permanent."fiWHO=`id | awk -F'(' '{print $2}' | awk -F')' '{print $1}' `if [ -z "$BACKUPDIR" -o -z "$DBAS" ] ; then  echo "Field 9 or 12 in $ORACONF is empty!"   |$TLOG  echo "(9=BACKUPDIR, 12=complete Mail command)" |$TLOG  exit 1fi                                   #Build list of SID'sif [ $# -ne 0 -a "$1" != "at" ] ; then GREP=`echo $* | sed 's/ /:|^/g' | sed 's/$/:/'` ORACLE_SID_LIST=`egrep "^$GREP" $ORATAB` ARG=backupelse ORACLE_SID_LIST=`grep -v '^\#' $ORATAB|grep -v '\*'` case $1 in  query )   QUERYONLY=Y ; ARG=backup  ;;  at )   ARG=at  ;;  * )   ARG=backup  ;; esacfiif [ -z "`echo $WHO | egrep \"$USERS\"`" ] ; then echo "WRONG LOGIN!\n" Usagefitouch $ORACONF ${ORACONF}.2Log_error $? "Unable to create $ORACONF.2 (Needed 4 SKIP feature.)" exit                    #Skip b/u if find "skip" in ORACONFif [ "$SKIP" = "skip" ]; then sed "s/$HOST.*:skip:/$HOST.master::/" $ORACONF >${ORACONF}.2 mv -f ${ORACONF}.2 $ORACONF echo "SKIPPING $0 ON $HOST TONIGHT ONLY DUE"   |$TLOG echo "TO THE WORD \"skip\" IN $ORACONF!!"      |$TLOG cat $LOG >>$PERMLOG exit 0ficase ${ARG} inat) #Check's $ORACONF for what time the sheduled backup is to run, and then #schedules an 'at' job to run the script with no args, which will put it #in the 'backup' case of this case statement if [ -z "$TIME" ]; then  Log_error 1 "No backup time found in $ORACONF" exit  exit 1 ficase $LOCAL_OSnR in #The -s option is available in most unixes, and specifies to #start an at job w/Bourne sh.  If you can't use this, and you #are using csh as Oracle's shell, you'll need to change the output #redirection in the section that creates the at job #(This is one of the many reasons why I hate csh...) *hpux*|*irix* ) _S=''   ;; * )     _S='-s' ;;esac at $_S $TIME <<EOF_AT          $BINDIR/oraback.sh > $TMP/oraback.out 2>&1EOF_AT;;backup)#Actually run backup echo "==============================================================" |$TLOG echo "Oracle database backup started on $HOST: `date '+%X %m/%d/%Y'`" |$TLOG echo "==============================================================" |$TLOG echo "1" > $TMP/$X.CT Preback                           #Pre-backup function cd $TMP LABEL="$0 $* `date +%m/%d/%Y`" LABEL=`echo $LABEL| sed 's/ /_/g'|sed 's-/-_-g'` echo |tee -a $LOG echo "Creating table of contents for this backup..." |tee -a $LOG if [ -n "$TAPE" ] ; then  echo "Then placing it as a file called $LABEL on $DEVICE" |tee -a $LOG  echo "(and verifying that $DEVICE is set to NO-REW...)" |tee -a $LOG fi echo |tee -a $LOGcat >$LABEL <<EOF_HEAD----------------------------------------------------------------------This tape is a full backup of the Oracle instances on $HOST made `date`The following is a table of contents of this backup.(This information is most useful if the backup is sent to tape.)It is in the following format: INSTANCE:ORACLE_SID:ORACLE_HOME_DIR:DATABASE_STATUS (in a 3 letter code) ------------------- ORACLE_SID:FILE_NUMBER:TABLESPACE_NAME:DATA_FILE_NAME ORACLE_SID:FILE_NUMBER:TABLESPACE_NAME:DATA_FILE_NAME INSTANCE:ORACLE_SID:ORACLE_HOME_DIR:DATABASE_STATUS (in a 3 letter code) ------------------- ORACLE_SID:FILE_NUMBER:TABLESPACE_NAME:DATA_FILE_NAME ORACLE_SID:FILE_NUMBER:TABLESPACE_NAME:DATA_FILE_NAMETo recover any of the DATA_FILEs:1. cd to the directory that should contain that file.2. $L_MT $L_F $DEVICE fsf FILE_NUMBER3. dd if=$DEVICE bs=64k of=DATA_FILE_NAMEWARNING!  Databases can go up and down in the middle of a backup!That will drastically affect what gets put on this tape!This table of contents represents only what SHOULD be put on the tape,based on the DB_STAT information at the time of label creation.If there is any question as to what actually went TO the tape, the logof this session will be appended to this tape as a tar file.To read that tar file follow these steps:1. Look at the highest FILE_NUMBER listed2. $L_MT $L_F $DEVICE fsf (FILE_NUMBER + 1)3. tar xvf $LOGIf this works, then all the files went to the tape.  If it does not work,it means that some did not go to the tape because a database was downwhen it should have been up, or some other reason.  If that is the case, thenuse the following loop:COUNT=1while truedo  tar xvf $DEVICE   if [ \$? -eq 0 ] ; then     exit    else     $L_MT $L_F $DEVICE  $L_REWIND     $L_MT $L_F $DEVICE  fsf \$COUNT     COUNT=\`expr $COUNT + 1\`   fidoneALSO, this program now supports a no-rewind option, which allows it to becalled by another program (e.g. hostdump.sh).  If called with this argument,the tape will not start at the beginning.  This means that the tape filethat will have the tar file will be unpredictable.----------------------------------------------------------------------The proposed table of contents for this backup:EOF_HEADFILE_NUMBER=1           #Initialize the counter                        #For each SID we are backing up for LINE in $ORACLE_SID_LIST do  ORACLE_SID=`echo $LINE  | awk -F':' '{print $1}' `  CWD=$BACKUPDIR/$ORACLE_SID  ORACLE_HOME=`echo $LINE | awk -F':' '{print $2}' `  Find_config_files

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -