Open schmengler opened 2 years ago
Bug confirmed in v4.9.1
Found an issue in result of the piped command.
Example:
mysqldump --single-transaction --quick -h'db' -u'db' --password='db1' 'db' | LANG=C LC_CTYPE=C LC_ALL=C sed -E 's/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g' > 'db.sql' 2>&1
We have a special pipehandling for bash compatible shells included.
The check with getenv('SHELL')
is not working anymore.
Tried with Symfony/Process component. Seems that internally any shell_exec or proc_open with piped commands is executed in OS default shell.
On some system, like my ddev test environment based on Debian, the "bin/sh" is a link to "dash". Dash does not support set -o pipefail
which is currently needed to stop the pipe.
In our command line call the last command is a sed which always returns "0" status code.
I am still looking for a good solution.
@cmuench Spotted this and wonder if you have come across this before? http://cfajohnson.com/shell/cus-faq-2.html#Q11
Might be useful, may still produce a dump file but allow you to get the exit code somehow
@cmuench Spotted this and wonder if you have come across this before? http://cfajohnson.com/shell/cus-faq-2.html#Q11
Might be useful, may still produce a dump file but allow you to get the exit code somehow
I am thankful for every hint. Thought it's easy to fix but then I spent hours to try out possible solutions.
🙈 Maybe it's a case of doing it in multiple processes / steps?
mysqldump --single-transaction --quick -h'db' -u'db' --password='db1' 'db' > db.sql.tmp
# if exit code !=0 delete db.sql.tmp and exit 1
LANG=C LC_CTYPE=C LC_ALL=C sed -i -E 's/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g' db.sql.tmp
# if exit code !=0 delete db.sql.tmp and exit 1
mv db.sql.tmp db.sql
# exit 0
It's probably more convoluted PHP code though
see_no_evil Maybe it's a case of doing it in multiple processes / steps?
mysqldump --single-transaction --quick -h'db' -u'db' --password='db1' 'db' > db.sql.tmp # if exit code !=0 delete db.sql.tmp and exit 1 LANG=C LC_CTYPE=C LC_ALL=C sed -i -E 's/DEFINER[ ]*=[ ]*`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g' db.sql.tmp # if exit code !=0 delete db.sql.tmp and exit 1 mv db.sql.tmp db.sql # exit 0
It's probably more convoluted PHP code though
I agree. This command btw. needs some refactoring.
Describe the bug
When running the
db:dump
command and mysqldump fails, magerun will still return with an exit code of 0.Expected behaviour
Non-zero exit code on error
Steps to reproduce the issue
magerun db:dump
mysqldump: Got error: 2005: "Unknown MySQL server host ''bielefeld'' (-2)" when trying to connect
echo $?
Technical details
Possible Fix
In script, I currently work around the issue with
$(magerun db:dump --only-command)
(together withset -e -o pipefail
)Additional context
This is important for scripting, e.g. database backup as part of the deployment pipeline. If a backup fails, the pipeline should not continue.