From 289f3882fedf9d5b457310b2f727ab6b069e09d4 Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Mon, 11 Jul 2022 14:43:02 -0400 Subject: [PATCH] MAYBE I have it in the right place now --- failover/failover.sh | 38 +++++++++----------------------------- failover/rsync_xi.sh | 25 +++++++++++-------------- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/failover/failover.sh b/failover/failover.sh index 2186436..f7b4060 100755 --- a/failover/failover.sh +++ b/failover/failover.sh @@ -18,7 +18,6 @@ secondary="" synconly="false" syncname="sync" extraCmd="" -cssDir="/usr/local/nagiosxi/html/includes/components/custom-includes/css" hostname=`/bin/hostname` @@ -70,11 +69,6 @@ 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() { @@ -88,36 +82,22 @@ do_secondary() { warning "The primary (${primary}) is on the network but --force specified. Proceeding anyway." fi fi - verbose "Expanding package from the primary" + verbose "Checking for package from the primary" syncfile=$(basename `ls -tr1 ${backupDir}/${syncname}* | tail -1`) - 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 - verbose "Exiting." - exit 2 - fi + 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" 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 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 "***" - warning "***" - error "***" - warning "This is intended to be manually executed when needed, so we assume you want to start Nagios..." -n + verbose "This is intended to be manually executed when needed, so we assume you want to start Nagios..." -n + sleep 5 start_nagios - rm -f ${syncfile} + rm -f ${fullfile} verbose "Done." fi } diff --git a/failover/rsync_xi.sh b/failover/rsync_xi.sh index e16ecbd..62fb0a4 100755 --- a/failover/rsync_xi.sh +++ b/failover/rsync_xi.sh @@ -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,7 +39,6 @@ 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 "" } @@ -63,9 +62,6 @@ while [ -n "$1" ]; do --noping) noping=/bin/true ;; - --nofile) - noFile=/bin/true - ;; -h | --help) usage exit 0 @@ -122,11 +118,12 @@ workDir=$rootdir/$name mkdir -p $workDir do_rsync() { - verbose "Syncing $*..." + verbose "Syncing $1 (Excluding ${2:-nothing})..." src="$1" + [ -n "$2" ] && exclude="--exclude $2" || exclude="" [ ! -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}/ - [ -f "$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 /usr/bin/rsync --rsync-path="sudo /bin/rsync" ${rsync_opts} ${exclude} ${execute} ${src} nagios@${sName}:${src} } do_backup_files() { @@ -155,7 +152,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 +do_rsync /usr/local/nagiosxi custom-includes/css/ do_rsync /usr/local/nagvis do_rsync /usr/local/nrdp 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/crontabs/$apacheuser - } # End of do_backup_files do_backup_sql() { @@ -283,8 +279,6 @@ 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 @@ -483,7 +477,7 @@ else exit 1 fi fi -fi # This is from the "noFile" check previously + ############################## # RESTART SERVICES ############################## @@ -504,9 +498,12 @@ echo "===============" } 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" 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