exitBackup 1

}

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

#Function restore_nodes ( <ipAddrArray> )

#Restores only the specified node(s).

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

function restore_nodes { local leaderindex=-1 local restoreIpArr=("$@")

local numNodes=${#restoreIpArr[@]} for (( i=0; i<$numNodes; i++ )); do

#Get the auth token for a specific node. restoreAuth[$i]=`getAuthToken ${restoreIpArr[$i]}` if [ "${restoreAuth[$i]}" == "" ]; then

teamBackup_log "Failed to get the auth Token for ${restoreIpArr[$i]}, can't start restore." exitBackup 1

fi

uuidURL="https://${restoreIpArr[$i]}:8443/sdn/v2.0/systems" restoreUUID[$i]=`get ${restoreIpArr[$i]} ${restoreAuth[$i]} "$uuidURL"` if [ "${restoreUUID[$i]}" == "" ]; then

teamBackup_log "Failed to get the UUID for ${restoreIpArr[$i]}, can't start restore." exitBackup 1

fi

restoreUUID[$i]=`extractJSONString "${restoreUUID[$i]}" "uid" sed '/^$/d'` teamBackup_log "UUID for ${restoreIpArr[$i]} is ${restoreUUID[$i]}"

#Upload the backup files to a specific node.

local ipFileName="sdn_controller_backup_${restoreIpArr[$i]}*.zip" local zipFile=`ls $RESTORE_BACKUP_FILESET/$ipFileName` upload_backup_file ${restoreIpArr[$i]} ${restoreUUID[$i]} \ ${restoreAuth[$i]} $zipFile

#Check if this is the leader node from the backup set. local leaderZip=`echo $zipFilegrep "Leader"`

[ "$leaderZip" != "" ] && leaderIndex=$I done

#Start restore in the leader node first before all the other nodes. if [ $leaderIndex -ne -1 ]; then

restore_node ${restoreIpArr[$leaderIndex]} ${restoreUUID[$leaderIndex]} \ ${restoreAuth[$leaderIndex]}

fi

#Verify the leader node is up after the restore.

validate_node_status ${restoreIpArr[$leaderIndex]}

#Continue restore on the remaining nodes. for (( i=0; i<$numNodes; i++ )); do

#Skip the leader node; it's already done. [ $i -eq $leaderIndex ] && continue

#Restore the specified node.

restore_node ${restoreIpArr[$i]} ${restoreUUID[$i]} ${restoreAuth[$i]} done

sleep 200

# Validate that the restored nodes are up. for (( n=0; n<$numNodes; n++ )); do

# Skip the leader node; it's already done. [ $n -eq $leaderIndex ] && continue validate_node_status ${restoreIpArr[$n]} done

}

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

# Function teamBackup_log ( <message> )

# Writes messages to the log for the team backup operation.

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

function teamBackup_log { msg="$1"

echo "$msg" tee -a $TEAM_BACKUP_LOGFILE

}

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

# Function exitBackup ( <exitStatus> )

# Exits the backup.

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

function exitBackup {

[ $1 -ne 0 ] && teamBackup_log "Stopping backup/restore with errors." rm -rf $TEAM_BACKUP_STATUS_FILE

kill -s TERM $B_PID exit $1

}

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

#Function get ( <ipAddr> <authToken> <url> )

#Performs a GET.

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

 

 

 

function get {

 

 

 

 

local getIP=$1

 

 

 

 

local getToken=$2

 

 

 

 

local getUrl=$3

 

 

 

 

local attempts=0

 

 

 

 

while [ $attempts -lt 5 ]; do

 

 

curl --noproxy $getIP --

header "X-Auth-Token:$getToken" \

--fail -ksS -L -f --

request GET --

url "$getUrl"

 

errorCode=$

 

 

 

 

?

 

 

 

 

let "attempts = $attempts + 1"

 

 

if [ 35 -eq $errorCode ]; then

 

 

teamBackup_log "SSL error on GET of $getUrl, retrying...

"

continue;

 

 

 

 

fi

 

 

 

 

128 Scripts