Nagios Backups

Good Day,
Is there a best practices guide for backing up Nagios.
We have begun a deployment and I have not found a “proper” method to backup configuration files, client configs and historical data.
Any help would be appreciated.

Thanks,
Duane

Hi Duane,

I am working on my own backup script and came here for a bit of inspiration! :slight_smile:

I have included what I currently have, to share but also to get pointers as to what needs adding / removing to have a successful backup.

for information: I am currently running Nagios, NagiosQL, NagVis and PNP4Nagios.

[code]#!/bin/bash

Set Directories

BACKUP_DIR=/backup
BACKUP_FILE=$BACKUP_DIR/hostname-date +%d%m%Y-%H%M%S.tar.bz2
NAGIOS_FILES=/usr/local/nagios
NAGVIS_FILES=/usr/local/nagvis
PNP4NAGIOS_FILES=/usr/local/pnp4nagios
NAGIOSQL_FILES=/usr/local/nagiosql

Backup MySQL Database

cd /
mysqldump -u root --databases db_nagiosql_v3 > /backup/db_nagiosql.sql

Create and TAR backup

cd /
tar cvfj $BACKUP_FILE $NAGIOS_FILES $NAGVIS_FILES $PNP4NAGIOS_FILES $NAGIOSQL_FILES /backup/db_nagiosql.sql
rm -f /backup_db_nagiosql.sql
[/code]

This script only backups locally at the moment but I will add in some FTP’ing once I get this bit 100%.

Thanks.

After running through an initial rebuild scenario I have come up with the altered backup script. If my next test rebuild works, I’ll post the procedure I created.

[code]#!/bin/bash

Set Directories

BACKUP_DIR=/backup
BACKUP_FILE=$BACKUP_DIR/hostname-date +%d%m%Y-%H%M%S.tar.bz2
NAGIOS_FILES="/usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/etc/cgi.cfg
/usr/local/nagios/etc/resource.cfg
/usr/local/nagios/etc/htpasswd.users"
NAGVIS_FILES="/etc/php.ini
/usr/local/nagvis/etc/maps/
/usr/local/nagvis/share/userfiles/“
PNP4NAGIOS_FILES=”/etc/yum.repos.d/CentOS-Testing.repo
/usr/local/pnp4nagios/var/perfdata/"

Stop Nagios

service nagios stop

Backup MySQL Database

cd /
mysqldump -u root --databases db_nagiosql_v3 > /backup/db_nagiosql.sql
NAGIOSQL_FILES="/backup/db_nagiosql.sql
/etc/httpd/conf.d/nagiosql.conf"

Create and TAR backup

cd /
tar cvfj $BACKUP_FILE $NAGIOS_FILES $NAGVIS_FILES $PNP4NAGIOS_FILES $NAGIOSQL_FILES
rm -f /backup/db_nagiosql.sql

Start Nagios

service nagios start[/code]

By only backing up the files I need (I think!) I have managed to reduce the backup from 12Mb to 4Mb. I only have <300 monitored service at the moment though!

Backup Script:

[code]#!/bin/bash
###########################################################################################

AUTH: Peter Shankland ([email protected])

FILE: /backup/backup-config.sh

VERS: 1.0

INFO: Used to backup Nagios files and FTP

###########################################################################################

MODS: [1.0][01/09/2010] Initial Creation

###########################################################################################

Set Directories

START_TIME=date
FTP=/usr/bin/ftp
TAR=/bin/tar
BACKUP_DIR=/backup
BACKUP_FILE=hostname-date +%d%m%Y-%H%M%S.tar.bz2
NAGIOS_FILES="/usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/etc/cgi.cfg
/usr/local/nagios/etc/resource.cfg
/usr/local/nagios/etc/htpasswd.users"
NAGVIS_FILES="/etc/php.ini
/usr/local/nagvis/etc/maps/
/usr/local/nagvis/share/userfiles/“
PNP4NAGIOS_FILES=”/etc/yum.repos.d/CentOS-Testing.repo
/usr/local/pnp4nagios/var/perfdata/“
OTHER_FILES=”/backup/*.sh"

Stop Nagios

service nagios stop

Backup MySQL Database

cd /
mysqldump -u root --databases db_nagiosql_v3 > $BACKUP_DIR/db_nagiosql.sql
NAGIOSQL_FILES="/backup/db_nagiosql.sql
/etc/httpd/conf.d/nagiosql.conf"

Create and TAR backup

$TAR cvfj $BACKUP_DIR/$BACKUP_FILE $NAGIOS_FILES $NAGVIS_FILES $PNP4NAGIOS_FILES $NAGIOSQL_FILES $OTHER_FILES
rm -f $BACKUP_DIR/db_nagiosql.sql

Start Nagios

service nagios start

Delete backups older than 1 week

find . -name $BACKUP_DIR/*.tar.bz2 -mtime +7 -exec rm -rf {} ; 2>/dev/null

FTP backup

cd $BACKUP_DIR
$FTP -n xxx.xxx.xxx.xxx <<EOF
quote USER username
quote PASS password
binary
cd Backup
put $BACKUP_FILE
quit
EOF

END_TIME=date
[/code]

Procedure:

[quote][size=150]Restore Backup[/size]
mkdir ~/downloads/
mkdir ~/downloads/restored/
extract the backup to this location

[size=150]Install Required Repositories[/size]
cd ~/downloads
wget packages.sw.be/rpmforge-release/ … x86_64.rpm
wget dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
rpm --import RPM-GPG-KEY.dag.txt
rpm -K rpmforge-release-0.5.1-1.el5.rf..rpm
rpm -i rpmforge-release-0.5.1-1.el5.rf.
.rpm
yum update

[size=150]Install Nagios[/size]
yum install net-snmp net-snmp-utils net-snmp-libs
yum install httpd php
yum install gcc glibc glibc-common
yum install gd gd-devel
/usr/sbin/useradd -m nagios
passwd nagios
*****enter password *****
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
wget prdownloads.sourceforge.net/sour … 2.1.tar.gz
wget prdownloads.sourceforge.net/sour … .14.tar.gz
tar xzf nagios-3.2.1.tar.gz
cd nagios-3.2.1
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
Restore /usr/local/nagios/etc/htpasswd.users
cp ~/downloads/restored/usr/local/nagios/etc/htpasswd.users /usr/local/nagios/etc/
service httpd start
cd ~/downloads
tar xzf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chkconfig --add nagios
chkconfig nagios on
chkconfig httpd on
vim /var/www/html/index.html save blank file and exit
Restore Nagios cfg files from backup
cp ~/downloads/restored/usr/local/nagios/etc/*cfg /usr/local/nagios/etc/

[size=150]Install NagiosQL[/size]
cd ~/downloads
yum install mysql-server mysql-devel
yum install php-gettext php-mysql php-ftp php-pear
pear channel-update pear.php.net
pear install HTML_Template_IT
pear upgrade-all
wget sourceforge.net/projects/nagiosq … z/download
tar xzf nagiosql303.tar.gz
mv nagiosql3 /usr/local/
mv /usr/local/nagiosql3 /usr/local/nagiosql
Restore /etc/httpd/conf.d/nagiosql.conf
cp ~/downloads/restored/etc/httpd/conf.d/nagiosql.conf /etc/httpd/conf.d/
mkdir /usr/local/nagiosql/etc
mkdir /usr/local/nagiosql/etc/hosts
mkdir /usr/local/nagiosql/etc/services
mkdir /usr/local/nagiosql/etc/backup
mkdir /usr/local/nagiosql/etc/backup/hosts
mkdir /usr/local/nagiosql/etc/backup/services
chgrp apache /usr/local/nagios
chgrp apache /usr/local/nagios/etc
chgrp apache /usr/local/nagios/etc/nagios.cfg
chgrp apache /usr/local/nagios/etc/cgi.cfg
chmod 775 /usr/local/nagios
chmod 775 /usr/local/nagios/etc
chmod 664 /usr/local/nagios/etc/nagios.cfg
chmod 664 /usr/local/nagios/etc/cgi.cfg
chmod 6755 /usr/local/nagiosql
chmod 6755 /usr/local/nagiosql/etc
chmod 6755 /usr/local/nagiosql/etc/hosts
chmod 6755 /usr/local/nagiosql/etc/services
chmod 6755 /usr/local/nagiosql/etc/backup
chmod 6755 /usr/local/nagiosql/etc/backup/hosts
chmod 6755 /usr/local/nagiosql/etc/backup/services
chown apache.nagios /usr/local/nagiosql
chown apache.nagios /usr/local/nagiosql/etc
chown apache.nagios /usr/local/nagiosql/etc/hosts
chown apache.nagios /usr/local/nagiosql/etc/services
chown apache.nagios /usr/local/nagiosql/etc/backup
chown apache.nagios /usr/local/nagiosql/etc/backup/hosts
chown apache.nagios /usr/local/nagiosql/etc/backup/services
chown nagios.apache /usr/local/nagios/bin/nagios
chmod 750 /usr/local/nagios/bin/nagios
chmod 777 /usr/local/nagiosql/config
chmod 664 /usr/local/nagios/etc/resource.cfg
chmod 777 /usr/local/nagios/var/spool/checkresults
vim /usr/local/nagiosql/install/ENABLE_INSTALLER save an exit empty file
service mysqld start
chkconfig mysqld on
service httpd restart
mkdir /usr/local/nagios/import
visit localhost/nagiosql and complete install
entered in the initial Admin password - same as nagiosadmin

rm /usr/local/nagiosql/install/ENABLE_INSTALLER
import MySQL DB from backup
mysql -u root db_nagiosql_v3 < ~/downloads/restored/backup/db_nagiosql.sql
log into NagiosQL and write EVERY config
DO NOT start Nagios through NagiosQL as it hasn’t started yet! Instead run the following

service nagios start
chown nagios.apache /usr/local/nagios/var/rw/nagios.cmd
chmod 660 /usr/local/nagios/var/rw/nagios.cmd
service nagios restart

[size=150]Install NagVis[/size]yum install gcc gcc-c++
cd ~/downloads
wget mathias-kettner.de/download/mk-l … 6p1.tar.gz
tar xzf mk-livestatus-1.1.6p1.tar.gz
cd mk-livestatus-1.1.6p1
./configure
make
make install
service nagios restart
yum install php-gd php-mbstring
cd /etc/yum.repos.d/
wget graphviz.org/graphviz-rhel.repo
cd ~/downloads
yum install graphviz* --disablerepo=rpmforge --exclude=graphviz-php
wget downloads.sourceforge.net/projec … m&48004736
tar xzf nagvis-1.5.1.tar.gz
cd nagvis-1.5.1
chmod +x install.sh
./install.sh
accept all defaults for installer
service httpd restart
service nagios restart
restore /etc/php.ini from backup
cp ~/downloads/restored/etc/php.ini /etc/
restore /usr/local/nagvis/etc/maps/ from backup
cp -r ~/downloads/restored/usr/local/nagvis/etc/maps/ /usr/local/nagvis/etc/
restore /usr/local/nagvis/share/userfiles/ from backup
yes | cp -r ~/downloads/restored/usr/local/nagvis/share/userfiles/ /usr/local/nagvis/share/
shutdown -r 0
log on to localhost/nagvis/ and change default password of U=nagiosadmin, P=nagiosadmin to the same as the nagios user

[size=150]Install PNP4Nagios[/size]
Restore /etc/yum.repos.d/CentOS-Testing.repo from backup
cp ~/downloads/restored/etc/yum.repos.d/CentOS-Testing.repo /etc/yum.repos.d/
yum update
yum install rrdtool perl-rrdtool
yum install perl-Net-SNMP perl-Net-DNS
cd ~/downloads
wget sourceforge.net/projects/pnp4nag … z/download
tar xzf pnp4nagios-0.6.6.tar.gz
cd pnp4nagios-0.6.6
./configure
make all
make install
make install-webconf
make install-config
make install-init
service httpd restart
service nagios restart
goto localhost/pnp4nagios/ if you get no errors complete the following:
rm /usr/local/pnp4nagios/share/install.php
service nagios stop
restore /usr/local/pnp4nagios/var/perfdata/ from backup
yes | cp -r ~/downloads/restored/usr/local/pnp4nagios/var/perfdata/ /usr/local/pnp4nagios/var/
service nagios start

[size=150]Setup Backup Job[/size]
mkdir /backup
Restore backup-config.sh
cp ~/downloads/restored/backup/backup-config.sh /backup
vim /etc/crontab
add the following line
55 23 * * * /backup/backup-config.sh
[/quote]

Now the above has worked for me but there is obviously 0% guarantee that it will for anyone else :slight_smile:

Pete.