Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote drush commands not exporting to file using > #4004

Closed
omarlopesino opened this issue Mar 20, 2019 · 18 comments
Closed

Remote drush commands not exporting to file using > #4004

omarlopesino opened this issue Mar 20, 2019 · 18 comments

Comments

@omarlopesino
Copy link

omarlopesino commented Mar 20, 2019

Describe the bug
After upgrading from drush 9.5.2 to drush 9.6.0 the drush sql-dump command does not dump the output to a file, running the command from the

To Reproduce
What did you do?

drush @remote.stg sql:dump > tmp/db.sql

Expected behavior
The file tmp/db.sql should have all the database dumped.

Actual behavior
The file tmp/db.sql is empty.

Workaround
Is there another way to do the desired action?
Make the action in two steps:

drush @remote.stg sql-dump --target-file=<targetfile>
drush rsync @remote.stg:<targetfile> tmp/db.sql

System Configuration

Q A
Drush version? 9.6.0
Drupal version? 8.6.12
PHP version 7.1.17-
OS? Ubuntu 17.10

Remote environment os:
Linux **** 3.16.0-5-amd64 #1 SMP Debian 3.16.51-3+deb8u1 (2018-01-08) x86_64 GNU/Linux

Drush alias

stg:
  uri: 'host.domain'
  root: '/path/to/codebase'
  host: 'host.domain'
  user: 'remote-user'
  command:
    sql:
      sync:
        options:
          structure-tables-list: 'cache*,session,watchdog'
    dump:
      sync:
        options:
          structure-tables-list: 'cache*,session,watchdog'
@greg-1-anderson
Copy link
Member

greg-1-anderson commented Mar 25, 2019

Just tried it on HEAD of master, and it worked fine for me.

What's in your alias file? Are both the local and remote OS Ubuntu 17.10?

Try running drush -s @remote.stg sql:dump and inspect the ssh command that Drush prints. Try running the ssh command directly from your shell, and see if it works correctly.

Also try drush @remote.stg status and make sure that you can connect to the database.

@omarlopesino
Copy link
Author

I tried from master HEAD and it didn't work neither.

I added drush alias and remote environment OS at description.

Drush status also works. Furthermore, the drush -s @remote.stg sql:dump > tmp/db.sql does not throwed any error but the file is stil empty , when it should have the simulation result. Seems is not a problem with drush sql-dump , but with drush. What could be happening?

@greg-1-anderson
Copy link
Member

Try:

  • drush -d @remote.stg sql:dump
  • drush -s @remote.stg sql:dump
  • drush @remote.stg version > tmp/version.txt

@omarlopesino
Copy link
Author

omarlopesino commented Mar 26, 2019

drush -d @Remote.stg sql:dump:

 [info] Executing: ssh -o PasswordAuthentication=no remote-stg@remote-stg.remote.pro 'drush -vvv --quiet sql:dump --uri=remote-stg.remote.pro --root=/path/to/codebase' [0.06 sec, 10.26 MB]
>  [preflight] Config paths: /path/to/codebase/vendor/drush/drush/drush.yml,/path/to/codebase/drush/drush.yml
>  [preflight] Alias paths: /path/to/codebase/web/drush/sites,/path/to/codebase/drush/sites
>  [preflight] Commandfile search paths: /path/to/codebase/vendor/drush/drush/src,/path/to/codebase/drush
>  [bootstrap] Starting bootstrap to max [0.12 sec, 8.87 MB]
>  [bootstrap] Drush bootstrap phase: bootstrapDrupalRoot() [0.13 sec, 8.87 MB]
>  [bootstrap] Change working directory to /path/to/codebase/web [0.13 sec, 8.87 MB]
>  [bootstrap] Initialized Drupal 8.6.13 root directory at /path/to/codebase/web [0.13 sec, 9.03 MB]
>  [bootstrap] Drush bootstrap phase: bootstrapDrupalSite() [0.13 sec, 9.44 MB]
>  [bootstrap] Initialized Drupal site remote-stg.remote.pro at sites/default [0.13 sec, 9.66 MB]
>  [bootstrap] Drush bootstrap phase: bootstrapDrupalConfiguration() [0.13 sec, 9.66 MB]
>  [debug] Add service modifier [0.14 sec, 9.92 MB]
>  [info] Executing: command -v mysql [0.14 sec, 10.48 MB]
>  [info] sql:query: SHOW TABLES; [0.18 sec, 10.54 MB]
>  [info] Executing: mysql --defaults-file=/tmp/drush_aktXcP --database=remote_stg --host=localhost --silent -A < /tmp/drush_gRhgv9 [0.18 sec, 10.55 MB]
>  [info] Executing: mysqldump --defaults-file=/tmp/drush_iecmWu  remote_stg --host=localhost --no-autocommit --single-transaction --opt -Q  [0.19 sec, 10.57 MB]

drush -s @Remote.stg sql:dump:

./vendor/drush/drush -s @remote.stg sql:dump 
 [notice] Simulating: ssh -t -o PasswordAuthentication=no remoteweb-stg@remote-stg.remote.pro 'drush sql:dump --uri=remote-stg.remote.pro --root=/path/to/codebases/remoteweb-stg/codebase'
[26 20:41] omar@helm:~/docker/web (dev) $ drush @remote.stg version > tmp/version.txt
 Drush version : 9.6.0 
Connection to remote-stg.remote.pro closed.

The last command doesn't dumps the output to the file.

[26 20:43] omar@helm:~/docker/web (dev) $ cat tmp/version.txt 
[26 20:43] omar@helm:~/docker/web (dev) $ 

@omarlopesino omarlopesino changed the title Drush sql-dump not exporting to file using > Remote drush commands not exporting to file using > Mar 26, 2019
@greg-1-anderson
Copy link
Member

OK, pretty strange results.

Copy the whole ssh line (ssh -t -o PasswordAuthentication=no remoteweb-...) and run it in your terminal. Is an sql dump produced?

Run drush @remote.stg version 2> tmp/version.txt. Do you get any output in tmp/version.txt?

@weitzman
Copy link
Member

weitzman commented Mar 31, 2019

I get similar as OP. Stdout is dumped to screen, not redirected to tmp.txt. I test with st command below because its ouput is small.

root@mass:/var/www/mass.local# drush -v @cd st > tmp.txt
 [info] Executing: ssh -t -o ForwardAgent=yes massgov.cd@massgovcd.ssh.prod.acquia-sites.com 'drush -v st --uri=massgovcd.prod.acquia-sites.com --root=/var/www/html/massgov.cd/docroot'
 Drupal version   : 8.6.10                                               
 Site URI         : http://massgovcd.prod.acquia-sites.com               
 DB driver        : mysql                                                
 DB hostname      : staging-21435                                        
 DB port          : 3306                                                 
 DB username      : s27893                                               
 DB name          : massgovcd                                            
 Database         : Connected                                            
 Drupal bootstrap : Successful                                           
 Default theme    : mass_theme                                           
 Admin theme      : mass_admin_theme                                     
 PHP binary       : /usr/local/php7.1/bin/php                            
 PHP config       : /usr/local/php7.1/etc/cli/php.ini                    
 PHP OS           : Linux                                                
 Drush script     : /mnt/www/html/massgovcd/vendor/drush/drush/drush     
 Drush version    : 9.6.0-dev                                            
 Drush temp       : /mnt/tmp/massgovcd                                   
 Drush configs    : /etc/drush/drush.yml                                 
                    /mnt/www/html/massgovcd/vendor/drush/drush/drush.yml 
                    /mnt/www/html/massgovcd/drush/drush.yml              
 Install profile  : standard                                             
 Drupal root      : /mnt/www/html/massgovcd/docroot                      
 Site path        : sites/default                                        
 Files, Public    : files                                                
 Files, Private   : /mnt/files/massgov.cd/files-private                  
 Files, Temp      : /mnt/gfs/massgov.cd/tmp                              
Connection to massgovcd.ssh.prod.acquia-sites.com closed.
root@mass:/var/www/mass.local# more tmp.txt 
root@mass:/var/www/mass.local# 

I also tried drush @cd version 2> tmp/version.txt and the number outputs on screen and is not written to tmp/version.txt. that file is empty.

@greg-1-anderson
Copy link
Member

The problem is that Drush is setting tty mode even though output is redirected. This is wrong.

Workaround:

drush -Dssh.tty=0 @cd version 2> tmp/version.txt

Should have a fix shortly.

@Sutharsan
Copy link
Contributor

For anyone coming across this issue. I had a similar problem with Drush 9.7.0 where sql:dump output was sent to standard output instead of a file. Based on the above workaround, I fixed it with the 'ssh' option in the drush alias of the remote site:

remote:
  ssh:
    tty: 0

@greg-1-anderson
Copy link
Member

Probably related to #4092

@iainhouston
Copy link

#4004 (comment) solved the same issue I encountered with drush 9.7.1

@geek-merlin
Copy link
Contributor

I'm also facing this issue and use the workaround from said comment.

tbfisher added a commit to tbfisher/ldev that referenced this issue Dec 6, 2019
# Conflicts:
#	scripts/pull
tbfisher added a commit to tbfisher/ldev that referenced this issue Dec 6, 2019
# Conflicts:
#	scripts/pull

# Conflicts:
#	scripts/pull
tbfisher added a commit to tbfisher/ldev that referenced this issue Dec 6, 2019
# Conflicts:
#	scripts/pull

# Conflicts:
#	scripts/pull
tbfisher added a commit to tbfisher/ldev that referenced this issue Dec 6, 2019
# Conflicts:
#	scripts/pull

# Conflicts:
#	scripts/pull
@hussainweb
Copy link
Contributor

I had the same problem and the comment above (#4004 (comment)) helped me. But it was not immediately obvious that remote is not a configuration option but the name of your alias. I was about to give up thinking it was an option in an older version of Drush. In case it helps someone.

stage:
  host: ...
  user: ...
  root: ...
  uri: ...
  ssh:
    tty: 0

@rudolfbyker
Copy link

This still happens on Drush 9.7.2 and Drush 10.2.2, even with simple commands like drush @remote-alias status --field=db-name. The tty:0 workaround above fixes it.

Command output without workaround:

db_name
Connection to example.com closed.

... and shell redirection doesn't work.

Command output with workaround:

db_name

... and shell redirection works.

@johnpitcairn
Copy link

Still seeing this in Drush 10.3.2, FWIW. Setting ssh: tty: 0 for the remote alias works.

@vishnumoorthy
Copy link

I had the same problem and the comment above (#4004 (comment)) helped me. But it was not immediately obvious that remote is not a configuration option but the name of your alias. I was about to give up thinking it was an option in an older version of Drush. In case it helps someone.

stage:
  host: ...
  user: ...
  root: ...
  uri: ...
  ssh:
    tty: 0

@hussainweb

Thanks for your comment. I try to add the tty in the remote configuration but still i am facing this issue. I am using drush 9.7.2.

This my remote config:
test:
uri:
host:
options: { }
paths:
root:
user:
ssh: { options: '-p 22' , tty: False }

@joelpittet
Copy link
Contributor

We are using the alias workaround above but realizing that drush @self.stg sql:cli doesn't work with

stg:
  host: ...
  user: ...
  root: ...
  uri: ...
  ssh:
    tty: 0

@gconry-openbox
Copy link

This seems to still be an active issue. We can't just blanket use tty: 0 because that breaks commands that require interactivity such as drush cim. Any other options?

@tormi
Copy link

tormi commented Jul 13, 2023

It seems to be resolved in Drush version : 12.1.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests