Nagios backupstipt and remote db's

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
benhank
Posts: 1264
Joined: Tue Apr 12, 2011 12:29 pm

Nagios backupstipt and remote db's

Post by benhank »

Howdi fellas

Because of the size of my environment we were advised to store our db on a remote server. This setup is fine and working well.
the problem is that the bundled back up script

Code: Select all

/usr/local/nagiosxi/backupxi.sh
does not back up the remote db.
Can you mad scientist evil geniuses show a brutha how to get the script to include the remote db in the backup?
thanks and MUHAHAHAHAH! in advance!
Proudly running:
NagiosXI 5.4.12 2 node Prod Env 2500 hosts, 13,000 services
Nagiosxi 5.5.7(test env) 2500 hosts, 13,000 services
Nagios Logserver 2 node Prod Env 500 objects sending
Nagios Network Analyser
Nagios Fusion
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios backupstipt and remote db's

Post by jdalrymple »

Hey benhank,

This really should do offloaded dbs as well. Check out the code:

Code: Select all

##############################
# BACKUP DATABASES
##############################
echo "Backing up MySQL databases..."
mkdir -p $mydir/mysql
mysqldump -h $cfg__db_info__ndoutils__dbserver -u $cfg__db_info__ndoutils__user --password="$cfg__db_info__ndoutils__pwd" --add-drop-database -B $cfg__db_info__ndoutils__db > $mydir/mysql/nagios.sql
res=$?
if [ $res != 0 ]; then
        echo "Error backing up MySQL database 'nagios' - check the password in this script!"
        exit $res;
fi
mysqldump -h $cfg__db_info__nagiosql__dbserver -u $cfg__db_info__nagiosql__user --password="$cfg__db_info__nagiosql__pwd" --add-drop-database -B $cfg__db_info__nagiosql__db > $mydir/mysql/nagiosql.sql
res=$?
if [ $res != 0 ]; then
        echo "Error backing up MySQL database 'nagiosql' - check the password in this script!"
        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..."
        mkdir -p $mydir/pgsql
        if [ -z $cfg__db_info__nagiosxi__dbserver ]; then
                cfg__db_info__nagiosxi__dbserver="localhost"
        fi
        pg_dump -h $cfg__db_info__nagiosxi__dbserver -c -U $cfg__db_info__nagiosxi__user $cfg__db_info__nagiosxi__db > $mydir/pgsql/nagiosxi.sql
        res=$?
        if [ $res != 0 ]; then
                echo "Error backing up PostgresQL database 'nagiosxi' !"
                exit $res;
        fi
else
        mysqldump -h $cfg__db_info__nagiosxi__dbserver -u $cfg__db_info__nagiosxi__user --password="$cfg__db_info__nagiosxi__pwd" --add-drop-database -B $cfg__db_info__nagiosxi__db > $mydir/mysql/nagiosxi.sql
        res=$?
        if [ $res != 0 ]; then
                echo "Error backing up MySQL database 'nagiosxi' - check the password in this script!"
                exit $res;
        fi
fi
The important bits are the -h $cfg__db_info__xyz__dbserver for each database getting dumped. If it's not working then that variable isn't getting set correctly, however, if I'm not mistaken ... if that variable isn't getting set correctly then Nagios XI is broken :) I think it grabs that information from the same exact place all the other code gets it from:

Code: Select all

# IMPORT ALL XI CFG VARS
php $BASEDIR/import_xiconfig.php > $BASEDIR/config.dat
. $BASEDIR/config.dat
How are you verifying that the remote dbs aren't getting backed up?
User avatar
benhank
Posts: 1264
Joined: Tue Apr 12, 2011 12:29 pm

Re: Nagios backupstipt and remote db's

Post by benhank »

how do i modify the backup script so that it doesn't backup the db? I think that will solve 1 part of my problem
Proudly running:
NagiosXI 5.4.12 2 node Prod Env 2500 hosts, 13,000 services
Nagiosxi 5.5.7(test env) 2500 hosts, 13,000 services
Nagios Logserver 2 node Prod Env 500 objects sending
Nagios Network Analyser
Nagios Fusion
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Nagios backupstipt and remote db's

Post by BanditBBS »

benhank wrote:how do i modify the backup script so that it doesn't backup the db? I think that will solve 1 part of my problem
benhank, your DB should already be getting backed up, I know my offloaded one is being backed up with the default scripts. How are you determining your DB is not?
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
User avatar
benhank
Posts: 1264
Joined: Tue Apr 12, 2011 12:29 pm

Re: Nagios backupstipt and remote db's

Post by benhank »

lemme dble check that BB
Proudly running:
NagiosXI 5.4.12 2 node Prod Env 2500 hosts, 13,000 services
Nagiosxi 5.5.7(test env) 2500 hosts, 13,000 services
Nagios Logserver 2 node Prod Env 500 objects sending
Nagios Network Analyser
Nagios Fusion
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Nagios backupstipt and remote db's

Post by BanditBBS »

benhank wrote:lemme dble check that BB
benhank - I just dbl checked myself, my DR server where my nightly backups are rcync'd. I extracted the files and verified data in the nagiosql db is updated with stuff that was only put in last week. So, if yours isn't being backed up, I fear it is a different issue than the script.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
User avatar
benhank
Posts: 1264
Joined: Tue Apr 12, 2011 12:29 pm

Re: Nagios backupstipt and remote db's

Post by benhank »

ok so i get the error listed below:

Code: Select all

/store/backups/./restore_xi.sh /store/backups/nagiosxi/1445278732.tar.gz
Could not open input file: /store/backups/import_xiconfig.php
TS=1445279187
Extracting backup to /store/backups/nagiosxi/1445279187-restore...
In /store/backups/nagiosxi/1445279187-restore/1445278732...
Backup files look okay.  Preparing to restore...
Shutting down services...
Stopping nagios:. done.
Stopping ndo2db: done.
rm: cannot remove `/usr/local/nagiosxi/var/subsys/npcd.pid': No such file or directory
NPCD was not running.
Restoring directories to /...
Restoring Nagios Core...
Restoring Nagios XI...
Restoring NagiosQL...
Restoring NagiosQL backups...
Restoring NRDP backups...
Restoring MRTG...
Restoring MySQL databases...
ERROR 2005 (HY000): Unknown MySQL server host '-u' (1)
Error restoring MySQL database 'nagios' - check the password in this script!
Normally I would just change the db pw, but I know that in this case we went with all the defaults.
Proudly running:
NagiosXI 5.4.12 2 node Prod Env 2500 hosts, 13,000 services
Nagiosxi 5.5.7(test env) 2500 hosts, 13,000 services
Nagios Logserver 2 node Prod Env 500 objects sending
Nagios Network Analyser
Nagios Fusion
User avatar
benhank
Posts: 1264
Joined: Tue Apr 12, 2011 12:29 pm

Re: Nagios backupstipt and remote db's

Post by benhank »

BB, I think that your solution is the one I am aiming for.
How do you have your script set up? can you pm it to me ?
Proudly running:
NagiosXI 5.4.12 2 node Prod Env 2500 hosts, 13,000 services
Nagiosxi 5.5.7(test env) 2500 hosts, 13,000 services
Nagios Logserver 2 node Prod Env 500 objects sending
Nagios Network Analyser
Nagios Fusion
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Nagios backupstipt and remote db's

Post by BanditBBS »

benhank wrote:BB, I think that your solution is the one I am aiming for.
How do you have your script set up? can you pm it to me ?
I just used the scheduled backups in admin menu. Limit to 4 and then on my PROD XI server I have rsync setup to rsync the /store/backups folder to my DR server in a different data center about 2 hours after the backup files get created. I have rsync set to delete files no longer existing on the source

Code: Select all

30 02 * * * rsync -azv --bwlimit=25600 --progress --delete /store/backups/nagiosxi/ dr-server-hostname.domain:/store/backups/nagiosxi
I haven't yet done a restore, so not sure if I would get the same error as you are during a restore attempt. I just know the DB is actually backed up from looking in the archives being rsync'd to the DR server.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
User avatar
benhank
Posts: 1264
Joined: Tue Apr 12, 2011 12:29 pm

Re: Nagios backupstipt and remote db's

Post by benhank »

well sir I am gonna try it, thanks for the help bro!
Proudly running:
NagiosXI 5.4.12 2 node Prod Env 2500 hosts, 13,000 services
Nagiosxi 5.5.7(test env) 2500 hosts, 13,000 services
Nagios Logserver 2 node Prod Env 500 objects sending
Nagios Network Analyser
Nagios Fusion
Locked