Centreon and Nagios backup

These are two scripts I've been using for years now to succefully backup Nagios and Centreon. Feel free to use them.

Nagios

#!/bin/bash
#
# backup the nagios configuration files and plugins
# roderick at roderick-ict.nl
# www.roderick-ict.nl
#
# v 20070313.2
#
# option = full (backup_nagios_config.sh full)
#
####################################################
if [ "$1" = "help" ]; then
   echo "options: none for just the config, <full> for full backup"
   echo
   exit
fi

### set variables, used for when you have more sites where nagios is running
    if [ "$HOSTNAME" = "centreon.r71.nl" ]; then
       SITE="r71"
       EMAILADDRESS=" This e-mail address is being protected from spambots. You need JavaScript enabled to view it "
    else
       SITE="ezh"
       EMAILADDRESS=" This e-mail address is being protected from spambots. You need JavaScript enabled to view it "
    fi

    DATE=$(date +%Y%m%d%H%M%S)
    BACKUP_DIR="/root/nagios/backup"
    BACKUP_CONFIGFILE="${DATE}_backup_nagios_config_${SITE}_site.tar.gz"
    BACKUP_FULLFILE="${DATE}_fullbackup_nagios_${SITE}_site.tar.gz"
    TEMPFILE="/tmp/nagios.tmp"
    BACKUPDIR_CONFIGFILE="${BACKUP_DIR}/${BACKUP_CONFIGFILE}"
    BACKUPDIR_FULLFILE="${BACKUP_DIR}/${BACKUP_FULLFILE}"

    if [ ! -e  $BACKUP_DIR ]; then
       mkdir $BACKUP_DIR
    fi

#cd $BACKUPDIR

## Remove Old Backupfiles
find $BACKUPDIR -mtime +1 -type f -exec rm {} \;


## backup command
echo Backing up the Nagios configuration files and plugins

if [ "$1" = "full" ]; then
       tar czf $BACKUPDIR_FULLFILE /usr/local/nagios/ /etc/init.d/nagios /root/nagios/backup_nagios_config.sh /usr/share/snmp/mibs
else
       tar czf $BACKUPDIR_CONFIGFILE /usr/local/nagios/ /etc/init.d/nagios /root/nagios/backup_nagios_config.sh /usr/share/snmp/mibs --exclude /usr/local/nagios/nagiosgraph --exclude /usr/local/nagios/var
fi



if [ "$1" != full ]; then

  if [ "$?" -ne "0" ]; then
     echo problem detected creating the tar file $BACKUPDIR_CONFIGFILE
  fi

  if [ -e $BACKUPDIR_CONFIGFILE ]; then
     echo
     echo Hurray, we created a perfect backup!
     echo File:
     ls -al $BACKUPDIR_CONFIGFILE
     echo
  fi
else
  if [ "$?" -ne "0" ]; then
     echo problem detected creating the tar file $BACKUPDIR_FULLFILE
  fi

  if [ -e $BACKUPDIR_FULLFILE ]; then
     echo
     echo Hurray, we created a perfect fullbackup!
     echo File:
     ls -al $BACKUPDIR_FULLFILE
     echo
  fi

fi



#if [ "$1" != full ]; then
#
#  echo Hurray, another backup of the Nagios Config files and plugins. See the attachement. > $TEMPFILE
#  echo Sending the files to $EMAILADDRESS
#  echo

#  ## mail the stuff
#  mutt -s "Another lovely Nagios backup from the ${SITE} site" -a $BACKUPDIR_CONFIGFILE $EMAILADDRESS < $TEMPFILE
#
#
#  if [ "$?" -ne "0" ]; then
#     echo problem detected creating when trying to send an email to $EMAILADDRESS
#  fi
#
#  rm -f $TEMPFILE
#fi

exit 0

Centreon

#!/bin/bash
#
# backup the centreon databases and files
# roderick at roderick-ict.nl
# www.roderick-ict.nl
#
# v 20070313.2
#
#
####################################################
if [ "$1" = "help" ]; then
   echo "options: none, this script makes a full backup of the centreon databases"
   echo
   exit
fi

    DATE=$(date +%Y%m%d%H%M%S)
    BACKUP_DIR="/root/centreon/backup"

echo BACKUP_DIR $BACKUP_DIR

    if [ ! -e  $BACKUP_DIR ]; then
       mkdir $BACKUP_DIR
    fi

#cd $BACKUPDIR

## Remove Old Backupfiles
find $BACKUPDIR -mtime +1 -type f -exec rm {} \;


## backup command

     echo Backing up the ndo database..
     mysqldump --opt -hlocalhost -uroot -proot ndo |gzip > ${BACKUP_DIR}/${DATE}.ndo.sql.gz
     echo Backing up the centreon database..
     mysqldump --opt -hlocalhost -uroot -proot centreon |gzip > ${BACKUP_DIR}/${DATE}.centreon.sql.gz
     echo Backing up the centstorage database..
     mysqldump --opt -hlocalhost -uroot -proot centstorage |gzip > ${BACKUP_DIR}/${DATE}.centstorage.sql.gz

     echo Backing up the Centreon files
     tar czf ${BACKUP_DIR}/${DATE}.centreon.files.tar.gz /usr/local/centreon/ /etc/centreon /var/lib/centreon /etc/httpd/conf.d/centreon.conf

exit 0