Minor updates to client/server sides

2021
Eric Loyd 6 years ago
parent faf9fdd312
commit 34d701c7d5

@ -1,8 +1,8 @@
primary: primary: sync
./failover.sh -P 192.168.56.113 -S 192.168.56.114 -H 192.168.56.113 ./failover.sh -P 192.168.56.113 -S 192.168.56.114 -H 192.168.56.113
secondary: secondary:
./failover.sh -P 192.168.56.113 -S 192.168.56.114 -H 192.168.56.114 ./failover.sh -P 192.168.56.113 -S 192.168.56.114 -H 192.168.56.114
sync: sync:
rsync -avu --stats . clone:/root/princeton/failover rsync -av --stats ./ secondary:/root/princeton/failover

@ -11,6 +11,7 @@ PATH=/usr/sbin:/sbin:/usr/bin:/bin
primary="nagiosxi-p.princeton.edu" primary="nagiosxi-p.princeton.edu"
secondary="nagiosxi-f.princeton.edu" secondary="nagiosxi-f.princeton.edu"
synconly="false" synconly="false"
syncname="sync"
hostname=`/bin/hostname` hostname=`/bin/hostname`
@ -19,6 +20,7 @@ while [ -n "$1" ]; do
-H | --hostname) hostname="$2"; shift 2;; -H | --hostname) hostname="$2"; shift 2;;
-S | --secondary) secondary="$2"; shift 2;; -S | --secondary) secondary="$2"; shift 2;;
-P | --primary) primary="$2"; shift 2;; -P | --primary) primary="$2"; shift 2;;
-n | --sync-name) syncname="$2"; shift 2;;
-s | --sync-only) synconly="true"; shift 1;; -s | --sync-only) synconly="true"; shift 1;;
*) shift 1;; *) shift 1;;
esac esac
@ -33,17 +35,17 @@ do_nothing() {
do_primary() { do_primary() {
echo "We are the primary. Creating package to send to secondary." 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() { do_secondary() {
echo "We are the secondary. Expanding package from the primary." echo "We are the secondary. Expanding package from the primary."
mysqlfile=`ls -tr1 /store/backups/nagiosxi/ | tail -1` syncfile=`ls -tr1 /store/backups/nagiosxi/ | tail -1`
[ -z "$mysqlfile" ] && echo "No MySQL Backup file." && exit 2 [ -z "$syncfile" ] && echo "No sync file ($syncfile) found." && exit 2
./restore_xi.sh /store/backups/nagiosxi/$mysqlfile ./restore_xi.sh /store/backups/nagiosxi/$syncfile
./nagios_startstop.sh stop ./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 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 case "$hostname" in

@ -115,7 +115,6 @@ if [ $res != 0 ]; then
echo "Error restoring MySQL database 'nagios' - check the password in this script!" echo "Error restoring MySQL database 'nagios' - check the password in this script!"
exit; exit;
fi fi
if [[ "$cfg__db_info__nagiosql__dbserver" == *":"* ]]; then if [[ "$cfg__db_info__nagiosql__dbserver" == *":"* ]]; then
nagiosql_dbport=`echo "$cfg__db_info__nagiosql__dbserver" | cut -f2 -d":"` nagiosql_dbport=`echo "$cfg__db_info__nagiosql__dbserver" | cut -f2 -d":"`
nagiosql_dbserver=`echo "$cfg__db_info__nagiosql__dbserver" | cut -f1 -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!" echo "Error restoring MySQL database 'nagiosql' - check the password in this script!"
exit; exit;
fi fi
# Only restore PostgresQL if we are still using it # Only restore PostgresQL if we are still using it
if [ "$cfg__db_info__nagiosxi__dbtype" == "pgsql" ]; then if [ "$cfg__db_info__nagiosxi__dbtype" == "pgsql" ]; then
service postgresql initdb &>/dev/null || true service postgresql initdb &>/dev/null || true
echo "Restoring Nagios XI PostgresQL database..." echo "Restoring Nagios XI PostgresQL database..."
if [ -f /var/lib/pgsql/data/pg_hba.conf ]; then if [ -f /var/lib/pgsql/data/pg_hba.conf ]; then
pghba="/var/lib/pgsql/data/pg_hba.conf" 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 echo "local all all trust
host all all 127.0.0.1/32 trust host all all 127.0.0.1/32 trust
host all all ::1/128 trust" > $pghba host all all ::1/128 trust" > $pghba
$BASEDIR/manage_services.sh start postgresql $BASEDIR/manage_services.sh start postgresql
sudo -u postgres psql -c "create user nagiosxi with password 'n@gweb';" sudo -u postgres psql -c "create user nagiosxi with password 'n@gweb';"
sudo -u postgres psql -c "create database nagiosxi owner nagiosxi;" sudo -u postgres psql -c "create database nagiosxi owner nagiosxi;"
$BASEDIR/manage_services.sh restart postgresql $BASEDIR/manage_services.sh restart postgresql
# Sleep a bit (required so Postgres finishes startup before we connect again) # Sleep a bit (required so Postgres finishes startup before we connect again)
echo "Sleeping for a few seconds (please wait)..." echo "Sleeping for a few seconds (please wait)..."
sleep 7 sleep 7
psql -U nagiosxi nagiosxi < $backupdir/pgsql/nagiosxi.sql psql -U nagiosxi nagiosxi < $backupdir/pgsql/nagiosxi.sql
res=$? res=$?
if [ $res != 0 ]; then if [ $res != 0 ]; then
@ -202,27 +193,17 @@ else
exit; exit;
fi fi
fi fi
echo "Restarting database servers..."
$BASEDIR/manage_services.sh restart mysqld
} }
############################## restore_databases
# RESTART SERVICES echo "Restarting services..."
############################## $BASEDIR/manage_services.sh restart mysqld
$BASEDIR/manage_services.sh restart httpd $BASEDIR/manage_services.sh restart httpd
$BASEDIR/manage_services.sh start npcd $BASEDIR/manage_services.sh start npcd
$BASEDIR/manage_services.sh start ndo2db $BASEDIR/manage_services.sh start ndo2db
$BASEDIR/manage_services.sh start nagios $BASEDIR/manage_services.sh start nagios
##############################
# DELETE TEMP RESTORE DIRECTORY
##############################
rm -rf $mydir rm -rf $mydir
##############################
# DELETE forceinstall FILE
##############################
rm -f /tmp/nagiosxi.forceinstall rm -f /tmp/nagiosxi.forceinstall
echo " " echo " "

@ -93,53 +93,49 @@ mkdir -p $mydir
############################## ##############################
# BACKUP DIRS # BACKUP DIRS
############################## ##############################
do_rsync() { 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 # Only backup NagiosQL if it exists
if [ -d "/var/www/html/nagiosql" ]; then if [ -d "/var/www/html/nagiosql" ]; then
echo "Backing up NagiosQL..."
do_rsync /var/www/html/nagiosql/ do_rsync /var/www/html/nagiosql/
do_rsync /etc/nagiosql/ do_rsync /etc/nagiosql/
fi fi
echo "Backing up Nagios Core..."
do_rsync /usr/local/nagios
# Backup ramdisk if it exists # Backup ramdisk if it exists
if [ -f "/etc/sysconfig/nagios" ]; then if [ -f "/etc/sysconfig/nagios" ]; then
echo "Copying ramdisk configuration..."
do_rsync /etc/sysconfig/nagios do_rsync /etc/sysconfig/nagios
fi 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/ do_rsync /etc/mrtg/conf.d/
do_rsync /etc/mrtg/mrtg.cfg
# SNMP configs and MIBS
echo "Backing up the SNMP directories"
do_rsync /etc/snmp/ do_rsync /etc/snmp/
do_rsync /usr/share/snmp/ do_rsync /home/nagios/
do_rsync /usr/local/nagios/
echo "Backing up NRDP..." do_rsync /usr/local/nagiosmobile/
do_rsync /usr/local/nrdp/ do_rsync /usr/local/nagiosxi/
echo "Backing up Nagvis..."
do_rsync /usr/local/nagvis/ 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 /etc/logrotate.d/nagiosxi
do_rsync /home/nagios/ 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..." echo "Backing up MySQL databases..."
mkdir -p $mydir/mysql mkdir -p $mydir/mysql
if [[ "$cfg__db_info__ndoutils__dbserver" == *":"* ]]; then if [[ "$cfg__db_info__ndoutils__dbserver" == *":"* ]]; then
@ -170,7 +166,6 @@ if [ $res != 0 ]; then
rm -r $mydir rm -r $mydir
exit $res; exit $res;
fi fi
# Only backup PostgresQL if we are still using it # Only backup PostgresQL if we are still using it
if [ $cfg__db_info__nagiosxi__dbtype == "pgsql" ]; then if [ $cfg__db_info__nagiosxi__dbtype == "pgsql" ]; then
echo "Backing up PostgresQL databases..." echo "Backing up PostgresQL databases..."
@ -202,43 +197,6 @@ else
fi fi
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 # COMPRESS BACKUP
############################## ##############################

Loading…
Cancel
Save