Compare commits

..

1 Commits
test ... master

@ -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. * 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 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/failover.sh
* /home/nagios/bin/nagios_startstop.sh /home/nagios/bin/nagios_startstop.sh
* /home/nagios/bin/rsync_xi.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 * 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. * root on primary (and root on secondary) has crontab requirements that will be detailed separately.

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

Binary file not shown.

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

Loading…
Cancel
Save