drush icon indicating copy to clipboard operation
drush copied to clipboard

drush sql:dump shows output at the terminal even if output is redirected

Open deviantintegral opened this issue 4 years ago • 4 comments

Describe the bug

Running drush @site sql:dump --gzip > out.sql.gz shows output in the terminal instead of redirecting.

To Reproduce

  • This is being run within a ddev docker container
  • Create a site alias with a remote server to pull databases from
  • Run drush @site sql:dump --gzip > out.sql.gz

Expected behavior

I expected out.sql.gz to be created.

Actual behavior

My terminal exploded 💥

Workaround

Disabling the tty as shown at https://drupal.stackexchange.com/a/287855 works around this:

drush -Dssh.tty=0 @site.alias sql-dump > out.sql

System Configuration

Q A
Drush version? 10.6.0
Drupal version? 8.9
PHP version 7.4
OS? macOS / Docker for Mac

Additional information

I wonder if this is related to how ddev exec's into the container. I have memories of this happening when -t isn't used with docker exec, or perhaps that was with drush sqlc?

There's a previous PR fixing a similar issue at https://github.com/drush-ops/drush/pull/4028, and that code looks to survive in https://github.com/drush-ops/drush/blob/10.x/src/Runtime/RedispatchHook.php#L101-L105

deviantintegral avatar Aug 20 '21 18:08 deviantintegral

I'm running into this as well, the -Dssh.tty=0 workaround does the trick, the

alias:
  ssh: 
    tty: 0

yaml config breaks drush @site.alias sql:cli

Reading through some of the related issue and how they are solved, I'll loop in @danepowell and @greg-1-anderson but maybe like some of the input aware issues were fixed with implementations of StdinAwareInterface maybe the same could be done for output with OutputAwareInterface or a new StdoutAwareInterface just a shot in the dark.

And maybe even ./vendor/bin/drush @self.prod sql:dump --result-file=/tmp/${PWD##*/}.sql could be aware that the output should be on the host and not the remote /tmp directory.

joelpittet avatar Jul 05 '22 23:07 joelpittet

Another workaround is use the -n for non-interactive, it's shorter than -Dssh.tty=0

drush -n @site.alias sql-dump > out.sql

joelpittet avatar Jul 06 '22 18:07 joelpittet

Still an issue with Drush 11?

weitzman avatar Dec 14 '22 16:12 weitzman

Yes I believe so, working around it with the -n flag

joelpittet avatar Dec 15 '22 02:12 joelpittet