HP VAN SDN Controller Administrator Guide

88
Back Up a Controller Team
Note
Because the scripts in this appendix cross page boundaries, be careful to avoid including
the page number when copying a script. Copying a script one page at a time can prevent
inclusion of page numbers.
#!/bin/bash
#-------------------------------------------------------------------------------
# Copyright 2013 Hewlett Packard Co., All Rights Reserved.
#-------------------------------------------------------------------------------
#
# Backup a Team
#-------------------------------------------------------------------------------
export BACKUP_DIR="/opt/sdn/backup"
export BACKUP_TEAM_DIR="/opt/sdn/team_backup"
export TEAM_BACKUP_STATUS_FILE="$BACKUP_TEAM_DIR/teamBackup_status"
export TEAM_BACKUP_LOGFILE="$BACKUP_TEAM_DIR/teamBackup_log.log"
export BACKUP_WAIT_COUNT=200 # this * 10 = seconds to wait for backup to finish
export B_PID=$$
trap "exit 1" TERM
#==============================================================================
# F U N C T I O N S
#==============================================================================
#------------------------------------------------------------------------------
# Function validateTeamLead ( )
# Validates configured node IP against the team leader IP.
#------------------------------------------------------------------------------
function validateTeamLead {
leaderIp=`ifconfig|grep -o $leaderIp`
if [ "$leaderIp" == "" ]; then
teamBackup_log "Run this script from the team lead node."
exitBackup 1
fi
teamBackup_log "Leader node IP $leaderIp is correctly configured."
}
#------------------------------------------------------------------------------
# Function validateTeamBackupStatus ( )
# Checks if a new backup can be started.
#------------------------------------------------------------------------------
function validateTeamBackupStatus {
TEAM_BACKUP_ON="backup_in_progress=true"
# Check if any backup is going on now.
if [ -e "$TEAM_BACKUP_STATUS_FILE" ]; then
teamBackup_log "Backup status file $TEAM_BACKUP_STATUS_FILE exists."
backupStatus=`cat $TEAM_BACKUP_STATUS_FILE`
if [ "$backupStatus" == "$TEAM_BACKUP_ON" ]; then
teamBackup_log "Backup already in progress, aborting new backup..."
exitBackup 1
fi
fi
rm -rf $BACKUP_TEAM_DIR
mkdir $BACKUP_TEAM_DIR
chmod 777 $BACKUP_TEAM_DIR