MYSQL password wrong on Backup

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
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 »

You said:
I have used the new script supplied in this thread & backup is working correctly now
Are you still having issues?
Be sure to check out our Knowledgebase for helpful articles and solutions!
intelXIadmin
Posts: 65
Joined: Mon Mar 25, 2013 9:10 am

Re: MYSQL password wrong on Backup

Post by intelXIadmin »

I changed the root password back to nagiosxi, now the monitoring engine will not start.
intelXIadmin
Posts: 65
Joined: Mon Mar 25, 2013 9:10 am

Re: MYSQL password wrong on Backup

Post by intelXIadmin »

Hello,

I was able to put the database in safe mode and change the password using these commands

1. Put in safe mode: mysqld_safe --skip-grant-tables
2. mysql --user=root mysql
3. update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;

Now I can login to the mysql database. However, the backup script still fails:

[root@ubitmon-jf scripts]# ./backup_xi.sh
Could not open input file: ./import_xiconfig.php
Backing up Core Config Manager (NagiosQL)...
tar: Removing leading `/' from member names
tar: Removing leading `/' from member names
Backing up Nagios Core...
tar: Removing leading `/' from member names
tar: /usr/local/nagios/var/ndo.sock: socket ignored
Backing up Nagios XI...
tar: Removing leading `/' from member names
Backing up MRTG...
tar: Removing leading `/' from member names
Backing up MySQL databases...
Error backing up MySQL database 'nagios' - check the password in this script!
[root@ubitmon-jf scripts]#
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 »

Did you change only the mysql root password, or you changed other passwords as well? Can you verify that you have "n@gweb" set as a password (or whatever you are using) in the "/usr/local/nagiosxi/html/config.inc.php" file (under "ndoutils" and "nagiosql" sections)?
Be sure to check out our Knowledgebase for helpful articles and solutions!
intelXIadmin
Posts: 65
Joined: Mon Mar 25, 2013 9:10 am

Re: MYSQL password wrong on Backup

Post by intelXIadmin »

I only changed the root password, not any other accounts. I have never changed passwords in the the past because I have limited knowledge on mysql.

Both the passwords are set to n@gweb in the script.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: MYSQL password wrong on Backup

Post by slansing »

After changing the password back to nagiosxi "in all locations it was changed" did you "for sanity's sake" run:

Code: Select all

service mysqld stop

service nagios restart

service mysqld start
You are saying that nagios is not starting correct? Or is the icon in the web interface showing up as red?
intelXIadmin
Posts: 65
Joined: Mon Mar 25, 2013 9:10 am

Re: MYSQL password wrong on Backup

Post by intelXIadmin »

The server now starts, but I still cannot back it up. I need to do this today because some major changes are pending doing a backup first.

I never changed any passwords to begin with, but got the password error in the backup. My original question at the start of this thread is how do I do this, and what accounts need to be changed, and what should the passwords be? You say nagiosxi should be the password, but one thread above shows a different password in one of the scripts.

So, I am confused. I never changed any passwords to begin with but this issue showed up after an upgrade.

Regards,

Randy.

slansing wrote:After changing the password back to nagiosxi "in all locations it was changed" did you "for sanity's sake" run:

Code: Select all

service mysqld stop

service nagios restart

service mysqld start
You are saying that nagios is not starting correct? Or is the icon in the web interface showing up as red?
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 »

Can you post the "backup_xi.sh" file in code wraps?
Be sure to check out our Knowledgebase for helpful articles and solutions!
intelXIadmin
Posts: 65
Joined: Mon Mar 25, 2013 9:10 am

Re: MYSQL password wrong on Backup

Post by intelXIadmin »

Yes I did restart all the processes.

I am still waiting though for some information on which accounts need their passwords changed. Obviously, they are not all the same passwords because the script I was asked to verify up above has a different password and according to a previous post, it is correct. :D

Here is a debugged run of the backup_xi script:

Code: Select all

++ dirname backup_xi.sh
+ BASEDIR=.
+ php ./import_xiconfig.php
Could not open input file: ./import_xiconfig.php
+ . ./config.dat
+ rm -rf ./config.dat
+ '[' -n '' ']'
+ '[' -z ']'
+ rootdir=/store/backups/nagiosxi
+ cd /store/backups/nagiosxi
++ date +%s
+ ts=1392052722
+ mydir=/store/backups/nagiosxi/1392052722
+ mkdir -p /store/backups/nagiosxi/1392052722
+ echo 'Backing up Core Config Manager (NagiosQL)...'
Backing up Core Config Manager (NagiosQL)...
+ tar czfps /store/backups/nagiosxi/1392052722/nagiosql.tar.gz /var/www/html/nagiosql
tar: Removing leading `/' from member names
+ tar czfps /store/backups/nagiosxi/1392052722/nagiosql-etc.tar.gz /etc/nagiosql
tar: Removing leading `/' from member names
+ echo 'Backing up Nagios Core...'
Backing up Nagios Core...
+ tar czfps /store/backups/nagiosxi/1392052722/nagios.tar.gz /usr/local/nagios
tar: Removing leading `/' from member names
tar: /usr/local/nagios/var/ndo.sock: socket ignored
+ echo 'Backing up Nagios XI...'
Backing up Nagios XI...
+ tar czfps /store/backups/nagiosxi/1392052722/nagiosxi.tar.gz /usr/local/nagiosxi
tar: Removing leading `/' from member names
+ echo 'Backing up MRTG...'
Backing up MRTG...
+ tar czfps /store/backups/nagiosxi/1392052722/mrtg.tar.gz /var/lib/mrtg
tar: Removing leading `/' from member names
+ cp /etc/mrtg/mrtg.cfg /store/backups/nagiosxi/1392052722/
+ echo 'Backing up MySQL databases...'
Backing up MySQL databases...
+ mkdir -p /store/backups/nagiosxi/1392052722/mysql
+ echo 'rlgdebug --  = '
rlgdebug --  = 
+ mysqldump -h -u --password= --add-drop-database -B
+ res=1
+ '[' 1 '!=' 0 ']'
+ echo 'Error backing up MySQL database '\''nagios'\'' - check the password in this script!'
Error backing up MySQL database 'nagios' - check the password in this script!
+ exit 1

Here is the backup_xi script (I don't know what you meant by code wrap):

Code: Select all

#!/bin/sh

BASEDIR=$(dirname $0)

# IMPORT ALL XI CFG VARS
php $BASEDIR/import_xiconfig.php > $BASEDIR/config.dat
. $BASEDIR/config.dat
rm -rf $BASEDIR/config.dat


###############################
# 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

# 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
echo "rlgdebug -- $cfg_db_info_ndoutils_dbserver = $cfg__db_info__ndoutils__dbserver" 
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

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

##############################
# 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
[root@ubitmon-jf scripts]#
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 »

Hm-m, the script seems to fail because of a wrong mysql password:
Error backing up MySQL database 'nagios' - check the password in this script!
Can you log in mysql, using your new password?

Code: Select all

mysql -p<new password>
Can you also show us all of the code under the "// db-specific connection information" section in the "/usr/local/nagiosxi/html/config.inc.php" file?

Note: Put the text in code wraps: copy/paste, select all text, and click on the "Code" button.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked