MYSQL password wrong on Backup

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: MYSQL password wrong on Backup

Post by scottwilkerson »

Can you run

Code: Select all

ls -l /usr/local/nagiosxi/scripts/import_xiconfig.php
Also, can you confirm you are on version 2012R2.8+

The attached script will only work on 2012R2.8+
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
intelXIadmin
Posts: 65
Joined: Mon Mar 25, 2013 9:10 am

Re: MYSQL password wrong on Backup

Post by intelXIadmin »

I am on version 2012r2.7. That is the version where all of the sudden the password issue came into place. The reason for the backup was to install the upgrade. I am afraid if those passwords are wrong, the upgrade will fail. :)
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: MYSQL password wrong on Backup

Post by lmiltchev »

The upgrade should actually fix the problem. If for some reason upgrade fails, this shouldn't break your current Nagios XI instance. If you wish, you can put the "old" script back and run it to make sure it works (prior to the upgrade). The backup should work, since you've fixed the issue with the root password.

Note: If you haven't saved the old backup script, here is a copy of it:

Code: Select all

#!/bin/sh

###############################
# USAGE / HELP
###############################
usage () {
	echo ""
	echo "Use this script to backup Nagios XI."
	echo ""
		echo " -n | --name              Set the name of the backup minus the .tar.gz"
        echo " -p | --prepend           Prepend a string to the .tar.gz name"
        echo " -a | --append            Append a string to the .tar.gz name"
        echo " -d | --directory         Change the directory to store the compressed backup"
	echo ""
}

###############################
# ADDING LOGIC FOR NEW BACKUPS
###############################
while [ -n "$1" ]; do
	case "$1" in
		-h | --help)
			usage
			exit 0
			;;
		-n | --name)
			fullname=$2
			;;
		-p | --prepend)
			prepend=$2
			;;
		-a | --append)
			append=$2
			;;
		-d | --directory)
			rootdir=$2
			;;
	esac
	shift
done


# MySQL root password
mysqlpass="nagiosxi"

# Must be root
#me=`whoami`
#if [ $me != "root" ]; then
#	echo "You must be root to run this script."
#	exit 1
#fi
# No longer need root because of file permissions -JO

if [ -z $rootdir ]; then
	rootdir=/store/backups/nagiosxi
fi

# Make root directory to store backups
#mkdir -p $rootdir
cd $rootdir
# Directory is created upon XI install -JO

# Get current Unix timestamp
ts=`date +%s`

# My working directory
mydir=$rootdir/$ts

# Make directory for this specific backup
mkdir -p $mydir

##############################
# BACKUP DIRS
##############################

echo "Backing up Core Config Manager (NagiosQL)..."
#cp -rp /var/www/html/nagiosql $mydir
#cp -rp /etc/nagiosql $mydir/nagiosql-etc
tar czfps $mydir/nagiosql.tar.gz /var/www/html/nagiosql
tar czfps $mydir/nagiosql-etc.tar.gz /etc/nagiosql

echo "Backing up Nagios Core..."
#cp -rp /usr/local/nagios $mydir
tar czfps $mydir/nagios.tar.gz /usr/local/nagios

echo "Backing up Nagios XI..."
#cp -rp /usr/local/nagiosxi $mydir
tar czfps $mydir/nagiosxi.tar.gz /usr/local/nagiosxi

echo "Backing up MRTG..."
#cp -rp /usr/local/nagiosxi $mydir
tar czfps $mydir/mrtg.tar.gz /var/lib/mrtg
cp /etc/mrtg/mrtg.cfg $mydir/

##############################
# BACKUP DATABASES
##############################
echo "Backing up MySQL databases..."
mkdir -p $mydir/mysql
mysqldump -u root --password=$mysqlpass --add-drop-database -B nagios > $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 -u root --password=$mysqlpass --add-drop-database -B nagiosql > $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

echo "Backing up PostgresQL databases..."
mkdir -p $mydir/pgsql
pg_dump -c -U nagiosxi nagiosxi > $mydir/pgsql/nagiosxi.sql
res=$?
if [ $res != 0 ]; then
	echo "Error backing up PostgresQL database 'nagiosxi' !"
	exit $res;
fi

##############################
# BACKUP CRONJOB ENTRIES
##############################
# Not necessary

##############################
# BACKUP SUDOERS
##############################
# Not necessary

##############################
# BACKUP LOGROTATE
##############################
echo "Backing up logrotate config files..."
mkdir -p $mydir/logrotate
cp -rp /etc/logrotate.d/nagiosxi $mydir/logrotate

##############################
# BACKUP APACHE CONFIG FILES
##############################
echo "Backing up Apache config files..."
mkdir -p $mydir/httpd
cp -rp /etc/httpd/conf.d/nagios.conf $mydir/httpd
cp -rp /etc/httpd/conf.d/nagiosxi.conf $mydir/httpd
cp -rp /etc/httpd/conf.d/nagiosql.conf $mydir/httpd

#############################
# SET THE NAME
#############################
name=$fullname
if [ -z $fullname ]; then
	name=$prepend$ts$append
fi

##############################
# ZIP BACKUP
##############################
echo "Compressing backup..."
tar czfps $name.tar.gz $ts
rm -rf $ts

if [ -s $name.tar.gz ];then

	echo " "
	echo "==============="
	echo "BACKUP COMPLETE"
	echo "==============="
	echo "Backup stored in $rootdir/$name.tar.gz"

	exit 0;
else
	echo " "
	echo "==============="
	echo "BACKUP FAILED"
	echo "==============="
	echo "File was not created at $rootdir/$name.tar.gz"

	exit 1;
fi
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked