
B Scripts
Restoring a controller
The
Restore.sh
script restores a controller from a backup file. This script must have permissions
set to 770 and be owned by the
sdn
user and
sdn
group:
#!/bin/bash
readonly OPT_ROOT="/opt/sdn"
readonly VAR_LIB_SDN="/var/lib/sdn"
readonly backupDir=${OPT_ROOT}"/backup"
readonly targetDir=${backupDir}"/tmp/com.hp.sdn.adm.backup.impl.BackupRestoreLegacyManager"
readonly configDir=${OPT_ROOT}"/config/"
readonly repoDir=${OPT_ROOT}"/virgo/repository/usr"
readonly backupFile=${backupDir}"/sdn_controller_backup*.zip"
readonly LOG_FILE=${backupDir}"/restore.log"
readonly INFO_FILE=${backupDir}"/info.bin"
readonly metricsDir=${OPT_ROOT}"/virgo/metrics"
WAIT_FOR_STOP=120
function restore_log {
typeset script_name=${0##*/}
typeset DATE_FORMAT=${DATE_FORMAT:-"+%b %e %H:%M:%S"}
typeset LOG_PREFIX="$(whoami)@$(hostname)"
echo "$(date "$DATE_FORMAT") $LOG_PREFIX $script_name[$$]: $*" >> $LOG_FILE
}
# For restore, clean virgo runtime environment
function clean_virgo_runtime {
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
$OPT_ROOT/virgo/bin/startup.sh -clean -noStart
}
function get_sdnc_pid {
echo $(ps -ef | grep -w "/bin/bash" | grep -w "/opt/sdn/admin/sdnc.sh" | head -n 1 | awk '{print $2}')
}
is_sdnc_running()
{
pid='get_sdnc_pid'
[ "x" = "x$pid" ] && return 1 || return 0
}
function restoreCassandraData {
# 1. shutdown the node - done by stopping sdnc
/opt/sdn/cassandra/bin/caServer.sh status
if [ $? -eq 0 ]; then
restore_log "Cassandra is still running, attempting stop..."
sudo -u sdnadmin /opt/sdn/cassandra/bin/caServer.sh stop
check_stop_and_exit $?
fi
#pick the cassandra zip file and unpack
restore_log "Deleting cassandra configuration"
if [ -d "$OPT_ROOT/cassandra/conf" ]; then
rm -rf "$OPT_ROOT/cassandra/conf/"
check_and_exit $?
fi
restore_log "Unzipping the cassandra configuration"
unzip -o $2 -d "$OPT_ROOT/cassandra/conf/"
# 2. Clear all files in /var/lib/cassandra/commitlog
restore_log "Deleting the commitlog directory"
if [ -d "$OPT_ROOT/cassandra/commitlog/" ]; then
rm -rf "$OPT_ROOT/cassandra/commitlog/"
check_and_exit $?
fi
# 3. Delete system and other data directories
restore_log "Deleting cassandra data directory"
if [ -d "/var/lib/sdn/cassandra/" ]; then
rm -rf "/var/lib/sdn/cassandra/"
check_and_exit $?
fi
# 4. pick the cassandra zip file and unpack
restore_log "Unzipping the cassandra data directory"
unzip -o $1 -d "/var/lib/sdn/cassandra/"
chmod -R g=u /var/lib/sdn/cassandra
}
function restoreTeamConfig {
# Restore the teaming config
unzip -o $1 -d "$VAR_LIB_SDN"
Restoring a controller
199