Home Contact
Validate the HTML of this page

MetaLib/SFX NetWorker Script

save-exlibris

Session File
#!/bin/sh

###############################################################
#
#   Shell Script: save-exlibris
#
#   2004-2007, Michael Doran, doran@uta.edu
#   University of Texas at Arlington Library
#
#   This custom backup program takes the place of (and
#   incorporates) the "save" command used by the Legato
#   NetWorker utility.  It must reside in the same
#   directory as "save" (i.e. /usr/bin/save).
#   There is a symbolic link to /usr/bin/save-exlibris 
#     from /usr/sbin/save-exlibris
#
#   See on NetWorker Administrator -> Manage Clients ->
#	 {this_server} (/exlibris filesystem)
#        Remote [tab] -> Backup command: save-exlibris
#   Save set: /exlibris
#
#   2007 - added MetaLib shutdown to backup
#   2007 - utilizing fssnap to minimize database downtime
#
###############################################################

######################################
# Variables:
 host_name=`uname -n`                # Server name
 script_name=$0                      # Script name
 sess_file=/tmp/backuplog.$$         # Session file
 trash_can=/dev/null                 # Unwanted output
# Added for fssnap
 file_sys=/exlibris                  # Ex Libris file system
 bs_dir=/var/fssnap                  # Backing store directory
 bs_file=${bs_dir}${file_sys}-bsf    # Backing store file
 tmp_mnt_pnt=/exlibris-snap          # Temporary mount point


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

######################################
# Function to mail error messages
senderr ()
{
    /usr/bin/echo "$1" | mailx -s "$0 error" -c doran operator
}

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

# Function to send pager message to sysdamin
beepsysadmin ()
{
    /usr/bin/echo "$1" | /usr/bin/mailx -s "$1" -c beep-doran operator
}

######################################
# Function to start and stop SFX and MetaLib server(s)
servers ()
{
  case "$1" in
  'start')
        add "\nStarting SFX V3 Apache and MySQL servers\n"
	/etc/init.d/sfxd $1 >> ${trash_can} 2>&1
        add "Starting MetaLib server processes\n"
	/etc/init.d/exlibris $1 >> ${trash_can} 2>&1
        ;;
  'stop')
        add "\nStopping SFX V3 Apache and MySQL servers\n"
	/etc/init.d/sfxd $1 >> ${trash_can} 2>&1
        add "Stopping MetaLib server processes\n"
	/etc/init.d/exlibris $1 >> ${trash_can} 2>&1
        ;;
   *)
        echo "Usage: servers {start|stop}"
        ;;
  esac
}

######################################
# Provide session file with script name and date
add "Script: ${script_name}\t`date`"
add "Backup of ${host_name}:/exlibris filesystem via NetWorker.\n"

######################################
# Shutdown SFX & MetaLib servers
servers stop

# Create backing store directory if needed
if [ ! -d ${bs_dir} ]
then
    mkdir -p ${bs_dir} >> ${sess_file} 2>&1
fi

# Create UFS snapshot
block_snap_dev=`/usr/sbin/fssnap -F ufs \
 -o unlink,backing-store=${bs_file} ${file_sys}`

add "\n${file_sys} backup via ${block_snap_dev} snapshot mounted on ${tmp_mnt_pnt}"
# For now, let's include this info in session file...
add "\nUFS Snapshot information..."
/usr/lib/fs/ufs/fssnap -i >> ${sess_file} 2>&1

add "\n"

# start SFX & MetaLib servers back up
servers start

if [ ! -d ${tmp_mnt_pnt} ]
then
    mkdir ${tmp_mnt_pnt} >> ${sess_file} 2>&1
fi

# Mount snapshot on temporary mount point
/usr/sbin/mount -F ufs -o ro ${block_snap_dev} ${tmp_mnt_pnt} \
        >> ${sess_file} 2>&1

######################################
# Do backup via NetWorker save command.
add "Running NetWorker save command"
/usr/sbin/save "$@"

exit_status=$?
add "NetWorker exit status: ${exit_status}"
if [ ${exit_status} -ne 0 ]  # If save had problems
then
    beepsysadmin "`uname -n` backup problem"
fi

# Unmount snapshot from temporary mount point
/usr/sbin/umount ${block_snap_dev} >> ${sess_file} 2>&1

add "\n"

/usr/lib/fs/ufs/fssnap -i | \
  egrep "Mount|Block|Backing store size" \
  >> ${sess_file} 2>&1

add ""

# Delete UFS snapshot
/usr/sbin/fssnap -d ${file_sys} >> ${sess_file} 2>&1

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

# and exit script.
exit 0