Compare commits

..

3 Commits
master ... test

@ -6,9 +6,9 @@ Failover from primary Nagios XI to secondary Nagios XI is a Disaster Recovery ef
* The syncing process will delete files that it does not believe should be on the secondary, so all work must be performed on the primary. Any work performed on the secondary will be overwritten when the next synchronization process occurs. Note that this includes SSH keys, as /home/nagios will be synced from the parimary to the secondary.
* /home/nagios/bin exists and contains the files needed for this process. Note that the sync process will sync these from the primary to the secondary, so like all other files, they must only be modified on the primary.
/home/nagios/bin/failover.sh
/home/nagios/bin/nagios_startstop.sh
/home/nagios/bin/rsync_xi.sh
* /home/nagios/bin/failover.sh
* /home/nagios/bin/nagios_startstop.sh
* /home/nagios/bin/rsync_xi.sh
* The root user has the ability to SSH from the primary to the secondary as the nagios user without entering a passphrase. This is how the rsync and database copies are performed
* root on primary (and root on secondary) has crontab requirements that will be detailed separately.

@ -7,6 +7,7 @@
# EverWatch Global, Inc.
PATH=/usr/sbin:/sbin:/usr/bin:/bin
. /home/nagios/bin/colors.sh
#primary="nagiosxi-p.princeton.edu"
#secondary="nagiosxi-f.princeton.edu"
@ -18,11 +19,10 @@ secondary=""
synconly="false"
syncname="sync"
extraCmd=""
cssDir="/usr/local/nagiosxi/html/includes/components/custom-includes/css"
hostname=`/bin/hostname`
. ./colors.sh
while [ -n "$1" ]; do
case "$1" in
-H | --hostname) hostname="$2"; shift 2;;
@ -69,6 +69,11 @@ do_primary() {
[ $? -ne 0 ] && error "Cannot ping ${secondary}. Use --noping to continue wihout ping." && exit
verbose "Creating package to send to secondary"
/home/nagios/bin/rsync_xi.sh --prepend ${syncname} --primary "${primary}" --secondary "${secondary}" $extraCmd
# Update header.css with proper gradient files
if [ -r "${cssDir}/header.css.primary" -a -w "${cssDir}/header.css" ]; then
verbose "Copying local gradient files"
rsync ${cssDir}/header.css.primary ${cssDir}/header.css
fi
}
do_secondary() {
@ -82,22 +87,37 @@ do_secondary() {
warning "The primary (${primary}) is on the network but --force specified. Proceeding anyway."
fi
fi
verbose "Checking for package from the primary"
verbose "Expanding package from the primary"
syncfile=$(basename `ls -tr1 ${backupDir}/${syncname}* | tail -1`)
fullfile="/store/backups/nagiosxi/$syncfile"
if [ -f "$fullfile" ]; then
verbose " Sync file found ($fullfile). Continuing."
/home/nagios/bin/rsync_xi.sh --primary "${primary}" --secondary "${secondary}" --file "$fullfile"
if [ -z "$syncfile" ]; then
error "No sync file ($syncfile) found."
warning "Continue anyway? (10 second timeout, one letter only please) [y/N] " -n
read -t 10 -e -n 1 continueAnyway
if [ "$continueAnyway" = "y" -o "$continueAnyway" = "Y" ]; then
/home/nagios/bin/rsync_xi.sh --primary "${primary}" --secondary "${secondary}" --file "/store/backups/nagiosxi/$syncfile" --nofile
else
warning " No sync file found. Continuing to activate Nagios."
verbose "Exiting."
exit 2
fi
else
/home/nagios/bin/rsync_xi.sh --primary "${primary}" --secondary "${secondary}" --file "/store/backups/nagiosxi/$syncfile"
fi
if [ $? -eq 0 ]; then
# Update header.css with proper gradient files
if [ -r "${cssDir}/header.css.secondary" -a -w "${cssDir}/header.css" ]; then
verbose "Copying local gradient files"
rsync ${cssDir}/header.css.secondary ${cssDir}/header.css
fi
verbose "Ensuring that xi.key file has proper permissions"
chmod 0640 /usr/local/nagiosxi/var/keys/xi.key
chown nagios:nagios /usr/local/nagiosxi/var/keys/xi.key
verbose "This is intended to be manually executed when needed, so we assume you want to start Nagios..." -n
sleep 5
verbose "***"
warning "***"
error "***"
warning "This is intended to be manually executed when needed, so we assume you want to start Nagios..." -n
sleep 3
start_nagios
rm -f ${fullfile}
rm -f ${syncfile}
verbose "Done."
fi
}

Binary file not shown.

@ -14,11 +14,11 @@ hostname="`/bin/hostname`"
pName=""
sName=""
noping=/bin/false
noFile=/bin/false
execute="-n"
syncfile=""
isP=/bin/false
isS=/bin/false
rsync_opts="-a --delete --delete-after"
# Import Nagios XI and xi-sys.cfg config vars
. $BASEDIR/../var/xi-sys.cfg
@ -39,6 +39,7 @@ usage () {
echo " -p | --prepend Prepend a string to the .tar.gz name"
echo " -a | --append Append a string to the .tar.gz name"
echo " -d | --directory Change the directory to store the compressed backup"
echo " --nofile Ignore the missing sync file but continue the process"
echo ""
}
@ -62,6 +63,9 @@ while [ -n "$1" ]; do
--noping)
noping=/bin/true
;;
--nofile)
noFile=/bin/true
;;
-h | --help)
usage
exit 0
@ -118,12 +122,11 @@ workDir=$rootdir/$name
mkdir -p $workDir
do_rsync() {
verbose "Syncing $1 (Excluding ${2:-nothing})..."
verbose "Syncing $*..."
src="$1"
[ -n "$2" ] && exclude="--exclude $2" || exclude=""
[ ! -e "$src" ] && warning " OK: No such file or directory: $src" && return
[ -d "$src" ] && sudo /usr/bin/rsync --rsync-path="sudo /bin/rsync" ${rsync_opts} ${exclude} ${execute} ${src}/ nagios@${sName}:${src}/
[ -f "$src" ] && sudo /usr/bin/rsync --rsync-path="sudo /bin/rsync" ${rsync_opts} ${exclude} ${execute} ${src} nagios@${sName}:${src}
[ -d "$src" ] && sudo rsync -a --delete --delete-after --rsync-path="sudo /bin/rsync" ${execute} ${src}/ nagios@${sName}:${src}/
[ -f "$src" ] && sudo rsync -a --delete --delete-after --rsync-path="sudo /bin/rsync" ${execute} ${src} nagios@${sName}:${src}
}
do_backup_files() {
@ -152,7 +155,7 @@ do_rsync $httpdconfdir/nrdp.conf
do_rsync $httpdconfdir/ssl.conf
do_rsync /usr/local/nagios
do_rsync /usr/local/nagiosmobile
do_rsync /usr/local/nagiosxi custom-includes/css/
do_rsync /usr/local/nagiosxi
do_rsync /usr/local/nagvis
do_rsync /usr/local/nrdp
do_rsync /usr/share/snmp
@ -160,6 +163,7 @@ do_rsync /var/lib/mrtg
do_rsync /var/spool/cron/apache
do_rsync /var/spool/cron/crontabs/$apacheuser
} # End of do_backup_files
do_backup_sql() {
@ -279,6 +283,8 @@ test_mysql_connection() {
rootdir=/store/backups/nagiosxi
backupfile=$1
# This is a poor way to write this, but it's the easiest. Skip doing all the restore operations if there's no file to restore from.
if [ ! $noFile ]; then
if [ ! -f $backupfile ]; then
error "Unable to find backup file $backupfile!"
exit 1
@ -477,7 +483,7 @@ else
exit 1
fi
fi
fi # This is from the "noFile" check previously
##############################
# RESTART SERVICES
##############################
@ -498,12 +504,9 @@ echo "==============="
}
do_secondary() {
[ ! -r "$syncfile" ] && error "No sync file ($syncfile) found." && exit 2
[ ! $noFile -a ! -r "$syncfile" ] && error "No sync file ($syncfile) found." && exit 2
restore_secondary "$syncfile"
if [ $? -eq 0 ]; then
if [ -r "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.secondary" -a -w "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css" ]; then
cp /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.secondary /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css
fi
rm -f ${syncfile}
fi
} # End of do_secondary

Loading…
Cancel
Save