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
#!/usr/bin/ksh

HOSTNAME=`uname -a | awk '{print $2}'`
DATE=$(date +%m%d%Y)
FILENAME=$HOSTNAME.$DATE
RETAIN_LOCAL_BACKUPS=1
RETAIN_NFS_BACKUPS=7
BACKUPDIR="/mksysb/nfs_mksysb"
NFSSERVER="NFSServer"

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

# 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
fi

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

# 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
cp "/mksysb/$FILENAME" "$BACKUPDIR/$HOSTNAME/"

# 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

Friday, July 15, 2011

Collect WWN from AIX Systems

I have a need to collect all the WWN from my AIX systems that are running. Unfortunately I’m inheriting this environment from someone and they didn’t keep records and I’m really not interested in the other method of getting them from the HMC.
I have a file that has all the systems or IP address that I need the names from called “hostfile” in the current directory – you can parse this from any file you have with just a bit more scriptfu if you need.
for x in `cat hostfile | sort`
do
        echo $x
        ssh root@$x "for i in \`lsdev -Cc adapter | grep fcs | awk '{print \$1}'\`; do \
                lscfg -vpl \$i | grep 'Network Address'; done"
done



Running this will produce output similar to this:      (With the actual WWN of course)


server01
        Network Address.............C0xxxxxxxxxxxxxx
        Network Address.............C0xxxxxxxxxxxxxx
        Network Address.............C0xxxxxxxxxxxxxx
        Network Address.............C0xxxxxxxxxxxxxx
server02
        Network Address.............C0xxxxxxxxxxxxxx
        Network Address.............C0xxxxxxxxxxxxxx
        Network Address.............C0xxxxxxxxxxxxxx
        Network Address.............C0xxxxxxxxxxxxxx
server03
        Network Address.............C0xxxxxxxxxxxxxx
        Network Address.............C0xxxxxxxxxxxxxx
        Network Address.............C0xxxxxxxxxxxxxx
        Network Address.............C0xxxxxxxxxxxxxx

Tuesday, July 12, 2011

Blog Name Change

I’m hope there are a few people that subscribe to my blog feed. Unfortunately for some of those people that have subscribed for my technical Windows or PowerShell content I may need to disappoint  you.

I have recently changed employers and I was the only person in the shop with AIX experience and they had an over abundance of Windows administrators. This led me to a decision that I’m hoping will pay off and not haunt me later. I’ve moved over to handle the IBM pSeries side of the shop. This includes working on anything the pSeries will support as an installed operating system, interface with or be managed by.

While I’m not completely new to various flavors of UNIX, this will certainly be a learning experience for me and I will be posting technical content, tips & tricks and other times as I learn them.