[Back To HomePage and Script Library]

Disclaimer: Use these scripts and/or any recommendations they may contain at your own risk. These scripts may or may not have been tested.

Title: Backing Up Archive Logs to ADSM

Author: Paul Schwerdtfeger, a database administrator
      for First Trust Corporation in Denver, Colorado.

      This script runs every 15 minutes through cron. It monitors the size of the archive logs
      directory. When the directory becomes 70% or greater utilized, it suspends logging,
      moves the archive logs, resumes logging and then sends the archived logs to ADSM to
      be backed up. After the backup is complete, the archive logs are removed from the
      backup directory.
Source/Text/Comments


      #
      # This script will check the amount of space used in the Archive Logs directory.
      # If greater than 70% utilized, it will suspend logging, move the log files and
      # back them up to ADSM.
      #
      #
      # This script will check the amount of space used in the Archive Logs directory.
      # If greater than 70% utilized, it will suspend logging, move the log files and
      # back them up to ADSM.
      #
      # Revision History:
      #
      #    Date      Who  Modification
      # -----------  ---  -------------------------------------------------------------
      # 09 April 1999  prs  Creation.
      # 18 April 1999  prs  Check to see if ADSM is already running.  Exit if it is.
      #
      #-----------------------------------------------------------------------------------
       #
      # Set Local Variables
      #
      . $HOME/crontab.env

      TDATE=`date +"%y%m%d"`
      LOGFILE=/home/oracle7/backarch${TDATE}.log
      ARCHDIR=/archivelogs
      TEE="tee -a ${LOGFILE}"

      #
      # Check to see if ADSM is already running.  If so, exit.
      #
      STATUS=`ps -fu oracle7 | grep -v grep | grep -c "dsmc selective"`
      if [ "$STATUS" != "0" ]; then
         echo "ADSM is currently backing up ${ARCHDIR}.  Exiting." | $TEE
         echo " " | $TEE
         exit
      fi

      #
      # Get the percentage in use of the file system. Strip off the '%' sign.
      #
      INUSE=`df -k ${ARCHDIR} | tail -1 | awk '{print $4}' | sed -e 's/%//'`;  export INUSE

      #
      # if file system is less then 70% utilized exit the script
      #
      if [ "$INUSE" -le 70 ]
      then
         echo "`date` ${ARCHDIR} is ${INUSE}% utilized.  Exiting." | $TEE
         exit
      fi

      echo "`date` ${ARCHDIR} is ${INUSE}% utilized.  RUNNING..." | $TEE
      echo "Current ORACLE_SID: ${ORACLE_SID}" | $TEE

      #
      # file system is > 70% utilized.  Connect to Oracle, Suspend archiving,
      # Move the archive logs to the backup directory, restart archiving.
      #
      svrmgrl <${LOGFILE} | $TEE
      STATUS="$?"
      if [ "$STATUS" != 0 ]
      then
         echo "`date` ERROR ${STATUS} received from ADSM." | $TEE
         exit
      fi
      echo "`date` Files Moved to ADSM:" | $TEE
      ls -ltr ${ARCHDIR}/backup/* | $TEE
      echo " " | $TEE
      #
      # Remove the files from the backup directory
      #
      rm ${ARCHDIR}/backup/*
      STATUS="$?"
      if [ "$STATUS" != 0 ]
      then
         echo "`date` Error ${STATUS} removing files from the backup directory." | $TEE
      else
         echo "`date` removed files from the backup directory." | $TEE
      fi
      echo "---------------------------------------" | $TEE