From 34d701c7d521f8b7762413ad57c0e9736458c7df Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Thu, 19 Sep 2019 10:55:40 -0400 Subject: [PATCH] Minor updates to client/server sides --- failover/Makefile | 4 +- failover/failover.sh | 12 +++--- failover/restore_xi.sh | 25 ++---------- failover/rsync_xi.sh | 92 ++++++++++++------------------------------ 4 files changed, 37 insertions(+), 96 deletions(-) diff --git a/failover/Makefile b/failover/Makefile index a73994e..f226a60 100644 --- a/failover/Makefile +++ b/failover/Makefile @@ -1,8 +1,8 @@ -primary: +primary: sync ./failover.sh -P 192.168.56.113 -S 192.168.56.114 -H 192.168.56.113 secondary: ./failover.sh -P 192.168.56.113 -S 192.168.56.114 -H 192.168.56.114 sync: - rsync -avu --stats . clone:/root/princeton/failover + rsync -av --stats ./ secondary:/root/princeton/failover diff --git a/failover/failover.sh b/failover/failover.sh index 28a9ec4..5bd31f8 100755 --- a/failover/failover.sh +++ b/failover/failover.sh @@ -11,6 +11,7 @@ PATH=/usr/sbin:/sbin:/usr/bin:/bin primary="nagiosxi-p.princeton.edu" secondary="nagiosxi-f.princeton.edu" synconly="false" +syncname="sync" hostname=`/bin/hostname` @@ -19,6 +20,7 @@ while [ -n "$1" ]; do -H | --hostname) hostname="$2"; shift 2;; -S | --secondary) secondary="$2"; shift 2;; -P | --primary) primary="$2"; shift 2;; + -n | --sync-name) syncname="$2"; shift 2;; -s | --sync-only) synconly="true"; shift 1;; *) shift 1;; esac @@ -33,17 +35,17 @@ do_nothing() { do_primary() { echo "We are the primary. Creating package to send to secondary." - ./rsync_xi.sh --prepend sync --secondary "$secondary" + ./rsync_xi.sh --prepend ${syncname} --secondary "${secondary}" + cp /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.primary /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css } 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 - ./restore_xi.sh /store/backups/nagiosxi/$mysqlfile + syncfile=`ls -tr1 /store/backups/nagiosxi/ | tail -1` + [ -z "$syncfile" ] && echo "No sync file ($syncfile) found." && exit 2 + ./restore_xi.sh /store/backups/nagiosxi/$syncfile ./nagios_startstop.sh stop 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 - cd /usr/local/nagiosxi/scripts && ./reconfigure_nagios.sh } case "$hostname" in diff --git a/failover/restore_xi.sh b/failover/restore_xi.sh index 10db47c..14239eb 100755 --- a/failover/restore_xi.sh +++ b/failover/restore_xi.sh @@ -115,7 +115,6 @@ if [ $res != 0 ]; then echo "Error restoring MySQL database 'nagios' - check the password in this script!" exit; fi - if [[ "$cfg__db_info__nagiosql__dbserver" == *":"* ]]; then nagiosql_dbport=`echo "$cfg__db_info__nagiosql__dbserver" | cut -f2 -d":"` nagiosql_dbserver=`echo "$cfg__db_info__nagiosql__dbserver" | cut -f1 -d":"` @@ -129,12 +128,9 @@ if [ $res != 0 ]; then echo "Error restoring MySQL database 'nagiosql' - check the password in this script!" exit; fi - # Only restore PostgresQL if we are still using it if [ "$cfg__db_info__nagiosxi__dbtype" == "pgsql" ]; then - service postgresql initdb &>/dev/null || true - echo "Restoring Nagios XI PostgresQL database..." if [ -f /var/lib/pgsql/data/pg_hba.conf ]; then pghba="/var/lib/pgsql/data/pg_hba.conf" @@ -147,18 +143,13 @@ if [ "$cfg__db_info__nagiosxi__dbtype" == "pgsql" ]; then echo "local all all trust host all all 127.0.0.1/32 trust host all all ::1/128 trust" > $pghba - $BASEDIR/manage_services.sh start postgresql - sudo -u postgres psql -c "create user nagiosxi with password 'n@gweb';" sudo -u postgres psql -c "create database nagiosxi owner nagiosxi;" - $BASEDIR/manage_services.sh restart postgresql - # Sleep a bit (required so Postgres finishes startup before we connect again) echo "Sleeping for a few seconds (please wait)..." sleep 7 - psql -U nagiosxi nagiosxi < $backupdir/pgsql/nagiosxi.sql res=$? if [ $res != 0 ]; then @@ -202,27 +193,17 @@ else exit; fi fi - -echo "Restarting database servers..." -$BASEDIR/manage_services.sh restart mysqld } -############################## -# RESTART SERVICES -############################## +restore_databases +echo "Restarting services..." +$BASEDIR/manage_services.sh restart mysqld $BASEDIR/manage_services.sh restart httpd $BASEDIR/manage_services.sh start npcd $BASEDIR/manage_services.sh start ndo2db $BASEDIR/manage_services.sh start nagios -############################## -# DELETE TEMP RESTORE DIRECTORY -############################## rm -rf $mydir - -############################## -# DELETE forceinstall FILE -############################## rm -f /tmp/nagiosxi.forceinstall echo " " diff --git a/failover/rsync_xi.sh b/failover/rsync_xi.sh index d75ce18..3ad87ee 100755 --- a/failover/rsync_xi.sh +++ b/failover/rsync_xi.sh @@ -93,53 +93,49 @@ mkdir -p $mydir ############################## # BACKUP DIRS ############################## - - do_rsync() { - rsync -avu --delete --delete-after $1 ${secondary}:${1} + echo "Syncing $*..." + rsync -av --delete --delete-after "$1" "${secondary}:${1}" } # Only backup NagiosQL if it exists if [ -d "/var/www/html/nagiosql" ]; then - echo "Backing up NagiosQL..." do_rsync /var/www/html/nagiosql/ do_rsync /etc/nagiosql/ fi - -echo "Backing up Nagios Core..." -do_rsync /usr/local/nagios - # Backup ramdisk if it exists if [ -f "/etc/sysconfig/nagios" ]; then - echo "Copying ramdisk configuration..." do_rsync /etc/sysconfig/nagios fi +if [ "$distro" == "Ubuntu" -o "$distro" == "Debian" ]; then + do_rsync /var/spool/cron/crontabs/$apacheuser +else + do_rsync /var/spool/cron/apache +fi +if [ -d "/etc/apache2/sites-available" ]; then + do_rsync /etc/apache2/sites-available/default-ssl.conf +else + do_rsync $httpdconfdir/ssl.conf +fi -echo "Backing up Nagios XI..." -do_rsync /usr/local/nagiosxi/ - -echo "Backing up MRTG..." -do_rsync /var/lib/mrtg/ -do_rsync /etc/mrtg/mrtg.cfg do_rsync /etc/mrtg/conf.d/ - -# SNMP configs and MIBS -echo "Backing up the SNMP directories" +do_rsync /etc/mrtg/mrtg.cfg do_rsync /etc/snmp/ -do_rsync /usr/share/snmp/ - -echo "Backing up NRDP..." -do_rsync /usr/local/nrdp/ - -echo "Backing up Nagvis..." +do_rsync /home/nagios/ +do_rsync /usr/local/nagios/ +do_rsync /usr/local/nagiosmobile/ +do_rsync /usr/local/nagiosxi/ do_rsync /usr/local/nagvis/ +do_rsync /usr/local/nrdp/ +do_rsync /usr/share/snmp/ +do_rsync /var/lib/mrtg/ -echo "Backing up nagios user home dir..." -do_rsync /home/nagios/ +do_rsync /etc/logrotate.d/nagiosxi +do_rsync $httpdconfdir/nagiosxi.conf +do_rsync $httpdconfdir/nagiosmobile.conf +do_rsync $httpdconfdir/nagvis.conf +do_rsync $httpdconfdir/nrdp.conf -############################## -# BACKUP DATABASES -############################## echo "Backing up MySQL databases..." mkdir -p $mydir/mysql if [[ "$cfg__db_info__ndoutils__dbserver" == *":"* ]]; then @@ -170,7 +166,6 @@ if [ $res != 0 ]; then rm -r $mydir exit $res; fi - # Only backup PostgresQL if we are still using it if [ $cfg__db_info__nagiosxi__dbtype == "pgsql" ]; then echo "Backing up PostgresQL databases..." @@ -202,43 +197,6 @@ else fi fi -############################## -# BACKUP CRONJOB ENTRIES -############################## -echo "Backing up cronjobs for Apache..." -if [[ "$distro" == "Ubuntu" ]] || [[ "$distro" == "Debian" ]]; then - do_rsync /var/spool/cron/crontabs/$apacheuser -else - do_rsync /var/spool/cron/apache -fi - -############################## -# BACKUP SUDOERS -############################## -# Not necessary - -############################## -# BACKUP LOGROTATE -############################## -echo "Backing up logrotate config files..." -do_rsync /etc/logrotate.d/nagiosxi - -############################## -# BACKUP APACHE CONFIG FILES -############################## -echo "Backing up Apache config files..." -do_rsync $httpdconfdir/nagios.conf -do_rsync $httpdconfdir/nagiosxi.conf -do_rsync $httpdconfdir/nagiosmobile.conf -do_rsync $httpdconfdir/nagvis.conf -do_rsync $httpdconfdir/nrdp.conf - -if [ -d "/etc/apache2/sites-available" ]; then - do_rsync /etc/apache2/sites-available/default-ssl.conf -else - do_rsync $httpdconfdir/ssl.conf -fi - ############################## # COMPRESS BACKUP ##############################