innobackupex command runs from command-line but not from bash script

I’ve got a bash script that I’ve created to run a backup using innobackupex/xtrabackup, but I’m having an issue actually executing the innobackupex command from the script.

Here is a simplied version of my script highlighting the issue (test.bash):


CMD="/usr/bin/innobackupex --user=username --password=password /var/backups/mysql/test &> /var/backups/mysql/test.log"

All this is doing is storing the command I want to execute to a variable and then executing it. In my actual script, the command is constructed from other options and settings, but even this simple script fails. The command itself is running the backup, and storing the output in test.log, and running the command in the background

When I try to run this script (e.g., bash test.bash), I get the error:
innobackupex: Too many command line arguments

However, if I literally copy the command above and then paste into the console at a bash prompt, it runs fine.

Anyone have any idea what’s going on here?


Hi Travis,

you’re facing a bash syntax problem - here’s a turnaround by indicating the output separated from the innobackupex command itself:

CMD=“/usr/bin/innobackupex --user=username --password=password /var/backups/mysql/test”

$CMD &> /var/backups/mysql/test.log

That should do. Let us known, please.



Thanks Fernando, that did the trick!!