exitBackup 1
}
#Function restore_nodes ( <ipAddrArray> )
#Restores only the specified node(s).
function restore_nodes { local
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
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
#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
}
# Function teamBackup_log ( <message> )
# Writes messages to the log for the team backup operation.
function teamBackup_log { msg="$1"
echo "$msg" tee
}
# Function exitBackup ( <exitStatus> )
# Exits the backup.
function exitBackup {
[ $1
kill
}
#Function get ( <ipAddr> <authToken> <url> )
#Performs a GET.
|
|
| ||
function get { |
|
|
|
|
local getIP=$1 |
|
|
|
|
local getToken=$2 |
|
|
|
|
local getUrl=$3 |
|
|
|
|
local attempts=0 |
|
|
|
|
while [ $attempts |
|
| ||
curl | header | |||
request GET | url "$getUrl" |
| ||
errorCode=$ |
|
|
|
|
? |
|
|
|
|
let "attempts = $attempts + 1" |
|
| ||
if [ 35 |
|
| ||
teamBackup_log "SSL error on GET of $getUrl, retrying... | " | |||
continue; |
|
|
|
|
fi |
|
|
|
|
128 Scripts