From d322efa0839bcf31a60e8fa2afb922ef38dfd345 Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Wed, 18 Sep 2019 11:25:51 -0400 Subject: [PATCH] Ready to test secondary --- failover/failover.sh | 7 ++++++- failover/rsync_xi.sh | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/failover/failover.sh b/failover/failover.sh index 324a493..e802b89 100755 --- a/failover/failover.sh +++ b/failover/failover.sh @@ -15,7 +15,9 @@ hostname=`/bin/hostname` while [ -n "$1" ]; do case "$1" in - -H) hostname="$2"; shift 2;; + -H | --hostname) hostname="$2"; shift 2;; + -s | --secondary) secondary="$2"; shift 2;; + -p | --primary) primary="$2"; shift 2;; *) shift 1;; esac done @@ -29,10 +31,13 @@ do_nothing() { do_primary() { echo "We are the primary. Creating package to send to secondary." + ./rsync_xi.sh --prepend sync --secondary "$secondary" } do_secondary() { echo "We are the secondary. Expanding package from the primary." + mysqlfile=`ls -tr1 /store/backups/nagiosxi/ | tail -1` + [ -z "$mysqlfile" ] && echo "No MySQL Backup file." && exit 2 } case "$hostname" in diff --git a/failover/rsync_xi.sh b/failover/rsync_xi.sh index d696d26..d950da1 100755 --- a/failover/rsync_xi.sh +++ b/failover/rsync_xi.sh @@ -4,10 +4,11 @@ # Copyright (c) 2011-2018 Nagios Enterprises, LLC. All rights reserved. # -BASEDIR=$(dirname $(readlink -f $0)) BASEDIR=/usr/local/nagiosxi/scripts +# FIXME SBLOG="/usr/local/nagiosxi/var/components/scheduledbackups.log" ts=`date +%s` +secondary="" # Import Nagios XI and xi-sys.cfg config vars . $BASEDIR/../var/xi-sys.cfg @@ -32,6 +33,9 @@ usage () { ############################### while [ -n "$1" ]; do case "$1" in + -s | --secondary) + secondary="$2" + ;; -h | --help) usage exit 0 @@ -52,7 +56,10 @@ while [ -n "$1" ]; do shift done +[ -z "$secondary" ] && echo "Secondary not specified." && exit 2 + # Restart nagios to forcibly update retention.dat +echo "Restart nagios to forcibly update retention.dat" $BASEDIR/manage_services.sh restart nagios sleep 10 @@ -88,9 +95,12 @@ mkdir -p $mydir ############################## -rsync_opts="-avun --delete --delete-after" do_rsync() { - echo rsync $rsync_opts $1 secondary:${1} + echo rsync -avun --delete --delete-after $1 ${secondary}:${1} +} + +do_rsync2() { + rsync -avu --delete --delete-after $1 ${secondary}:${1} } # Only backup NagiosQL if it exists @@ -244,14 +254,11 @@ rm -rf $name chown $nagiosuser:$nagiosgroup $name.tar.gz if [ -s $name.tar.gz ];then - echo " " echo "===============" echo "BACKUP COMPLETE" echo "===============" echo "Backup stored in $rootdir/$name.tar.gz" - - exit 0; else echo " " echo "===============" @@ -261,3 +268,5 @@ else rm -r $mydir exit 1; fi + +do_rsync2 $rootdir/$name.tar.gz