1

Topic: Backup problem - wrong username or password

==== Required information ====
- iRedMail version: 0.8.3
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): LDAP
- Linux/BSD distribution name and version: Debian 6
- Related log if you're reporting an issue:
====

Hello,
From couple of days I get this in my Logwatch mail:

[ERROR] MySQL username or password is incorrect in file /var/vmail/backup/backup_mysql.sh.
Please fix them first.

I check username and password and it's correct. I can without any problem login with username and password in that file to phpMyAdmin.

Any suggestions?

ag

2

Re: Backup problem - wrong username or password

Does it work if you execute this script manually? For example:

# bash /var/vmail/backup/backup_mysql.sh

3

Re: Backup problem - wrong username or password

No. I get the same error text.

4

Re: Backup problem - wrong username or password

Could you please try this:

# bash -xv /var/vmail/backup/backup_mysql.sh

Option '-xv' will print debug message in terminal, please paste them all here to help troubleshoot. Of course you must replace sensitive info before pasting, e.g. mysql password.

5

Re: Backup problem - wrong username or password

#!/usr/bin/env bash

# Author:   Zhang Huangbin (zhb@iredmail.org)
# Date:     16/09/2007
# Purpose:  Backup specified mysql databases with command 'mysqldump'.
# License:  This shell script is part of iRedMail project, released under
#           GPL v2.

###########################
# REQUIREMENTS
###########################
#
#   * Required commands:
#       + mysqldump
#       + du
#       + bzip2 or gzip     # If bzip2 is not available, change 'CMD_COMPRESS'
#                           # to use 'gzip'.
#

###########################
# USAGE
###########################
#
#   * It stores all backup copies in directory '/var/vmail/backup' by default,
#     You can change it in variable $BACKUP_ROOTDIR below.
#
#   * Set correct values for below variables:
#
#       BACKUP_ROOTDIR
#       MYSQL_USER
#       MYSQL_PASSWD
#       DATABASES
#       DB_CHARACTER_SET
#       COMPRESS
#       DELETE_PLAIN_SQL_FILE
#
#   * Add crontab job for root user (or whatever user you want):
#
#       # crontab -e -u root
#       1   4   *   *   *   bash /path/to/backup_mysql.sh
#
#   * Make sure 'crond' service is running, and will start automatically when
#     system startup:
#
#       # ---- On RHEL/CentOS ----
#       # chkconfig --level 345 crond on
#       # /etc/init.d/crond status
#
#       # ---- On Debian/Ubuntu ----
#       # update-rc.d cron defaults
#       # /etc/init.d/cron status
#

#########################################################
# Modify below variables to fit your need ----
#########################################################
# Where to store backup copies.
export BACKUP_ROOTDIR="/var/vmail/backup"
+ export BACKUP_ROOTDIR=/var/vmail/backup
+ BACKUP_ROOTDIR=/var/vmail/backup

# MySQL user and password.
export MYSQL_USER="xxx"
+ export MYSQL_USER=xxx
+ MYSQL_USER=xxx
export MYSQL_PASSWD="xxx"
+ export 'MYSQL_PASSWD=xxx'
+ MYSQL_PASSWD='xxx'

# Databases we should backup.
# Multiple databases MUST be seperated by SPACE.
# Your iRedMail server might have below databases:
# mysql, roundcubemail, policyd (or postfixpolicyd), amavisd, iredadmin
export DATABASES=" mysql mysql postfixpolicyd amavisd roundcubemail iredadmin"
+ export 'DATABASES= mysql mysql postfixpolicyd amavisd roundcubemail iredadmin'
+ DATABASES=' mysql mysql postfixpolicyd amavisd roundcubemail iredadmin'

# Database character set for ALL databases.
# Note: Currently, it doesn't support to specify character set for each databases.
export DB_CHARACTER_SET="utf8"
+ export DB_CHARACTER_SET=utf8
+ DB_CHARACTER_SET=utf8

# Compress plain SQL file: YES, NO.
export COMPRESS="YES"
+ export COMPRESS=YES
+ COMPRESS=YES

# Delete plain SQL files after compressed. Compressed copy will be remained.
export DELETE_PLAIN_SQL_FILE="YES"
+ export DELETE_PLAIN_SQL_FILE=YES
+ DELETE_PLAIN_SQL_FILE=YES

#########################################################
# You do *NOT* need to modify below lines.
#########################################################
export PATH='/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin'
+ export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin
+ PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin

# Commands.
export CMD_DATE='/bin/date'
+ export CMD_DATE=/bin/date
+ CMD_DATE=/bin/date
export CMD_DU='du -sh'
+ export 'CMD_DU=du -sh'
+ CMD_DU='du -sh'
export CMD_COMPRESS='bzip2 -9'
+ export 'CMD_COMPRESS=bzip2 -9'
+ CMD_COMPRESS='bzip2 -9'
export CMD_MYSQLDUMP='mysqldump'
+ export CMD_MYSQLDUMP=mysqldump
+ CMD_MYSQLDUMP=mysqldump
export CMD_MYSQL='mysql'
+ export CMD_MYSQL=mysql
+ CMD_MYSQL=mysql

# Date.
export YEAR="$(${CMD_DATE} +%Y)"
${CMD_DATE} +%Y)"
${CMD_DATE} +%Y)
${CMD_DATE} +%Y
++ /bin/date +%Y
+ export YEAR=2013
+ YEAR=2013
export MONTH="$(${CMD_DATE} +%m)"
${CMD_DATE} +%m)"
${CMD_DATE} +%m)
${CMD_DATE} +%m
++ /bin/date +%m
+ export MONTH=05
+ MONTH=05
export DAY="$(${CMD_DATE} +%d)"
${CMD_DATE} +%d)"
${CMD_DATE} +%d)
${CMD_DATE} +%d
++ /bin/date +%d
+ export DAY=22
+ DAY=22
export TIME="$(${CMD_DATE} +%H.%M.%S)"
${CMD_DATE} +%H.%M.%S)"
${CMD_DATE} +%H.%M.%S)
${CMD_DATE} +%H.%M.%S
++ /bin/date +%H.%M.%S
+ export TIME=12.53.23
+ TIME=12.53.23
export TIMESTAMP="${YEAR}.${MONTH}.${DAY}.${TIME}"
+ export TIMESTAMP=2013.05.22.12.53.23
+ TIMESTAMP=2013.05.22.12.53.23

# Pre-defined backup status
export BACKUP_SUCCESS='YES'
+ export BACKUP_SUCCESS=YES
+ BACKUP_SUCCESS=YES

# Define, check, create directories.
export BACKUP_DIR="${BACKUP_ROOTDIR}/mysql/${YEAR}/${MONTH}/${DAY}"
+ export BACKUP_DIR=/var/vmail/backup/mysql/2013/05/22
+ BACKUP_DIR=/var/vmail/backup/mysql/2013/05/22

# Log file
export LOGFILE="${BACKUP_DIR}/${TIMESTAMP}.log"
+ export LOGFILE=/var/vmail/backup/mysql/2013/05/22/2013.05.22.12.53.23.log
+ LOGFILE=/var/vmail/backup/mysql/2013/05/22/2013.05.22.12.53.23.log

# Check required variables.
if [ X"${MYSQL_USER}" == X"" -o X"${MYSQL_PASSWD}" == X"" -o X"${DATABASES}" == X"" ]; then
    echo "[ERROR] You don't have correct MySQL related configurations in file: ${0}" 1>&2
    echo -e "\t- MYSQL_USER\n\t- MYSQL_PASSWD\n\t- DATABASES" 1>&2
    echo "Please configure them first." 1>&2

    exit 255
fi
+ '[' Xxxx == X -o 'Xxxx' == X -o 'X mysql mysql postfixpolicyd amavisd roundcubemail iredadmin' == X ']'

# Verify MySQL connection.
${CMD_MYSQL} -u"${MYSQL_USER}" -p"${MYSQL_PASSWD}" -e "show databases" &>/dev/null
+ mysql -uxxx '-pxxx' -e 'show databases'
if [ X"$?" != X"0" ]; then
    echo "[ERROR] MySQL username or password is incorrect in file ${0}." 1>&2
    echo "Please fix them first." 1>&2

    exit 255
fi
+ '[' X7 '!=' X0 ']'
+ echo '[ERROR] MySQL username or password is incorrect in file /var/vmail/backup/backup_mysql.sh.'
[ERROR] MySQL username or password is incorrect in file /var/vmail/backup/backup_mysql.sh.
+ echo 'Please fix them first.'
Please fix them first.
+ exit 255

6

Re: Backup problem - wrong username or password

Here is the root cause, the command exist status code is not zero (successfully completed):

# Verify MySQL connection.
${CMD_MYSQL} -u"${MYSQL_USER}" -p"${MYSQL_PASSWD}" -e "show databases" &>/dev/null
+ mysql -uxxx '-pxxx' -e 'show databases'
...
+ '[' X7 '!=' X0 ']'

*) Does your MySQL password contain special characters? for example, &, single/double quote, etc?
*) Does a password with just english characters and digital number work for you?

7

Re: Backup problem - wrong username or password

ad 1, Yes, it does. I have some % and !
ad 2, How can i check it? If i change my password to MySQL it could mess up in other places

But the question is; why this start been a problem from couple of days and for the last 6 months works great?

All what can I think off is that couple days ago (i'm not really sure; before or after problems with backup) i add line to write MySQL logs in directory in my.cnf, but I didnt reboot server so changes still panding so it can't be it.

8

Re: Backup problem - wrong username or password

ag wrote:

ad 2, How can i check it? If i change my password to MySQL it could mess up in other places

MySQL root password is not used in other config files.

ag wrote:

All what can I think off is that couple days ago (i'm not really sure; before or after problems with backup) i add line to write MySQL logs in directory in my.cnf, but I didnt reboot server so changes still panding so it can't be it.

Can you compare current backup file with default one shipped in iRedMail? Show us the differences.

9 (edited by mike_theknife 2013-10-10 15:11:42)

Re: Backup problem - wrong username or password

ZhangHuangbin wrote:
ag wrote:

ad 2, How can i check it? If i change my password to MySQL it could mess up in other places

MySQL root password is not used in other config files.

ag wrote:

All what can I think off is that couple days ago (i'm not really sure; before or after problems with backup) i add line to write MySQL logs in directory in my.cnf, but I didnt reboot server so changes still panding so it can't be it.

Can you compare current backup file with default one shipped in iRedMail? Show us the differences.


Hello ZhangHuangbin,

==== Required information ====
- iRedMail version:0.8.5
- Store mail accounts in which backend (MySQL):MySQL
- Linux/BSD distribution name and version: Ubuntu 12.04 LTS
- Related log if you're reporting an issue:
======== Required information ====

I have the same Problem, the system was running fine for more than one month now and now i have the following error:

[ERROR] MySQL username or password is incorrect in file /var/vmail/backup/backup_mysql.sh

bash -xv /var/vmail/backup/backup_mysql.sh

.
.
.
# Verify MySQL connection.
${CMD_MYSQL} -u"${MYSQL_USER}" -p"${MYSQL_PASSWD}" -e "show databases" &>/dev/null
+ mysql -uroot -p******** -e 'show databases'
if [ X"$?" != X"0" ]; then
    echo "[ERROR] MySQL username or password is incorrect in file ${0}." 1>&2
    echo "Please fix them first." 1>&2

    exit 255
fi
+ '[' X1 '!=' X0 ']'
+ echo '[ERROR] MySQL username or password is incorrect in file /var/vmail/backup/backup_mysql.sh.'
[ERROR] MySQL username or password is incorrect in file /var/vmail/backup/backup_mysql.sh.
+ echo 'Please fix them first.'
Please fix them first.
+ exit 255

i can login just fine using "mysql - u root -p" and I also changed the password in mysql and in the backup script with no success. I have not altered the backup script except for the username and password.

root:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 57
Server version: 5.5.32-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| amavisd            |
| cluebringer        |
| iredadmin          |
| mysql              |
| performance_schema |
| roundcubemail      |
| test               |
| vmail              |
+--------------------+
9 rows in set (0.05 sec)

mysql>

Do you have any idea?

Greetings Mike

10

Re: Backup problem - wrong username or password

*) Does your password contain any special characters like '!'?
*) Does it work if you use password in shell directly? For example:

$ mysql -uroot -p"password" -e 'show databases'

11 (edited by mike_theknife 2013-10-12 15:08:12)

Re: Backup problem - wrong username or password

ZhangHuangbin wrote:

*) Does your password contain any special characters like '!'?
*) Does it work if you use password in shell directly? For example:

$ mysql -uroot -p"password" -e 'show databases'

Thank you for your fast reply!

mysql -uroot -p'***$$*' -e 'show databases' 

works when i use a ' instead of the " around the password. I guess its beacuse i have a $ sign in the password.

I replaced the $ sign to some normal ascci character, now I can manually call the script and it does the backup.

Strange for me is that it started acting up only recently. Everything was working for more than one month and suddenly this.

[edit]
I have just checked my backup Directory /var/vmail/backup/mysql/, and it is the first time that the backup ran. So backup never worked until now smile
[/edit]

Thanks again!

BTW: I had to reset the mysql root apssword completely using this guide:
https://help.ubuntu.com/community/MysqlPasswordReset

12

Re: Backup problem - wrong username or password

mike_theknife wrote:

works when i use a ' instead of the " around the password. I guess its beacuse i have a $ sign in the password.

It makes sense. $ is used for parameter substitution in shell. for example, $abc will be replaced by value of parameter "abc", if no value is assigned, it will be empty.

Improved iRedMail to detect '$' in password moment ago, hope it can help avoid similar issue:
https://bitbucket.org/zhb/iredmail/comm … b1c2f747d2

13

Re: Backup problem - wrong username or password

I have the same problem.  I guess changing the password is in order?