Michael Doran Home Page
Contact | Site Map | Search  
  Home > Archives > Using Scripts > bk-vygr-dl0
This page is deprecated: please read archives disclaimer.

Using Scripts to Automate Voyager Tasks

bk-vygr-dl0

Session File


#!/bin/sh

###############################################################
#
#   Shell Script: bk-vygr-dl0
#   Backup Voyager database, dump level 0
#   1998 & 1999, Michael Doran, doran@uta.edu
#   University of Texas at Arlington Libraries
#
###############################################################

# Variables:
 args=0ucvf                       # Arguments to ufsdump
 mt_pt=/m1                        # File system mount point
 script_name=$0                   # Script name
 sess_file=/tmp/bklog.$$          # Session file
 tape_dev=/dev/rmt/0cb            # Tape device, w/ compression
 trash_can=/dev/null              # Unwanted output

# for "operator" see /etc/mail/aliases 

# Function to start and stop Voyager servers
servers ()
{
  case "$1" in
  'start')
        /etc/init.d/dbora $1 >> ${trash_can} 2>&1
        /etc/init.d/httpd $1 >> ${trash_can} 2>&1
        /etc/init.d/voyager $1 >> ${trash_can} 2>&1
        ;;
  'stop')
        /etc/init.d/dbora $1 >> ${trash_can} 2>&1
        /etc/init.d/httpd $1 >> ${trash_can} 2>&1
        ;;
   *)
        echo "Usage: servers {start|stop}"
        ;;
  esac
}

# Function to add comments to session file
add ()
{
    /usr/bin/echo "$1" >> ${sess_file}
}

# Function to mail session file to operator
swoosh ()
{
    /usr/bin/mailx -s "$1" operator < ${sess_file}
}

# Provide session file with script name and date
add "Script: ${script_name}\n`date`"
add "Full backup of Voyager database.\n"

# Check for tape:
/usr/bin/mt -f ${tape_dev} status >> ${trash_can} 2>&1
if [ $? -ne 0 ]     # If no tape
then                # notify operator and ...
    add "Backup aborted: No tape in drive."
    swoosh "Backup error"
    exit 1          # abort the backup.
fi 

# shut down servers
servers stop

# run "savecritical" script (per Voyager Technical Manual)
/m1/utility/savecritical >> ${trash_can} 2>&1

# Unmount the Voyager file system
/usr/sbin/umount ${mt_pt} >> ${trash_can} 2>&1
if [ $? -ne 0 ]   # If not successful
then
    # kill processes that are using Voyager resources
    /usr/sbin/fuser -c -k ${mt_pt} >> ${trash_can} 2>&1
    # and try again to unmount
    /usr/sbin/umount ${mt_pt} >> ${trash_can} 2>&1
    # If it still won't unmount...
    if [ $? -ne 0 ]
    then
        # Record processes and users using the mount point
        add "Output of fuser -c -u ${mt_pt}..."
        /usr/sbin/fuser -c -u ${mt_pt} >> ${sess_file} 2>&1
        # restart the Voyager and Web Servers, ...
        servers start
        # notify operator, and ...
        add "Backup aborted: Unable to unmount filesystem."
        swoosh "Backup error"
        # abort the backup.
        exit 1
    fi
fi

# Do backup
/usr/sbin/ufsdump ${args} ${tape_dev} /dev/md/rdsk/d0 >> ${sess_file} 2>&1

# Remount the Voyager file system
/usr/sbin/mount /dev/md/dsk/d0 ${mt_pt} >> ${sess_file} 2>&1
# Did the Voyager file system remount?
if [ $? -ne 0 ]  # If not...
then
    # notify operator, and ...
    add "Unable to remount ${mt_pt}\n ... will reboot the system."
    swoosh "Backup Log /w error"
    # reboot system.
    /usr/sbin/init 6
    exit 1
else  # If yes...
    # restart the Voyager and Web servers.
    servers start
    # Did Voyager restart?
    if [ $? -ne 0 ]
    # If not...
    then
        # notify operator, and ...
        add "Unable to restart Voyager.\n ... will reboot the system."
        swoosh "Backup Log /w error"
        # reboot system.
        /usr/sbin/init 6
        exit 1
    fi
fi

# Send session file to operator...
add "\\n${script_name} completed\\t`date`"
swoosh "Backup Log"

# and exit script.
exit 0