HP VAN SDN Controller Administrator Guide v3
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 and MD5 files 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/systems/$sysUUID/backup"
local zipFile=$4
if [ ! -f $zipFile ]; then
teamBackup_log "File $zipFile does not exist."
exitBackup 1
fi
if [ ! -f "$zipFile.MD5" ]; then
teamBackup_log "File $zipFile.MD5 does not exist."
exitBackup 1
fi
curl --noproxy $sysIp -X POST --fail -ksSfL --url $uploadUrl \
-H "X-Auth-Token:$sysAuth" -H HP-filename:$(basename "$zipFile") \
--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."
curl --noproxy $sysIp -X POST --fail -ksSfL --url $uploadUrl \
-H "X-Auth-Token:$sysAuth" -H HP-filename:$(basename "$zipFile").MD5 \
--data-binary @$zipFile.MD5
if [ $? -ne 0 ]; then
teamBackup_log "Failed to upload backup $zipFile.MD5 to $sysIp."
exitBackup 1
fi
teamBackup_log "Backup $zipFile.MD5 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/systems/$sysUUID/action"
# 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 "restore"`
if [ "" == "$restoreSession" ]; 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/contact"
for (( k=0; k<100; k++ )); do
sleep 30
authToken=`getAuthToken $sysIp`
[ "$authToken" == "" ] && continue
# Try to contact the system.
data=`get $sysIp $authToken $sysUrl`
[ "$data" == "" ] && continue
teamBackup_log "Node:$sysIp came up successfully." && return
done
teamBackup_log "Node:$sysIP failed to come up."
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
B.3 Restore a Controller Team 127