From 3e0c08db726717c92d355d210e199b59eb2291b6 Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Thu, 13 Jan 2022 10:43:59 -0500 Subject: [PATCH] failover.sh can now request that rsync continue without syncing, just to activate Nagios --- failover/failover.sh | 15 +++++++++++++-- failover/rsync_xi.sh | 11 +++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/failover/failover.sh b/failover/failover.sh index 5ce88b6..2186436 100755 --- a/failover/failover.sh +++ b/failover/failover.sh @@ -90,8 +90,19 @@ do_secondary() { fi verbose "Expanding package from the primary" syncfile=$(basename `ls -tr1 ${backupDir}/${syncname}* | tail -1`) - [ -z "$syncfile" ] && error "No sync file ($syncfile) found." && exit 2 - /home/nagios/bin/rsync_xi.sh --primary "${primary}" --secondary "${secondary}" --file "/store/backups/nagiosxi/$syncfile" + 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 + 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 diff --git a/failover/rsync_xi.sh b/failover/rsync_xi.sh index d87fd25..e16ecbd 100755 --- a/failover/rsync_xi.sh +++ b/failover/rsync_xi.sh @@ -14,6 +14,7 @@ hostname="`/bin/hostname`" pName="" sName="" noping=/bin/false +noFile=/bin/false execute="-n" syncfile="" isP=/bin/false @@ -38,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 "" } @@ -61,6 +63,9 @@ while [ -n "$1" ]; do --noping) noping=/bin/true ;; + --nofile) + noFile=/bin/true + ;; -h | --help) usage exit 0 @@ -278,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 @@ -476,7 +483,7 @@ else exit 1 fi fi - +fi # This is from the "noFile" check previously ############################## # RESTART SERVICES ############################## @@ -497,7 +504,7 @@ 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 rm -f ${syncfile}