Download & Extend

some commands (like sql-sync) wont respect ssh-options/ssh-port of sitealias

Project:Drush
Version:All-versions-5.x-dev
Component:PM (dl, en, up ...)
Category:bug report
Priority:critical
Assigned:greg.1.anderson
Status:closed (fixed)

Issue Summary

My apologies if this is a duplicate. I searched in the queue and have spent a couple hours trying to debug.

In short, I am trying to do an sql-sync from a production server to a development server, via the development server. Both have non-standard ports.

Here is the verbose, debug sql-sync output:

[/data/sites/dev.site.org] $ drush --debug sql-sync @prod @dev
Found command: sql-sync (commandfile=sql) [0.07 sec, 3.86 MB]      [bootstrap]
Including /data/drush/commands/sql/sync.sql.inc [0.07 sec, 3.86 MB]        [bootstrap]
Load alias @dev [0.07 sec, 4.04 MB]         [notice]
Load alias @prod [0.07 sec, 4.05 MB]        [notice]
Running: ssh -o PasswordAuthentication=no 'alan'@'site.org' 'drush  --all --ssh-options='\''-p 8888'\'' --root='\''/data/sites/site.org'\''                [command]
--uri='\''site.org'\'' sql-conf --backend' [0.08 sec, 4.06 MB]
Undefined offset:  1 backend.inc:112 [0.11 sec, 4.07 MB]   [notice]
Undefined variable: output backend.inc:119 [0.11 sec, 4.08 MB]      [notice]
                                              [error]ned: ssh: connect to host site.org port 22: Connection refused
, code: 255) [0.11 sec, 4.08 MB]
Running: /usr/bin/php /data/drush/drush.php --php=/usr/bin/php  --all --root='/data/sites/dev.site.org' --uri='dev.site.org' sql-conf --backend [0.11      [command]
sec, 4.08 MB]
Error: no database record could be found for @prod [0.5 sec, 4.1 MB]    [error]
An error occurred at function : drush_sql_sync [0.5 sec, 4.1 MB]    [error]
Command dispatch complete [0.5 sec, 4.1 MB]     [notice]
Peak memory usage was 4.11 MB [0.5 sec, 4.1 MB]

Here is my alias file:

<?php
/**
* @file
* Drush Aliases for Alan
*/

// QA
$aliases['qa'] = array(
 
'uri' => 'qa.site.org',
 
'root' => '/data/sites/qa.site.org',
);

// Dev
$aliases['dev'] = array(
 
'uri' => 'dev.site.org',
 
'root' => '/data/sites/dev.site.org',
);

// Production
$aliases['prod'] = array(
 
'uri' => 'site.org',
 
'root' => '/data/sites/site.org',
 
'remote-host' => 'site.org',
 
'remote-user' => 'alan',
 
'ssh-options' => '-p 8888',
);
?>

And finally here is my drushrc.php file:

<?php
// $Id$

/**
* @file
* Drush settings for Alan
*/

// General Drush settings
// Turn on verbose
$options['v'] = 1;
?>

From doing some debugging, and looking at the debug output. The port is not being specified on the ssh command to get the database settings. Though, this is confusing because sql-conf works fine.

[/data/sites/dev.site.org] $ drush --debug @prod sql-conf
Begin redispatch via backend invoke [0.08 sec, 3.97 MB]    [notice]
Running: ssh -p 8888 'alan'@'site.org' 'drush  --ssh-options='\''-p 8888'\'' --debug --uri='\''site.org'\'' --root='\''/data/sites/site.org'\''   [command]
sql-conf --backend' [0.08 sec, 3.98 MB]
Drush bootstrap phase : _drush_bootstrap_drush() [0.47 sec, 3.98 MB]  [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.47 sec, 3.99 MB]  [bootstrap]
Initialized Drupal 5.22 root directory at /data/sites/site.org [0.47 sec, 3.99 MB]  [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.47 sec, 3.99 MB] [bootstrap]
Initialized Drupal site site.org at sites/default [0.47 sec, 3.99 MB]   [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [0.47 sec, 3.99 MB]   [bootstrap]
Found command: sql-conf (commandfile=sql) [0.47 sec, 3.99 MB]  [bootstrap]
Command dispatch complete [0.47 sec, 3.99 MB]         [notice]
Peak memory usage was 5.95 MB [0.47 sec, 3.99 MB]     [memory]
Array
(
    [driver] => mysql
    [username] => site
    [port] =>
    [host] => localhost
    [database] => sitedb
)
Backend invoke is complete [0.47 sec, 3.98 MB] 

Any help would be much appreciated. Thanks for all the hard work and great module.

Comments

#1

Assigned to:Anonymous» greg.1.anderson

#2

Priority:normal» critical

confirming this with 3.1

#3

Priority:critical» normal

tracked this down in the source and it seems to me that the crucial code is in

backend.inc:339ff (as of 3.1)

function _drush_backend_generate_command($command, $args, &$data, $method = 'GET', $drush_path = null, $hostname = null, $username = null)

this gets hostname and username as arguments but NOT port (which is part of ssh-options *for the site*)

later on in line 363 we have

$ssh_options = drush_get_option('ssh-options', "-o PasswordAuthentication=no");

which seems to get ssh-options from commandline and NOT from sitealias.

#4

above analysis is supported by following observation:
adding my nonstandard port like "drush -d --ssh-options=1234sql-sync @here @there"
results in an ssh invocation with the right port.

this might be a WORKAROUND for some people
(alas in my case i get "returned: bash: drush: command not found" which surely is a separate issue (my remote drush path settings do work with "drush @there status").

#5

Title:sql-sync with remote host and non-standard ports does not get database settings» some commands (lime sql-sync) wont respect ssh-options/ssh-port of sitealias
Category:support request» bug report
Priority:normal» critical

i just might help fix this, but i think any proper fix is likely to change signature of _drush_backend_generate_command() : we need to not only pass hostname and user, but maybe a "connection" record with hostname, user, port.
which in turn suggests to have ssh_port in setting explicitly (not in ssh_options="-p 1234"), imho.

this seems to affect not only sql-sync and make some commands kind of unusable with nonstandard port.
so changing title / category and raising prio - feel free to correct me.

#6

as a memo the caller chain of above function:
* drush_sql_sync
* _drush_sql_sync
* sitealias_get_databases_from_record
* drush_sitealias_add_db_settings
* drush_do_site_command($alias_record, "sql-conf", array(), array('all' => TRUE))
* drush_backend_invoke_args($command, $args, $data, 'GET', $integrate, $drush_path, array_key_exists('remote-host', $site_record) ? $site_record['remote-host'] : NULL, array_key_exists('remote-user', $site_record) ? $site_record['remote-user'] : NULL);
* _drush_backend_generate_command($command, $args, $data, $method, $drush_path, $hostname, $username);

#7

one more finding: we might also need a change like this:
@@ -1500,7 +1500,7 @@ function drush_sitealias_evaluate_path($path, &$additional_options) {

/**
* Option keys used for site selection.
*/
function drush_sitealias_site_selection_keys() {
- return array('remote-host', 'remote-user', 'name');
+ return array('remote-host', 'remote-user', 'ssh-options', 'name');
}

#8

and last notice for today:
the workaround of #4 DOES work for me now:
"drush -d --ssh-options=1234 sql-sync @here @there"

#9

Status:active» needs review

Try this. Regarding #5, the signature of _drush_backend_generate_command is not changed due to the use of a default value for the new parameter.

AttachmentSize
820514-ssh-options.patch 4.25 KB

#10

Hey @greg.1.anderson, thanks for the patch. I have tested this out and it works for me. I'll let someone else double check it before I mark as reviewed.

#11

Thanks, patch seems to fix the issue for me too.

#12

Status:needs review» reviewed & tested by the community

#13

Title:some commands (lime sql-sync) wont respect ssh-options/ssh-port of sitealias» some commands (like sql-sync) wont respect ssh-options/ssh-port of sitealias
Status:reviewed & tested by the community» patch (to be ported)

Committed. Could go in 3.x too.

#14

Status:patch (to be ported)» fixed

Will roll a release soon. Committing critical backports.

#15

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#18

Component:Code» PM (dl, en, up ...)

yes, patch seems to fix the issue for me too...thank you
طراحی وب سایت

nobody click here