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

}

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

# Function upload_backup_file ( <systemIp> <systemUUID> <authToken> <zipFile> )

# Uploads backup file to the specific nodes of the team.

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

function upload_backup_file { local sysIp=$1

local sysUUID=$2 local sysAuth=$3

local uploadUrl="https://$sysIp:8443/sdn/v2.0/restore/backup"

local zipFile=$4

 

if [ ! -f $zipFile ]; then

 

teamBackup_log "File $zipFile does not exist."

 

exitBackup 1

 

fi

 

curl --noproxy $sysIp -X POST --fail -ksSfL --

url $uploadUrl \

-H "X-Auth-Token:$sysAuth"\

 

--data-binary @$zipFile

 

if [ $? -ne 0 ]; then

teamBackup_log "Failed to upload backup $zipFile to $sysIp." exitBackup 1

fi

teamBackup_log "Backup $zipFile uploaded successfully to $sysIp."

}

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

#Function restore_node ( <systemIp> <systemUUID> <authToken> )

#Restores a particular node.

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

function restore_node { local sysIp=$1

local sysUUID=$2 local sysAuth=$3

local restoreUrl="https://$sysIp:8443/sdn/v2.0/restore"

#Set the IP first. Ignore errors since this only works for standalone. put $sysIp $sysAuth "https://$sysIp:8443/sdn/v2.0/systems/$sysUUID" \ "{\"system\":{\"ip\":\"$sysIp\"}}" > /dev/null 2>&1 restoreSession=`post $sysIp $sysAuth $restoreUrl `

if [ $errorCode -ne 0 ]; then

teamBackup_log "Failed to start restore on node $sysIp." exitBackup 1

fi

teamBackup_log "Started restore on node $sysIp."

}

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

#Function validate_node_status ( )

#Validates node status after the restore.

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

function validate_node_status { local sysIp=$1

# Wait for the restore to complete.

local sysUrl="https://$sysIp:8443/sdn/v2.0/systems" for (( k=0; k<100; k++ )); do

sleep 30 authToken=`getAuthToken $sysIp`

[ "$authToken" == "" ] && continue

# Try to contact the system.

data=`get $sysIp $authToken "$sysUr?ip=$sysIp"` [ "$data" == "" ] && continue

teamBackup_log "Node:$sysIp came up successfully." && return done

teamBackup_log "Node:$sysIP failed to come up."

B.3 Restoring a controller team 127