Hi there--
I'm trying to create an alias pointing to a different DB server than is in my settings.php.

I've got an aliases.drushrc.php file in my drush directory, it doesn't throw any errors when I try to use the alias, but it is not using the DB credentials I've specified in the file. I don't get any errors when I run the command and it says it's loading the alias, but according to the sql-dump file I'm generating, it's pulling from the server in settings.php

drush status
 Drupal version                :  7.8                                              
 Site URI                      :  http://default                                   
 Database driver               :  mysql                                            
 Database hostname             :  www-db.REDACTED                          
 Database username             :  REDACTED                                  
 Database name                 :  REDACTED_DB                                     
 Database                      :  Connected                                        
 Drupal bootstrap              :  Successful                                       
 Drupal user                   :  Anonymous                                        
 Default theme                 :  REDACTED                                     
 Administration theme          :  seven                                            
 PHP configuration             :  /etc/php5/cli/php.ini                            
 Drush version                 :  4.5                                              
 Drush configuration           :                                                   
 Drush alias files             :  /usr/share/drush/includes/../aliases.drushrc.php 
 Drupal root                   :  /srv/www/svn/trunk/public                        
 Site path                     :  sites/default                                    
 File directory path           :  sites/default/files                              
 Private file directory path   :

drush call:

drush @backup sql-dump > test.sql -vvvvv
Load alias @backup                                                                                                           [notice]
Initialized Drupal 7.8 root directory at /srv/www/svn/trunk/public                                                           [notice]
Initialized Drupal site default at sites/default                                                                             [notice]
Command dispatch complete                                                                                                    [notice]
head test.sql 
Calling system(mysqldump --single-transaction --opt -Q  DB_REDACTED --host=www-db.REDACTED --port=3306 --user=REDACTED --password=REDACTED );

aliases.drushrc.php definition of the alias:

<?php
$aliases['backup'] = array(
  'databases' => array(
     'default' => array(
        'default' => array(
          'driver' => 'mysql',
          'database' => 'REDACTED',
          'username' => 'REDACTED',
          'password' => 'REDACTED',
          'host' => 'DESIRED_HOST',
          'port' => 3306,
          'prefix' => '',
          'collation' => 'utf8_general_ci',
        )
      )
    )
);

Any demos or examples of how the 'databases' instruction in aliases is supposed to work?

Thx

Comments

moshe weitzman’s picture

AFAIK, the databases element in the alias is only useful to avoid an ssh call to lookup this info for commands that don't require drush on the remote side. the only example i can think of is sql-sync. Your example is sql-dump and I'm a bit surpised that it does not fall into same category as sql-sync. I will take a look if noone else investigates this.

If you can, would be helpful if you try this on drush5 and see if behavior has changed.

craigmc’s picture

Moshe--
Thanks for following up.
I tested this with Drush 5.0-dev and it works perfectly out of the box with sql-dump.

Will try to test sql-sync with 4.5 later and will let you know

greg.1.anderson’s picture

Yeah, all of the sql-* commands will use a 'databases' record from the alias record if there is no bootstrapped site. I put this in back in September in 2af88b09. Maybe needs docs; not sure where.

greg.1.anderson’s picture

Status: Active » Closed (fixed)

Marking fixed.