
exitBackup 1
fi
# Last, backup the leader node to avoid synchronization issues on a restore.
backupNode $leaderIndex
teamBackup_log "Started backup on leader ${ipArr[$leaderIndex]}."
backup_complete=1
# Verify the backup on the leader node.
for (( k=0; k<$BACKUP_WAIT_COUNT; k++ )); do
sleep 10
verifyBackupStatus $leaderIndex
if [ $backup_complete -le 0 ]; then
teamBackup_log "Backup on the leader node completed successfully."
break
fi
done
if [ $backup_complete -gt 0 ]; then
teamBackup_log "Backup of the leader node took longer than $waitTime min. Aborting backup..."
teamBackup_log "To increase backup wait time, change BACKUP_WAIT_COUNT in the script."
exitBackup 1
fi
# Copy all the backup files from each node in the team onto the leader node.
for (( i=0; i<$numNodes; i++ )); do
downloadBackupSet $i
done
# Create one zip for entire team and copy it to the specified remote location.
teamBackupZip
remoteBackupFileCopy
echo
teamBackup_log "The team was backed up successfully."
exitBackup 0
Restoring a controller team
NOTE:
Before running this script, re-install the controller. Otherwise an Error 404 condition
results and the controller is not restored. See
“Restoring a controller from a backup ” (page 137)
Because the scripts in this appendix cross page boundaries, be careful to avoid including the
page number when copying a script. Copying a script one page at a time can prevent inclusion
of page numbers.
#!/bin/bash
#-------------------------------------------------------------------------------
# Copyright 2013 Hewlett Packard Co., All Rights Reserved.
#-------------------------------------------------------------------------------
#
# Restore a Team
#-------------------------------------------------------------------------------
export BACKUP_DIR="/opt/sdn/backup"
export BACKUP_TEAM_DIR="/opt/sdn/team_backup"
export RESTORE_TEAM_DIR="/opt/sdn/team_restore"
export TEAM_BACKUP_STATUS_FILE="$RESTORE_TEAM_DIR/teamRestore_status"
export TEAM_BACKUP_LOGFILE="$RESTORE_TEAM_DIR/teamRestore_log.log"
export RESTORE_BACKUP_FILESET="$RESTORE_TEAM_DIR/opt/sdn/team_backup"
export B_PID=$$
trap "exit 1" TERM
#==============================================================================
# F U N C T I O N S
#==============================================================================
#------------------------------------------------------------------------------
# Function extract_zip_and_ip ( )
# Extracts the team backup zip and the backed up IP addresses.
#------------------------------------------------------------------------------
function extract_zip_and_ip {
unzip -o "$RESTORE_TEAM_DIR/sdn_team_backup*" -d $RESTORE_TEAM_DIR
if [ $? -ne 0 ]; then
teamBackup_log "Failed to unzip the team backup file."
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
206
Scripts