HP VAN SDN Controller Administrator Guide

96
#!/bin/bash
#-------------------------------------------------------------------------------
# Copyright 2013 Hewlett Packard Co., All Rights Reserved.
#-------------------------------------------------------------------------------
#
# Restore a Team
#-------------------------------------------------------------------------------
export BACKUP_DIR="/opt/sdn/backup"
export BACKUP_TEAM_DIR="/opt/sdn/team_backup"
export RESTORE_TEAM_DIR="/opt/sdn/team_restore"
export TEAM_BACKUP_STATUS_FILE="$RESTORE_TEAM_DIR/teamRestore_status"
export TEAM_BACKUP_LOGFILE="$RESTORE_TEAM_DIR/teamRestore_log.log"
export RESTORE_BACKUP_FILESET="$RESTORE_TEAM_DIR/opt/sdn/team_backup"
export B_PID=$$
trap "exit 1" TERM
#==============================================================================
# F U N C T I O N S
#==============================================================================
#------------------------------------------------------------------------------
# Function extract_zip_and_ip ( )
# Extracts the team backup zip and the backed up IP addresses.
#------------------------------------------------------------------------------
function extract_zip_and_ip {
unzip -o "$RESTORE_TEAM_DIR/sdn_team_backup*" -d $RESTORE_TEAM_DIR
if [ $? -ne 0 ]; then
teamBackup_log "Failed to unzip the team backup file."
exitBackup 1
fi
teamBackup_log "Extracted the team backup file successfully."
rm -rf "$RESTORE_TEAM_DIR/sdn_team_backup*"
backupIp=($(ls $RESTORE_BACKUP_FILESET | grep "zip$" | sed "s/.zip//" | \
sed "s/.Leader//" | sed "s/sdn_controller_backup_//"))
numBackup=${#backupIp[@]}
teamBackup_log "Found $numBackup backup file sets in the team backup file."
}
#------------------------------------------------------------------------------
# Function create_restoreDir ( )
# Creates the team restore directory.
#------------------------------------------------------------------------------
function create_restoreDir {
rm -rf $RESTORE_TEAM_DIR
mkdir $RESTORE_TEAM_DIR
chmod 777 $RESTORE_TEAM_DIR
}
#------------------------------------------------------------------------------
# Function validate_my_Ip ( )
# Validates the configured node IP against the backed up IP addresses.
#------------------------------------------------------------------------------
function validate_my_Ip {
for (( v=0; v<numBackup; v++ )); do
myip=`ifconfig|grep -o "${backupIp[$v]}"`
if [ "$myip" != "" ]; then
teamBackup_log "IP $myip is a valid member of the team."
return
fi
done
teamBackup_log "IP $myip is not a valid member of the team, exiting."
exitBackup 1