I used to be able to run 'drush sql-sync dev stage', but after the commit of http://drupal.org/node/683852 it produces the following error:
$ drush -d sql-sync dev stage
Found command: sql-sync (commandfile=sql) [0.17 sec, 3.77 MB] [bootstrap]
Including /usr/local/drush/commands/sql/sync.sql.inc [0.17 sec, 3.78 MB] [bootstrap]
Undefined index: uri [0.2 sec, 4.03 MB] [notice]
Undefined index: root [0.2 sec, 4.03 MB] [notice]
Error: could not get database spec when it was required for dev
Drush command could not be completed. [0.2 sec, 4.03 MB] [error]
At first I thought I should change my drushrc.php, but this does not help. I even removed all the '%' variables from there - I still get the same error. Here is the last part from drushrc.php:
$ tail -n22 sites/default/drushrc.php
$options['site-aliases']['stage'] = array(
'uri' => 'default',
'root' => '/home/yuval/work/example',
# 'db-url' => 'pgsql://username:password@dbhost.com:port/databasename',
'remote-host' => 'yhager',
# 'remote-user' => 'publisher',
# 'path-aliases' => array(
# '%drush' => '/drush/path/to/drush',
# '%drush-script' => '/drush/path/to/drush/drush',
# '%dump' => '/home/yuval/tmp/db.sql',
# '%files' => 'sites/mydrupalsite.com/files',
# '%custom' => '/my/custom/path',
# ),
);
$options['site-aliases']['dev'] = array(
'uri' => 'default',
'root' => '/home/yuval/work/example/www',
# 'path-aliases' => array(
# '%dump' => '/home/yuval/tmp/example.sql',
# ),
);
using drush before this commit does not generate this error (thanks git bisect!), and it is still present in latest drush.
I am not sure if this is a misconfig on my end, or a bug though..
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | drush-config-docs.patch | 2.77 KB | greg.1.anderson |
| #8 | drush-718354.patch | 1.53 KB | greg.1.anderson |
Comments
Comment #1
greg.1.anderson commentedMaybe you need to upgrade drush on your stage server? Drush gets the db spec from the remote site via:
drush stage sql-conf --allTry to run that from the command line, and see if it produces reasonable output. If you define 'db-url' in your site alias, then drush will not need to fetch it via backend_invoke.
Anyway, while I do not quite remember, I think I might have made some change to drush that required both ends to be running the same version. Give that a try, and let me know if that does not solve your problem.
Comment #2
greg.1.anderson commentedComment #3
yhager commentedI've set drush to be HEAD both on stage and dev.
Both
drush stage sql-conf --allanddrush dev sql-conf --allproduce what looks to me quite reasonable (I've sanitized it a bit):Comment #4
greg.1.anderson commentedWell, that is a head-scratcher. Make sure that you have #702554: Look up sitealias database settings only after a full database bootstrap, then run your sql-sync command again, this time with "-v -d" (verbose + debug), and post the result here.
Comment #5
moshe weitzman commentedfyi, -d implies -v. no advantage to sending them both.
Comment #6
yhager commentedYes, I have #702554: Look up sitealias database settings only after a full database bootstrap and I get the same thing.
I found something interesting though - I added
var_dump($options);to the end of my drushrc.php, and found out it is not being read when I rundrush sql-sync. If I simply rundrush- I do get to see the dump.Also, by chance, I found that whern I run
drush dev sql-sync dev stageI do not get the error, but the standard message to make a backup. I have not continued this step though.Hope this helps a bit in deciphering this.
I also have domain module installed, but using '--uri=site' does not help too. I tried disabling domain, and I still get the same behavior.
Comment #7
greg.1.anderson commentedIf you just run "drush" or "drush help", then drush will do a full bootstrap. If you do "drush sql-sync", drush will only bootstrap to the "bootstrap drush" level. If your drushrc.php is in your sites folder, then it will not be loaded unless you bootstrap at least to the "bootstrap site" level. If you want to define settings that can be used by sql-sync, put your drushrc in some location that is loaded right away, like $HOME/.drushrc.php or /etc/drushrc.php or drush/drushrc.php.
It would be useful to see the output of "drush -d sql-sync dev stage"; I don't have enough to go on yet.
Comment #8
greg.1.anderson commentedAh, wait, there actually was enough information to figure this one out; it came to me suddenly.
The issue is not that drush cannot get the db spec, but that it cannot find a definition for the alias at all. The reason it cannot find the alias is that said alias is defined in a site drushrc.php file that is not loaded. The bug is that the error message is wrong.
The enclosed patch corrects the error message.
Comment #9
moshe weitzman commentedlooks good.
Comment #10
greg.1.anderson commentedCommitted.
Comment #11
greg.1.anderson commented@yhager: See also #721472: Site aliases should load the drushrc.php config file for the site selected.
Comment #12
yhager commentedMoving
drushrc.phpto$HOME/.drushrc.phpindeed solved the issue.I think this should be documented though. Currently, by reading the head of
example.drushrc.phpone just assumes that all these locations are equal (likesites/modules,sites/all/modulesetc.) - and I can choose the one most convenient to me. Since I want to be able to use drush for other sites on the same machine, the sites folder looked like the best approach.It is also not clear if
$HOME/.drushrc.phpcan coexist withsites/default/drushrc.phpin the sense that they can overwrite/complement each other (I can hold my site-aliases in my~/.drushrc.php, but site specific data, like$options['l']should go intosites/default/drushrc.php).Comment #13
yhager commentedComment #14
greg.1.anderson commentedThat is a good suggestion. In order to understand the difference between the site-specific configuration files and the others, you need to understand how drush bootstraping works, at least a little bit. Most of the drush configuration files are loaded during the 'drush' bootstrap, but the site-specific configuration file is not loaded until the 'site configuration' bootstrap phase. Some commands, like sql-sync, do not bootstrap past the drush bootstrap phase.
Another thing to note is that to a certain extent you got it backwards; the site folder is only used for the one drush site that the configuration file appears in. To have a config file used for all sites, you need to store it in one of the other possible locations. Also, $options['l'] selects which site drush should target, so this option in particular is useless in the context of a site-specific configuration file.
I'll add some more documentation to the example configuration file, but I want to get Moshe's opinion on #722612: Options for experimenting with drush bootstrap levels, and determining which configuration files were loaded. first.
Comment #15
greg.1.anderson commentedThe enclosed patch briefly describes bootstrapping in simplified form in an attempt to better explain the impact of storing drush configuration files in the different locations that are available.
Comment #16
moshe weitzman commentedcommitted. thanks.
Comment #17
yhager commentedThanks!