fradelg/docker-mysql-cron-backup

"No database selected"

Closed this issue · 5 comments

Hi,

Since the commit 7e99a5d I'm getting this error from backup.sh:

mysqldump: Got error: 1046: "No database selected" when selecting the database

If I get into the container and remove the double quotes added on 7e99a5d, it works as before. Could it be because in my case $MYSQLDUMP_OPTS is empty?

I have tested the following options:

  • MYSQLDUMP_OPTS with several options and double quoted on the dump command. Not working
MYSQLDUMP_OPTS="--comments --compress"
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" --databases "$db" $"MYSQLDUMP_OPTS" > "$FILENAME"
  • MYSQLDUMP_OPTS with several options and not double quoted on the dump command. Working
MYSQLDUMP_OPTS="--comments --compress"
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" --databases "$db" $MYSQLDUMP_OPTS > "$FILENAME"

I think that maybe we should go for a not double quoted MYSQLDUMP_OPTS on the dump command. What do you think?

Can you try with the first double quote symbol before the $?

What happen if you move this variable just before the --databases $db?

Can you try with the first double quote symbol before the $?

I tried, same error

What happens if you move this variable just before the --databases $db?

Using...

MYSQLDUMP_OPTS="--compress --comments"
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQLDUMP_OPTS" --databases "$db" > "$FILENAME"

I get

mysqldump: unknown option '--compress --comments'

If I remove the double quotes and use MYSQLDUMP_OPTS=--compress --comments

I get

mysqldump: Got error: 1046: "No database selected" when selecting the database

With (note that I do not use double quotes around MYSQLDUMP_OPTS)

MYSQLDUMP_OPTS="--compress --comments"
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $MYSQLDUMP_OPTS --databases "$db" > "$FILENAME"

it works

Does it work for you with the double quotes?

I think that the problem is that the bash es not splitting the expression by its white spaces. Try using a single argument, like MYSQLDUMP_OPTS="--compress". If it works, use this snippet to retrieve a list of arguments between double quotes for MYSQLDUMP_OPTS:

MYSQLDUMP_OPTS_LIST=
for i in "${MYSQLDUMP_OPTS}"
do
        MYSQLDUMP_OPTS_LIST=${MYSQLDUMP_OPTS_LIST}\ "$i"
done
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQLDUMP_OPTS_LIST" --databases "$db" > "$FILENAME"

Then it should not matter if you double-quoted the arguments or not.

In my case, I do not use options for the backup, so my MYSQLDUMP_OPTS is empty, and it still fails when using

I've checked, and none of my containers have backed up the database with an empty MYSQLDUMP_OPTS variable, and it was working a few days ago.

I guess that if it fails in my case it will fail in other systems. Can you confirm it?