mysqldump not working due to missing password

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

mysqldump not working due to missing password

Stefan Kiehne
Hi guys,

I have a ClientRunBeforeJob directive that makes a dump of each database (using mysqldump) before the backup.

ClientRunBeforeJob = "sh -c 'databases=`mysql -u root -e \"SHOW DATABASES;\" | grep -Ev \"(Database|information_schema|performance_schema)\"`; rm -f /var/spool/bacula/*.sql && for db in $databases; do mysqldump --defaults-extra-file=/var/spool/bacula/.my.cnf --opt --events --databases $db > /var/spool/bacula/$db.sql; done && unset databases'"

I added the option --defaults-extra-file=/root/.my.cnf because it neede a password but since the bacula user couldn't read the file in that directory it failed. So I moved the file to /var/spool/bacula/.my.cnf and changed the ClientRunBeforeJob accordingly. Just checked and it still didn't work (ClientRunBeforeJob: ERROR 1045 (28000): Access denied for user 'x'@'y' (using password: NO). I can log in to mysql as bacula with no problem (using 'sudo -u bacula mysql') So what am I missing here?

Also when it fails, the job still continues without error which is why I hadn't caught this problem before.

Hope you can help me figure this one out
Regards Stefan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Bacula-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/bacula-users
Reply | Threaded
Open this post in threaded view
|

Re: mysqldump not working due to missing password

Martin Simmons
>>>>> On Thu, 5 Jan 2017 08:47:08 +0100, Stefan Kiehne said:
>
> Hi guys,
>
> I have a ClientRunBeforeJob directive that makes a dump of each database
> (using mysqldump) before the backup.
>
> ClientRunBeforeJob = "sh -c 'databases=`mysql -u root -e \"SHOW DATABASES;\" | grep -Ev \"(Database|information_schema|performance_schema)\"`; rm -f /var/spool/bacula/*.sql && for db in $databases; do mysqldump --defaults-extra-file=/var/spool/bacula/.my.cnf --opt --events --databases $db > /var/spool/bacula/$db.sql; done && unset databases'"
>
> I added the option --defaults-extra-file=/root/.my.cnf because it neede a
> password but since the bacula user couldn't read the file in that directory
> it failed. So I moved the file to /var/spool/bacula/.my.cnf and changed the
> ClientRunBeforeJob accordingly. Just checked and it still didn't work
> (ClientRunBeforeJob: ERROR 1045 (28000): Access denied for user 'x'@'y'
> (using password: NO). I can log in to mysql as bacula with no problem
> (using 'sudo -u bacula mysql') So what am I missing here?

Is the "ERROR 1045" coming from `mysql ...` or from mysqldump?

I suspect confusion about users and defaults from your description.

1. The ClientRunBeforeJob runs in the bacula-fd.  Are you really running
that as the bacula user?  Normally it runs as root.

2. You are passing '-u root' to mysql so this is not connecting as the
bacula user and might be different from your tests with 'sudo -u bacula
mysql'.

3. You are not passing --defaults-extra-file to mysql (only to mysqldump).

4. You are not passing '-u root' to mysqldump, so the user will either be
specified in /var/spool/bacula/.my.cnf or defaulted to the user running the
command (probably root in the ClientRunBeforeJob).

__Martin

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Bacula-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/bacula-users
Reply | Threaded
Open this post in threaded view
|

Re: mysqldump not working due to missing password

Stefan Kiehne
You're right I messed up missing to pass the --defaults-extra-file in the mysql command and thus it would fail trying to get the list of databases. Messed around in a VM an got to the same conslusion. I changed the config now I'll see tomorrow how it went. Thanks for the tips. 

Still is there a way to have the Job fail on an error like that?

Stefan

On Thu, Jan 5, 2017 at 1:33 PM, Martin Simmons <[hidden email]> wrote:
>>>>> On Thu, 5 Jan 2017 08:47:08 +0100, Stefan Kiehne said:
>
> Hi guys,
>
> I have a ClientRunBeforeJob directive that makes a dump of each database
> (using mysqldump) before the backup.
>
> ClientRunBeforeJob = "sh -c 'databases=`mysql -u root -e \"SHOW DATABASES;\" | grep -Ev \"(Database|information_schema|performance_schema)\"`; rm -f /var/spool/bacula/*.sql && for db in $databases; do mysqldump --defaults-extra-file=/var/spool/bacula/.my.cnf --opt --events --databases $db > /var/spool/bacula/$db.sql; done && unset databases'"
>
> I added the option --defaults-extra-file=/root/.my.cnf because it neede a
> password but since the bacula user couldn't read the file in that directory
> it failed. So I moved the file to /var/spool/bacula/.my.cnf and changed the
> ClientRunBeforeJob accordingly. Just checked and it still didn't work
> (ClientRunBeforeJob: ERROR 1045 (28000): Access denied for user 'x'@'y'
> (using password: NO). I can log in to mysql as bacula with no problem
> (using 'sudo -u bacula mysql') So what am I missing here?

Is the "ERROR 1045" coming from `mysql ...` or from mysqldump?

I suspect confusion about users and defaults from your description.

1. The ClientRunBeforeJob runs in the bacula-fd.  Are you really running
that as the bacula user?  Normally it runs as root.

2. You are passing '-u root' to mysql so this is not connecting as the
bacula user and might be different from your tests with 'sudo -u bacula
mysql'.

3. You are not passing --defaults-extra-file to mysql (only to mysqldump).

4. You are not passing '-u root' to mysqldump, so the user will either be
specified in /var/spool/bacula/.my.cnf or defaulted to the user running the
command (probably root in the ClientRunBeforeJob).

__Martin

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Bacula-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/bacula-users


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Bacula-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/bacula-users
Reply | Threaded
Open this post in threaded view
|

Re: mysqldump not working due to missing password

Martin Simmons
I think the job will fail if the script returns a non zero exit status.  The
problem is that shell backquote doesn't return an exit status, but you could
do something like

if test -z "$databases"; then exit 1; else for db ... done; fi

__Martin

>>>>> On Thu, 5 Jan 2017 13:55:41 +0100, Stefan Kiehne said:
>
> You're right I messed up missing to pass the --defaults-extra-file in the
> mysql command and thus it would fail trying to get the list of databases.
> Messed around in a VM an got to the same conslusion. I changed the config
> now I'll see tomorrow how it went. Thanks for the tips.
>
> Still is there a way to have the Job fail on an error like that?
>
> Stefan
>
> On Thu, Jan 5, 2017 at 1:33 PM, Martin Simmons <[hidden email]> wrote:
>
> > >>>>> On Thu, 5 Jan 2017 08:47:08 +0100, Stefan Kiehne said:
> > >
> > > Hi guys,
> > >
> > > I have a ClientRunBeforeJob directive that makes a dump of each database
> > > (using mysqldump) before the backup.
> > >
> > > ClientRunBeforeJob = "sh -c 'databases=`mysql -u root -e \"SHOW
> > DATABASES;\" | grep -Ev \"(Database|information_schema|performance_schema)\"`;
> > rm -f /var/spool/bacula/*.sql && for db in $databases; do mysqldump
> > --defaults-extra-file=/var/spool/bacula/.my.cnf --opt --events
> > --databases $db > /var/spool/bacula/$db.sql; done && unset databases'"
> > >
> > > I added the option --defaults-extra-file=/root/.my.cnf because it neede
> > a
> > > password but since the bacula user couldn't read the file in that
> > directory
> > > it failed. So I moved the file to /var/spool/bacula/.my.cnf and changed
> > the
> > > ClientRunBeforeJob accordingly. Just checked and it still didn't work
> > > (ClientRunBeforeJob: ERROR 1045 (28000): Access denied for user 'x'@'y'
> > > (using password: NO). I can log in to mysql as bacula with no problem
> > > (using 'sudo -u bacula mysql') So what am I missing here?
> >
> > Is the "ERROR 1045" coming from `mysql ...` or from mysqldump?
> >
> > I suspect confusion about users and defaults from your description.
> >
> > 1. The ClientRunBeforeJob runs in the bacula-fd.  Are you really running
> > that as the bacula user?  Normally it runs as root.
> >
> > 2. You are passing '-u root' to mysql so this is not connecting as the
> > bacula user and might be different from your tests with 'sudo -u bacula
> > mysql'.
> >
> > 3. You are not passing --defaults-extra-file to mysql (only to mysqldump).
> >
> > 4. You are not passing '-u root' to mysqldump, so the user will either be
> > specified in /var/spool/bacula/.my.cnf or defaulted to the user running the
> > command (probably root in the ClientRunBeforeJob).
> >
> > __Martin
> >
> > ------------------------------------------------------------
> > ------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> > _______________________________________________
> > Bacula-users mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/bacula-users
> >

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Bacula-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/bacula-users