2

My Drupal 7 site connects to multiple databases using a $databases array like this:

$databases = [
  'default' => [
    'default' => [
      'database' => 'examplecom',
      'username' => 'example',
      'password' => 'sostrongpassword',
      'host' => '',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ],
  ],
  'nondefault' => [
    'default' => [
      'database' => 'notdefaultdb',
      'username' => 'notdefaultuser',
      'password' => 'notdefaultpass',
      'host' => '',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ],
  ],
];

Ideally I want to be able to do something like drush --database-key=nondefault sql-dump > myfile.sql but I don't see a way in drush to do that. Is it possible?

I tried creating a custom script to do this like:

drush_sql_bootstrap_further();
db_set_active('nondefault');
$sql = drush_sql_get_class();
return $sql->connect(FALSE);

And then calling that script with drush scr foo.php but the sql connect (or any other command) seem to work against the default database.

4

According to the Drush 8 docs, there is a --database=key option that does what you want.

I've verified it against a D8 site with multiple databases using the command:

drush @dev sql-dump --database="blog_import" > ~/tmp/blog_import.sql

The drush sql-cli command also has the same option so you should be able to import the dump using a command like:

drush @dev sql-cli --database="blog_import" < ~/tmp/blog_import.sql
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.