*
News: SMF - Just Installed!


Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

Backing up your PureFlex Scripts 2529

Super Newbie Posts: 35 Karma: +3/-0 *
Backing up your PureFlex Scripts
« on: September 24, 2014, 04:57:31 PM »
These are two scripts (Also included as attachments) that I run to backup my PureFlex.

The first is backup_pureflex.sh.  Amont other things, it calls the second script, backup_vios.sh.

There are variables you will need to edit in backup_pureflex.sh.  It SHOULD be obvious :-)

>>>>>>Ericw

####################################################################
cat backup_pureflex.sh
#!/bin/sh
######################################################################
#
# Written By: Eric Wedaa @ Marist College
# Last Update: 2014-09-17 Added V7000 backup to weekly, added mount /backup_dir
#              2014-09-18 Added "Assorted Variables" and some notes
#                         Added loops instead of making multiple commands
#              2014-09-24 Added notes, keywords, disclaimer
#
######################################################################
#
#    $Header: /usr/local/sbin/RCS/backup_pureflex.sh,v 1.5 2014/09/24 20:51:51 root Exp root $
#    $Date: 2014/09/24 20:51:51 $
#    $Revision: 1.5 $
#    $Author: root $
#
######################################################################
#
######################################################################
# backup_pureflex.sh - Help backup your PureFlex
# Copyright (C) 2014  Marist College
# 3399 North Road, Poughkeepsie, NY 12601
#
#  Disclaimer
#
# Marist College makes no representations about the suitability of any of
# the information contained in software programs and related documents
# on the Marist College Freeware Download Page for any purpose. All such
# software programs and related documents are provided without warranty
# of any kind. In no event shall Marist College be liable for damages
# whatsoever, including special, indirect or consequential damages,
# arising out of or in connection with the use or performance of
# information available from the service.
######################################################################

######################################################################
#
# NOTES:  This script is intended to be run from a Linux server that
#         has ssh keys setup to (and sometimes from) the different
#         vios, V7000, FSM
#
#         Luckily the CMMs and IMMs can be backed up from the FSM
#         so once you can ssh to the FSM you can back those up as
#         well.
#
#         You WILL have to setup root ssh/authorized_keys for your
#         SCE server as well.
#
#         You WILL have to setup root ssh/authorized_keys for each of
#         the VIOs as well in order to mount the backup-directory.
#
#         This script kind of assumes you have a user "pureflex"
#         with a home directory of /home/pureflex
#         and that you don't mind putting in a password into a
#         script.
#
#         For the FSM backup...
#         If you get "Authentication with the SFTP server failed.
#         Check the user name and password."
#         then you should check file ownership and permissions of
#         your target directory.
#
#         It is STRONGLY advised that this script be owned by root
#         and is chmod 700
#
#         It may not be the nicest code, but it works for us :-)
######################################################################
#
#         Suggested crontab entries here
# 12 4 * * * /usr/local/sbin/backup_pureflex.sh -daily
# 12 4 * * 0 /usr/local/sbin/backup_pureflex.sh -weekly
# 12 4 1 * * /usr/local/sbin/backup_pureflex.sh -monthly
#
######################################################################
#
# Assorted Variables here
#
######################################################################
PATH_TO_SCRIPTS="/usr/local/sbin/"
DATE=`date +%Y.%m.%d`
FQHN_FOR_THIS_HOST="HOSTNAME of host where this script is run"
PUREFLEX_USER_ON_THIS_HOST="pureflex"
SECRET_PASSWORD_FOR_PUREFLEX_USER="MY SECRET PASSWORD"

FSM="10.10.5.45"
V7000="10.10.5.36"
SCE="10.10.5.249"
VIOS="dn-pf-vios1.it.marist.edu  \
   dn-pf-vios2.it.marist.edu \
   dn-pf-vios3.it.marist.edu \
   dn-pf-vios4.it.marist.edu \
   dn-pf-vios5.it.marist.edu \
   dn-pf-vios6.it.marist.edu"
IMMS="10.10.5.28 \
   10.10.5.29 \
   10.10.5.30 \
   10.10.5.31 \
   10.10.5.32 \
   10.10.5.33 \
   10.10.5.34 \
   10.10.5.35"
CMMS="10.10.5.11 \
        10.10.5.23"

# This is passed to each vio as part of a mount command
# and should be a local (to the server this script is
# run on) path
# This better be exported to all your VIOsband might need to be chmod 777
NFS_MOUNT_POINT="cfg.it.marist.edu:/home/pureflex/dn/vios"

PATH_TO_VIOS_BACKUPS="/home/pureflex/dn/vios/"
PATH_TO_CMMS_BACKUPS="/home/pureflex/dn/cmm/"
PATH_TO_IMMS_BACKUPS="/home/pureflex/dn/imm/"
PATH_TO_V7000_BACKUPS="/home/pureflex/dn/v7000/"
PATH_TO_FSM_BACKUPS="/home/pureflex/dn/fsm/"
PATH_TO_SCE_BACKUPS="/home/pureflex/dn/sce/"

if [ ! -d $PATH_TO_VIOS_BACKUPS ] ; then
   echo "$PATH_TO_VIOS_BACKUPS not found, exiting"
   exit
fi
if [ ! -d $PATH_TO_CMMS_BACKUPS ] ; then
   echo "$PATH_TO_CMMS_BACKUPS not found, exiting"
   exit
fi
if [ ! -d $PATH_TO_IMMS_BACKUPS ] ; then
   echo "$PATH_TO_IMMS_BACKUPS not found, exiting"
   exit
fi
if [ ! -d $PATH_TO_V7000_BACKUPS ] ; then
   echo "$PATH_TO_V7000_BACKUPS not found, exiting"
   exit
fi
if [ ! -d $PATH_TO_FSM_BACKUPS ] ; then
   echo "$PATH_TO_FSM_BACKUPS not found, exiting"
   exit
fi
if [ ! -d $PATH_TO_SCE_BACKUPS ] ; then
   echo "$PATH_TO_SCE_BACKUPS not found, exiting"
   exit
fi

######################################################################
#
# Process Arguments and show help
#
######################################################################
if [ "x$1" = "x" ] ; then
   echo "USAGE $0 hostname -daily|-weekly|-monthly"
   exit
fi
if [ "x$1" = "x-daily" ] ; then
   LEVEL="daily"
fi
if [ "x$1" = "x-weekly" ] ; then
   LEVEL="weekly"
fi
if [ "x$1" = "x-monthly" ] ; then
   LEVEL="monthly"
fi
if [ "x$LEVEL" = "x" ] ; then
   echo "USAGE $0 hostname -daily|-weekly|-monthly "
   exit
fi


######################################################################
#
# Daily
#
######################################################################
if [ "$LEVEL" = "daily" ] ; then
   echo "#############################################################################"
   echo "Backing up SCE now"
   echo ""
   cd $PATH_TO_SCE_BACKUPS
   mkdir SCE.$DATE
   cd SCE.$DATE
   scp -rq sysadmin@$SCE:/home/sysadmin/.SCE32 .
   scp -q root@$SCE:/opt/ibm/SCE32/program/skc.ini .
   
   echo "#############################################################################"
   echo "Backing up daily vios now"
   echo ""
   for i in $VIOS ; do
      echo "Backing up $i now"
      $PATH_TO_SCRIPTS/backup_vios.sh $i -daily  >$PATH_TO_VIOS_BACKUPS/$i.$DATE.daily
   done

fi

######################################################################
#
# Weekly
#
######################################################################
if [ "$LEVEL" = "weekly" ] ; then

   echo "#############################################################################"
   echo "Backing up weekly vios now"
   echo ""
   for i in $VIOS ; do
      echo "Backing up $i now"
      ssh root@$i mkdir  /backup_dir
      ssh root@$i umount  /backup_dir
      ssh root@$i mount $NFS_MOUNT_POINT /backup_dir
      $PATH_TO_SCRIPTS/backup_vios.sh $i -weekly 
      ssh root@$i umount  /backup_dir
   done

   echo "#############################################################################"
   echo "Backing up V7000 now"
   echo ""
   ssh superuser@$V7000 svcconfig clear -all
   ssh superuser@$V7000 svcconfig backup
   cd $PATH_TO_V7000_BACKUPS/dumps
   mkdir $DATE
   cd $DATE
   scp  superuser@$V7000:/dumps/svc.config.backup.* .

   echo "#############################################################################"
   echo "Backing up CMMs now"
   echo ""
   # Backup CMMs here
   for i in $CMMS ; do
      echo "Backing up $i now"
      ssh $FSM smcli backupcfg -i $i > $PATH_TO_CMMS_BACKUPS/chassis-$i-`date +%Y-%m-%d`.bkp
   done

   echo "#############################################################################"
   echo "Backing up IMMs now"
   echo ""
   # Backup IMMs here
   for i in $IMMS ; do
      echo "Backing up $i now"
      ssh $FSM smcli backupcfg -i $i > $PATH_TO_IMMS_BACKUPS/imm-$i-`date +%Y-%m-%d`.bkp
   done
fi

######################################################################
#
# Monthly
#
######################################################################
if [ "$LEVEL" = "monthly" ] ; then
   for i in $VIOS ; do
      echo "Backing up $i now"
      ssh root@$i mkdir  /backup_dir
      ssh root@$i umount  /backup_dir
      ssh root@$i mount $NFS_MOUNT_POINT /backup_dir
      $PATH_TO_SCRIPTS/backup_vios.sh $i -monthly 
      ssh root@$i umount  /backup_dir
   done

   echo "#############################################################################"
   echo "Backing up the FSM now"
   ssh USERID@FSM backup -l sftp -s $FQHN_FOR_THIS_HOST -d $PATH_TO_FSM_BACKUPS -u $PUREFLEX_USER_ON_THIS_HOST -p $SECRET_PASSWORD_FOR_PUREFLEX_USER
fi

#####################################################################################
cat backup_vios.sh
#!/bin/sh
######################################################################
#
# Written By: Eric Wedaa @ Marist College
# Last Update: 2014-09-18 Added notes
#
######################################################################
#
#    $Header: /usr/local/sbin/RCS/backup_vios.sh,v 1.3 2014/09/24 20:51:38 root Exp root $
#    $Date: 2014/09/24 20:51:38 $
#    $Revision: 1.3 $
#    $Author: root $
#
######################################################################
#
# NOTES:  This script is intended to be run from a Linux server that
#         has ssh keys setup to (and sometimes from) the different
#         vios, V7000, FSM
#
#        Typically it is called by backup_pureflex.sh, as that makes
#        sure that /backup_dir is created and mounted on the VIOs.
#
######################################################################
# backup_vios.sh - Help backup your VIOs
# Copyright (C) 2014  Marist College
# 3399 North Road, Poughkeepsie, NY 12601
#
#  Disclaimer
#
# Marist College makes no representations about the suitability of any of
# the information contained in software programs and related documents
# on the Marist College Freeware Download Page for any purpose. All such
# software programs and related documents are provided without warranty
# of any kind. In no event shall Marist College be liable for damages
# whatsoever, including special, indirect or consequential damages,
# arising out of or in connection with the use or performance of
# information available from the service.
######################################################################



if [ "x$1" = "x" ] ; then
   echo "USAGE $0 hostname -daily|-weekly|-monthly > please redirect to a file"
   exit
fi
if [ "x$2" = "x" ] ; then
   echo "USAGE $0 hostname -daily|-weekly|-monthly > please redirect to a file"
   exit
fi
if [ "x$2" = "x-daily" ] ; then
   LEVEL="daily"
fi
if [ "x$2" = "x-weekly" ] ; then
   LEVEL="weekly"
fi
if [ "x$2" = "x-monthly" ] ; then
   LEVEL="monthly"
fi
if [ "x$LEVEL" = "x" ] ; then
   echo "USAGE $0 hostname -daily|-weekly|-monthly > please redirect to a file"
   exit
fi

 
echo "Hostname is $1"
HOSTNAME=$1
#echo "DEBUG hostname is $HOSTNAME"
#SHORT_HOSTNAME=`echo $1 |awk -F. '{print $1}'`
#echo "DEBUG SHORT is $SHORT_HOSTNAME"
DATE=`date +%Y.%m.%d`


if [ "$LEVEL" = "daily" ] ; then
   #http://www.torontoaix.com/vio-how-to-s/manual-vios-config-backup
   # We recommend gathering the following additional information
   # to the lsmap command. This information enables the Virtual
   # I/O Server to be rebuilt from the install media if necessary.
   
   #Network settings
   for COMMAND in \
   'netstat -state' \
   'netstat -routinfo' \
   'netstat -routtable' \
   'lsdev -dev ent0 -attr' \
   'lsdev -dev ent1 -attr' \
   'lsdev -dev ent2 -attr' \
   'lsdev -dev ent3 -attr' \
   'lsdev -dev ent4 -attr' \
   'lsdev -dev ent5 -attr' \
   'lsdev -dev ent6 -attr' \
   'lsdev -dev ent7 -attr' \
   'lsdev -dev ent8 -attr' \
   'lsdev -dev ent9 -attr' \
   'cfgnamesrv -ls' \
   'hostmap -ls' \
   'optimizenet -list' \
   'entstat -all ent0' \
   'entstat -all ent1' \
   'entstat -all ent2' \
   'entstat -all ent3' \
   'entstat -all ent4' \
   'entstat -all ent5' \
   'entstat -all ent6' \
   'entstat -all ent7' \
   'entstat -all ent8' \
   'entstat -all ent9' \
   ; do
      echo "####################################################"
      echo "#Network settings"
      echo $COMMAND
      ssh padmin@$HOSTNAME  ioscli $COMMAND
   done
   
   #All physical and logical volume SCSI devices
   for COMMAND in \
   'lspv ' \
   'lsvg  '\
   'lsvg -lv VolumeGroup '\
   ; do
      echo "####################################################"
      echo "#Network settings"
      echo $COMMAND
      ssh padmin@$HOSTNAME  ioscli $COMMAND
   done
   
   
   #All physical and logical adapters
   for COMMAND in \
   'lsdev -type adapter '\
   ; do
      echo "####################################################"
      echo "#Network settings"
      echo $COMMAND
      ssh padmin@$HOSTNAME  ioscli $COMMAND
   done
   
   #Code levels and users and security
   for COMMAND in \
   'ioslevel '\
   'viosecure -firewall -view '\
   'viosecure -view -nonint '\
   'motd '\
   ; do
      echo "####################################################"
      echo "#Network settings"
      echo $COMMAND
      ssh padmin@$HOSTNAME  ioscli $COMMAND
   done
   
   # Users
   for COMMAND in \
   'lsuser '\
   ; do
      echo "####################################################"
      echo "#Network settings"
      echo $COMMAND
      ssh padmin@$HOSTNAME  ioscli $COMMAND
   done
   exit 0
fi


ssh padmin@$HOSTNAME df |grep backup_dir >/tmp/backup_vios.sh.$$
if [ -s /tmp/backup_vios.sh.$$ ] ; then
   echo "/backup_dir apparently mounted, continuing"
else
   echo "/backup_dir apparently NOT mounted, exiting now"
   rm /tmp/backup_vios.sh.$$
   exit 1
fi
rm /tmp/backup_vios.sh.$$

if [ "$LEVEL" = "weekly" ] ; then
   ssh padmin@$HOSTNAME ioscli viosbr -backup -file  /backup_dir/$HOSTNAME.weekly.$DATE.viosbr
fi

if [ "$LEVEL" = "monthly" ] ; then
   ssh padmin@$HOSTNAME ioscli viosbr -backup -file  /backup_dir/$HOSTNAME.$DATE.monthly.viosbr
   ssh padmin@$HOSTNAME ioscli backupios -file /backup_dir/$HOSTNAME.$DATE.monthly.mksysb -mksysb -nomedialib -nosvg
fi

##################################################################################