#-------------------------------------------------------------------------------

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=`ifconfiggrep -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

echo $TEAM_BACKUP_ON>$TEAM_BACKUP_STATUS_FILE

teamBackup_log "No backup is currently in progress. A new backup can start."

}

#------------------------------------------------------------------------------

#Function backupNode ( <nodeIndex> )

#Backs up a node.

#------------------------------------------------------------------------------

function backupNode { local nodeIndex=$1

local backupToken=${nodeAuth[$nodeIndex]} local backupIp=${ipArr[$nodeIndex]} local backupUUID=${nodeUUID[$nodeIndex]} backupURL="https://$backupIp:8443/sdn/v2.0/backup post $backupIp $backupToken "$backupURL"

if [ $errorCode -ne 0 ]; then

teamBackup_log "Failed to start backup for $backupIp." exitBackup 1

fi

if [ "$sessionID" == "" ]; then

teamBackup_log "Failed to start backup on $backupIp." exitBackup 1

fi

echo $sessionID

}

#------------------------------------------------------------------------------

#Function downloadBackupSet ( <nodeIndex> )

#Downloads the backup file from each node to the team leader node, verifying the checkum.

#------------------------------------------------------------------------------

function downloadBackupSet { local nodeIndex=$1

local backupAuth=${nodeAuth[$nodeIndex]} local backupIp=${ipArr[$nodeIndex]} local backupUUID=${nodeUUID[$nodeIndex]} local fileName=""

if [ "$backupIp" == "$leaderIp" ]; then

fileName="$BACKUP_TEAM_DIR/sdn_controller_backup_$backupIp.Leader.zip" else fileName="$BACKUP_TEAM_DIR/sdn_controller_backup_$backupIp.zip"

fi

122 Scripts