#!/usr/bin/ksh

#
# This script will soft mount /backup from server 10.1.2.3
# and create a mksysb image for server restores
#

TODAY=`date +%d%m%Y`

# Set DIR and LOG to the location of the summary log file.
DIR=/var/adm/log/nimlog
LOG="${DIR}/nim.backup-`uname -n`.$TODAY"

# Set FMNT to the IP address of the server you are mounting
# the NFS share of.
FMNT=10.1.2.3

MNT="-o soft,bg $FMNT"
UNAME=`hostname`

# Set LOGFILE to the location of your logfile on the client.
LOGFILE=/var/adm/backup/mksysb.${UNAME}

# Set UMNT to the mountpoint where you want to mount
# the NFS share of the NFS server onto the local server.
UMNT="/mksysbck"

# Set RMNT to the file system on the NFS server that should
# be mounted on the client.
RMNT="/backup"

if [ ! -d $DIR ] ; then
  mkdir $DIR
fi
cd $DIR
find ${DIR} -type f -mtime +14 -exec rm {} \;

if [ "`mount | grep $UMNT`" != "" ] ; then
   umount ${UMNT}
fi

if [ ! -d $UMNT ] ; then
    mkdir $UMNT
fi

if [ ! -d $DIR ] ; then
    mkdir $DIR
fi

/usr/sbin/mount $MNT:$RMNT $UMNT
status=$?

if [ $status != 0 ] ; then
  echo "$FMNT is not NFS mounting!!"
  exit 2
fi

START="Start: `date +%m%d%Y-%H%M` "
mksysb -m -p -e -v /mksysbck/$UNAME.image > $LOG 2>&1
result=$?

if [ $result != 0 ] ; then
  echo "MKSYSB result code: $result. Check results"
fi

END="End: `date +%m%d%Y-%H%M` Code: $result"
echo "${START}${END}" >> ${LOGFILE}
umount ${UMNT}
