Академический Документы
Профессиональный Документы
Культура Документы
/usr/bin/ksh
#
# Script to backup the VIO Server to an NFS mounted filesystem.
# This will backup to the NIM server given as the first parameter,
# the second parameter is either prod or qa.
#
# This need to be scheduled via crontab on the vio server, and run
# as the padmin user. Run "crontab -e padmin" on vio server.
#
# Written by Stephen Diwell - capacityreports.com
#
# If DEBUG is set, run set -x
#
[[ -n ${DEBUG} ]] && set -x
. /home/padmin/.profile
#
# Read the arguments.
#
if [[ $# -ne 2 ]]
then
print "Usage: ${0} nim_server [ prod | qa ]"
exit 10
fi
#
# Check that type is prod or qa.
#
if [[ $2 = "prod" || $2 = "qa" ]]
then
export BACKUP_HOST=$1
export TYPE=$2
else
print "Usage: ${0} nim_server [ prod | qa ]"
exit 12
fi
#
# Set the correct storage location.
#
if [[ ${TYPE} = "prod" ]]
then
NFS_DIR="/nim/mksysb/prod"
BACKUP_DIR="/home/padmin/prod"
else
NFS_DIR="/nim/mksysb/nonprod"
BACKUP_DIR="/home/padmin/nonprod"
fi
#
# Setup logging.
#
YEAR=$(date +%Y)
MONTH=$(date +%m)
DAY=$(date +%d)
TSTAMP=$(date +%m%d%H%M)
LOG_DIR=/home/padmin/logs
LOG_FILE=${LOG_DIR}/${TSTAMP}.mksysb.log
VG_DIR="/home/padmin/vgdata"
CONF_DIR="/home/padmin/configs"
# Set the ulimit for files to unlimited.
ulimit -f unlimited
HOSTNAME=$( hostname )
SCRIPT=$( print ${0##*/} )
#
# Create the directories if they do not exist.
#
[[ ! -d ${BACKUP_DIR} ]] && mkdir -p -m 775 ${BACKUP_DIR}
[[ ! -d ${LOG_DIR} ]] && mkdir -p -m 775 ${LOG_DIR}
[[ ! -d ${VG_DIR} ]] && mkdir -p -m 755 ${VG_DIR}
[[ ! -d ${CONF_DIR} ]] && mkdir -p -m 755 ${CONF_DIR}
#
# Redirect all output to the logfile.
#
exec 1>${LOG_FILE}
exec 2>&1
print "${SCRIPT}: The mksysb process is now starting."
print "${SCRIPT}: Will backup to ${BACKUP_HOST} directory ${NFS_DIR}."
#
# Tidy up the logs directory. We dont have find on vio servers.
#
for FILE in $( ls -1t ${LOG_DIR} | tail +7 )
do
rm ${LOG_DIR}/${FILE}
done
print "${SCRIPT}: Checking backup server ${BACKUP_HOST} is up."
if ! ping ${BACKUP_HOST} 4 1>/dev/null 2>&
then
print "${SCRIPT}: Backup server ${BACKUP_HOST} not up!!"
exec 2>&exec 1>&exit 100
fi
print "${SCRIPT}: Mounting the ${NFS_DIR} from ${BACKUP_HOST}."
if mount | grep -q ${NFS_DIR}
then
print "${SCRIPT}: ${NFS_DIR} already mounted!!"
else
print "${SCRIPT}: Mounting ${NFS_DIR} from ${BACKUP_HOST}."
mount ${BACKUP_HOST}:${NFS_DIR} ${BACKUP_DIR}
if [[ $? != 0 ]]
then
print "${SCRIPT}: Can not mount ${NFS_DIR} from ${BACKUP_HOST}!!
"
exec 2>&exec 1>&exit 101
fi
fi
#
# Backup all the other stuff that you will need to rebuild vio server.
#