Wednesday, July 27, 2011

Automated creation of mksysb and copy to NFS Server

I have a bunch of systems that we are working on, however we don’t have the tape library connected yet. It makes me very nervous to not have any backups so I put this together. It creates a mksysb on the local system and copies it to the NFS export. In my case I created this on my NIM server so if I needed to create a SPOT and reinstall or cut it to tape it’s already available there.
It’s pretty much ready to use so all you only need to do a few things:
  1. Update the variables
  2. Copy it to each system
  3. Schedule with cron

HOSTNAME=`uname -a | awk '{print $2}'`
DATE=$(date +%m%d%Y)

# Check to make sure the directory we need to mount is created
if [ ! -e "/mksysb/nfs_mksysb" ]; then
    mkdir -p /mksysb/nfs_mksysb

# Determine if the NFS share is mounted unless it's the server serviing the NFS Mount
if [ ! "$NFSSERVER" == "$HOSTNAME" ]; then
    mount | grep nfs_mksysb || mount "$NFSSERVER:/mksysb/nfs_mksysb" "$BACKUPDIR"
    mount | grep nfs_mksysb && MOUNTED = 1

# Ensure the directory for the system is created
if [ ! -e "$BACKUPDIR/$HOSTNAME" ]; then
    mkdir -p "$BACKUPDIR/$HOSTNAME"

# Everything is mounted and ready to go - lets create our backup
/usr/bin/mksysb -e -i "/mksysb/$FILENAME"

# MKSYSB is completed so lets copy it over to the NFS share

# Clean up local directories
find /mksysb \( ! -name mksysb -prune \) -name "$HOSTNAME.*" -mtime +$RETAIN_LOCAL_BACKUPS -exec rm {} \;

# Clean up NFS share
find "${BACKUPDIR}/${HOSTNAME}" -name "${HOSTNAME}.*" -mtime +${RETAIN_NFS_BACKUPS} -exec rm {} \;

# We are finished so lets unmount the share
[ ! -z "$MOUNTED" ] && umount /mksysb/nfs_mksysb

No comments:

Post a Comment