@ -63,8 +63,10 @@ done
# Restart nagios to forcibly update retention.dat
echo "Restart nagios to forcibly update retention.dat"
sudo $BASEDIR /manage_services.sh restart nagios
sleep 10
sudo $BASEDIR /manage_services.sh stop nagios
sleep 5
sudo $BASEDIR /manage_services.sh start nagios
if [ -z $rootdir ] ; then
rootdir = "/store/backups/nagiosxi"
@ -140,7 +142,13 @@ do_rsync $httpdconfdir/nagiosmobile.conf
do_rsync $httpdconfdir /nagvis.conf
do_rsync $httpdconfdir /nrdp.conf
echo "Backing up MySQL databases..."
verbose "Checking nagios.cfg for nonstandard directories..."
for dir in ` egrep "[^#].*=" /usr/local/nagios/etc/nagios.cfg | awk -F= '/\// {print $2}' | egrep -v "(usr/lib|/usr/local/nagios|/tmp|/var/run)" | rev | cut -d "/" -f 2- | rev | sort -u` ; do
echo " Directory $dir needs to be copied "
do_rsync " ${ dir } / "
done
verbose "Backing up MySQL databases..."
mkdir -p $mydir /mysql
if [ [ " $cfg__db_info__ndoutils__dbserver " = = *":" * ] ] ; then
ndoutils_dbport = ` echo " $cfg__db_info__ndoutils__dbserver " | cut -f2 -d":" `
@ -152,7 +160,7 @@ fi
mysqldump -h " $ndoutils_dbserver " --port= " $ndoutils_dbport " -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!" | tee -a $SBLOG
error "Error backing up MySQL database 'nagios' - check the password in this script!" | tee -a $SBLOG
rm -rf $mydir
exit $res ;
fi
@ -166,13 +174,13 @@ fi
mysqldump -h " $nagiosql_dbserver " --port= " $nagiosql_dbport " -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!" | tee -a $SBLOG
error "Error backing up MySQL database 'nagiosql' - check the password in this script!" | tee -a $SBLOG
rm -rf $mydir
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..."
verbose "Backing up PostgresQL databases..."
mkdir -p $mydir /pgsql
if [ -z $cfg__db_info__nagiosxi__dbserver ] ; then
cfg__db_info__nagiosxi__dbserver = "localhost"
@ -180,7 +188,7 @@ if [ $cfg__db_info__nagiosxi__dbtype == "pgsql" ]; then
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' !" | tee -a $SBLOG
error "Error backing up PostgresQL database 'nagiosxi' !" | tee -a $SBLOG
rm -rf $mydir
exit $res ;
fi
@ -195,7 +203,7 @@ else
mysqldump -h " $nagiosxi_dbserver " --port= " $nagiosxi_dbport " -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!" | tee -a $SBLOG
error "Error backing up MySQL database 'nagiosxi' - check the password in this script!" | tee -a $SBLOG
rm -rf $mydir
exit $res ;
fi
@ -204,7 +212,7 @@ fi
##############################
# COMPRESS BACKUP
##############################
echo "Compressing backup..."
verbose "Compressing backup..."
tar czfp $name .tar.gz $name
rm -rf $name
@ -216,13 +224,13 @@ if [ -s $name.tar.gz ];then
echo "==============="
echo "BACKUP COMPLETE"
echo "==============="
echo " Backup stored in $rootdir / $name .tar.gz "
verbose " Backup stored in $rootdir / $name .tar.gz "
else
echo " "
echo "==============="
echo "BACKUP FAILED"
echo "==============="
echo " File was not created at $rootdir / $name .tar.gz "
error " File was not created at $rootdir / $name .tar.gz "
rm -rf $mydir
exit 1;
fi