Hi,

indeed it's simple, it's just not yet well documented. This looks like 
referring to
http://doc.bareos.org/master/html/bareos-manual-main-reference.html#x1-405000G.2.3

It does not work because every external program is run through execv(p) so a 
shell
construct won't work. The mysqldump binary itself does not know what to do with 
">"
as an argument.

To get that working, it must be run through a shell like this:

ClientRunBeforeJob = "sh -c 'mysqldump --user=root --opt --all-databases > 
/var/lib/bareos/mysql_dump.sql'"

Note that RunBeforeJob runs the command on the director as user bareos,
while for backing up MySQL it's usually intended to be run by filedaemon
on the server being backed up. There, as filedaemon runs as root, the
script is also run as root.

The second table in the section on Run Script directive explains
the differences of the shortcuts, see
http://doc.bareos.org/master/html/bareos-manual-main-reference.html#directiveDirJobRun%20Script

"In addition, the command string is parsed then fed to the OS, which means that 
the path
will be searched to execute your specified command, but there is no shell 
interpretation,
as a consequence, if you invoke complicated commands or want any shell features 
such as
redirection or piping, you must call a shell script and do it inside that 
script."

So another option is to create a shell script, for example
/usr/local/sbin/bareos_mysql_dump.sh with the content

#!/bin/sh
mysqldump --user=root --opt --all-databases > /var/lib/bareos/mysql_dump.sql

and in director configuration use

ClientRunBeforeJob = "/usr/local/sbin/bareos_mysql_dump.sh"

Using the RunScript syntax is also a good idea, as the behavior is
better understandable without knowing the meaning of the shortcuts,
the equivalent to

  ClientRunBeforeJob = "sh -c 'mysqldump --user=root --opt --all-databases > 
/var/lib/bareos/mysql_dump.sql'"

would be

  RunScript {
    FailJobOnError = Yes
    RunsOnClient = Yes
    RunsWhen = Before
    Command = "sh -c 'mysqldump --user=root --opt --all-databases > 
/var/lib/bareos/mysql_dump.sql'"
  }

and the equivalent for

  ClientRunAfterJob = "rm /var/lib/bareos/mysql_dump.sql"

would be

  RunScript {
    RunsOnSuccess = Yes
    RunsOnClient = Yes
    RunsWhen = After
    Command = "rm /var/lib/bareos/mysql_dump.sql"
  }

Note: as no redirection is involved, no need to use sh -c for the rm command.

The example at 
http://doc.bareos.org/master/html/bareos-manual-main-reference.html#x1-404000G.2.3
will probably be changed to the following:

Job {
  Name = "BackupDatabase"
  JobDefs = "DefaultJob"
  Level = Full
  FileSet="Database"

  # This creates a dump of our database in the local filesystem
  RunScript {
    FailJobOnError = Yes
    RunsOnClient = Yes
    RunsWhen = Before
    Command = "sh -c 'mysqldump --user=<username> --password=<password> --opt 
--all-databases > /var/lib/bareos/mysql_dump.sql'"
  }

  # This deletes the dump in our local filesystem
  RunScript {
    RunsOnSuccess = Yes
    RunsOnClient = Yes
    RunsWhen = After
    Command = "rm /var/lib/bareos/mysql_dump.sql"
  }
}

The documention already mentions in most of the places where it's applicable
that sh -c must be used to be able to use shell features.

Regards

Stephan

On 02/25/2015 06:46 AM, Christian Tardif wrote:
> Hi,
>  
> This one should be simple, but it does not work.  I'm trying to create a 
> MySQL backup using RunBeforeJob and RunAfterJob. The report gives me that:
>  
> 25-Feb 00:17 zeus-dir JobId 159: shell command: run BeforeJob "mysqldump 
> --user=root --opt --all-databases > /var/lib/bareos/mysql_dump.sql"
> 25-Feb 00:17 zeus-dir JobId 159: BeforeJob: Usage: mysqldump [OPTIONS] 
> database [tables]
> 25-Feb 00:17 zeus-dir JobId 159: BeforeJob: OR mysqldump [OPTIONS] 
> --databases [OPTIONS] DB1 [DB2 DB3...]
> 25-Feb 00:17 zeus-dir JobId 159: BeforeJob: OR mysqldump [OPTIONS] 
> --all-databases [OPTIONS]
>  
> If I run the command manually, obviously, it works. The command syntax is 
> perfect (no password for root is yet set, so it does not appear on the 
> command line).  What's wrong with it within bareos ?
>  
> Thanks,
> 
> **
> 
> *
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *
> *
> Christian Tardif*
>  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "bareos-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout.


-- 
  Stephan Dühr                              [email protected]
  Bareos GmbH & Co. KG                      Phone: +49 221-630693-90
  http://www.bareos.com

  Sitz der Gesellschaft: Köln | Amtsgericht Köln: HRA 29646
  Komplementär: Bareos Verwaltungs-GmbH
  Geschäftsführer: S. Dühr, M. Außendorf,
  J. Steffens, Philipp Storz, M. v. Wieringen

-- 
You received this message because you are subscribed to the Google Groups 
"bareos-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to