Page 1 of 2

Nagios backupstipt and remote db's

Posted: Fri Oct 16, 2015 4:07 pm
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!

Re: Nagios backupstipt and remote db's

Posted: Sun Oct 18, 2015 11:31 am
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?

Re: Nagios backupstipt and remote db's

Posted: Mon Oct 19, 2015 1:13 pm
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

Re: Nagios backupstipt and remote db's

Posted: Mon Oct 19, 2015 1:16 pm
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?

Re: Nagios backupstipt and remote db's

Posted: Mon Oct 19, 2015 1:19 pm
by benhank
lemme dble check that BB

Re: Nagios backupstipt and remote db's

Posted: Mon Oct 19, 2015 1:26 pm
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.

Re: Nagios backupstipt and remote db's

Posted: Mon Oct 19, 2015 1:28 pm
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.

Re: Nagios backupstipt and remote db's

Posted: Mon Oct 19, 2015 1:43 pm
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 ?

Re: Nagios backupstipt and remote db's

Posted: Mon Oct 19, 2015 1:51 pm
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.

Re: Nagios backupstipt and remote db's

Posted: Mon Oct 19, 2015 1:55 pm
by benhank
well sir I am gonna try it, thanks for the help bro!