Bacula-users

Re: [Bacula-users] mysqldump not working due to missing password

2017-01-05 09:55:24
Subject: Re: [Bacula-users] mysqldump not working due to missing password
From: Martin Simmons <martin AT lispworks DOT com>
To: bacula-users AT lists.sourceforge DOT net
Date: Thu, 5 Jan 2017 14:54:25 GMT
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 <martin AT lispworks DOT com> 
> 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
> > Bacula-users AT lists.sourceforge DOT net
> > 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
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users

<Prev in Thread] Current Thread [Next in Thread>