Monday, August 6, 2012

Schedule Creation of MKSYSB to NIM Server

I have a customer that has a fair amount of systems they need to protect. Recently we had a corruption that required the re-install of the operating system. While this is an extremely rare event on modern systems, the problem was compounded by the fact they didn’t have a good mksysb backup. We needed to find a system that was similar (Test/Dev), locate the tape drives, move them to the source, take the backup, move the tape to the target and re-install. Not a fun evening and all the trouble could have easily been adverted by having a good backup.
If you have more than four AIX systems I would recommend having a NIM server. This should be your point of administration for everything done in AIX if possible. Also it gives you an environment to script, upgrade and deploy without working on your production systems.
This is a script I wrote to be executed by cron on the NIM server. It does a few things here:
  1. Queries NIM for a list of “standalone” systems
  2. Performs a mksysb backup of each and registers them on the NIM server as a resource
  3. Creates a backup of the volume group that all my NIM data is on. (I know you didn’t put it on rootvg!)
  4. Ejects the tape so it can be brought offsite
  5. Emails the report to the admin
#!/usr/bin/sh
 
DATE=`date +%m%d%Y`
LOGFILE=/tmp/mksysblog_${DATE}
SENDTO="admin@domain.com"
MSGCONTENT=""
 
LOG()
{
    echo "$*" >> $LOGFILE 2>&1
}
 
LOG "------------ MKSYSB LOG FOR ${DATE} ------------------"
TIME=`date`
LOG "Process started at ${TIME}"
 
#for mach in 0; do
for mach in $(lsnim -t standalone | awk '{print $1}'); do
    LOG ""
    LOG ""
    LOG "**************************************************"
    LOG "Starting process for ${mach} "
    LOG "Removing the NIM resources for ${mach}"
 
    nim -o remove ${mach}_mksysb >> $LOGFILE 2>&1
 
    LOG "NIM resources removed for ${mach}"
    LOG ""
    LOG "Starting mksysb backup of ${mach}"
    nim -o define -t mksysb -a server=master -a location=/export/mksysb/${mach}_mksysb -a source=${mach} -a mk_image=yes -a mksysb_flags="-i -m -e -p" -F ${mach}_mksysb >> $LOGFILE 2>&1
    if [ $? != 0 ]
        then
        echo "ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR" > ${MSGCONTENT}
        mail -s "MKSYSB error on ${mach}" "${SENDTO}" < ${MSGCONTENT}
        LOG "  ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR "
        LOG " There was an error of ${mach} "
        echo "" > ${MSGCONTENT}
    fi
    LOG "Completed the mksysb of ${mach}"
done
 
LOG "Starting the SAVEVG of NIM_VG"
/usr/bin/savevg -vmpXf /dev/rmt0 nim_vg >> $LOGFILE 2>&1
if [ $? != 0 ] then
    echo "ERROR on SAVEVG " > ${MSGCONTENT}
    mail -s "ERROR on SAVEVG" ${SENDTO} < ${MSGCONTENT}
    LOG " ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR "
    LOG "There was an error on the NIM server while saving to tape"
    echo "" > ${MSGCONTENT}
fi
LOG "Completed the SAVEVG"
LOG "Rewinding and ejecting the tape"
mt -f /dev/rmt0 rewoffl
LOG "Backup process complete"
 
TIME=`date`
LOG "Completed at ${TIME}"
 
mail -s "MKSYSB Process Log" "${SENDTO}" < ${LOGFILE}




As always use as needed, but please comment if you have them.


Cheers

No comments:

Post a Comment