Tuesday, April 6, 2010

NIS+ master Backup script

 This is the script I mentioned using in the my earlier post about replacing the hardware of a NIS+ master.

Having had to use it now, perhaps the only other thing I would add into it would be the root crontab, but that would simply be:
crontab -l >> $log

Obviously, < server > is your server name, i.e. atuin or sunsvr01. And the < off server storage location > is a storage location that is easily accessible when you need it!

# more scripts/nisbackup.sh
#!/bin/sh

log="/var/tmp/nisbackup.log"
date=`date '+%m/%d/%y at %H:%M:%S'`

echo "Starting NIS+ backup on $date" > $log
cp -p /etc/.rootkey /var/nisplus.rootkey.copy
cp -p /var/nis/NIS_COLD_START /var/<server>-NIS_COLD_START
cp -p /etc/shadow /var/<server>-shadow
cp -p /etc/passwd /var/<server>-passwd
/usr/sbin/nisbackup -a /var/nisplus_backup

if [ $? -eq 0 ]; then
  cd /var
  echo "Listing nisplus_backup" >> $log
  ls -l /var/nisplus_backup >> $log
  echo "Creating tar" >> $log
  tar cvf /<off server storage location>/nisplus/backup/nisplusbackup.tar nisplus_backup nisplus.rootkey.copy <server>-NIS_COLD_START <server>-shadow <server>-passwd >> $log
  echo "Checking validity of tar:" >> $log
  tar tvf /apps/admin/nisplus/backup/nisplusbackup.tar >> $log
  else
    echo "nisbackup failed!!!" >> $log
fi

/usr/bin/mailx -s "NIS+ backup" server_admins < $log

#

No comments: