4

I've recently made some backup scripts to automate backup of my site and databases. One of the scripts uses drush to dump the drupal and civicrm databases with these commands:

drush @myserveralias cc all && drush @myserveralias sql-dump --gzip --result-file=mydrupaldatabase-150731.sql

drush @myserveralias cc all && drush @myserveralias civicrm-sql-dump --gzip --result-file=mycivicrmdatabase-150731.sql

My problem is that both of them dumps the drupal database - I would like the second one to dump the civi-database.

Should i somehow specify the civicrm database? My aliases.drushrc.php doesn't specify anything about databases under myserveralis - should it be specified there? My settings.php has this to say about databases:

$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'drupal',
'username' => 'myusername',
'password' => 'mypassword',
'host' => 'localhost',
'port' => 3306,
'prefix' => 'drupal_',
'collation' => 'utf8_general_ci',
);
$databases['default']['default']['prefix']= array(
  'default' => 'drupal_',
  'civicrm_acl'                              => '`civicrm`.',
  'civicrm_acl_cache'                        => '`civicrm`.',
  'civicrm_acl_contact_cache'                => '`civicrm`.',
  'civicrm_acl_entity_role'                  => '`civicrm`.',
  ...

Thanks in advance for any help.

EDIT: I've updated drush to version 7.0.0, and the call to civicrm-sql-dump now fails with the following error:

PHP Fatal error:  Call to undefined function drush_sql_dump_execute() in /sites/all/modules/civicrm/drupal/drush/civicrm.drush.inc on line 995

I guess there's no longer a function in Drush called drush_sql_dump_execute.

SECOND EDIT: I've updated to civicrm 4.6.8 and now it works as it should. I didn't get the chance to explore Alan's suggestions, though i know for sure that my civi-database is in a different database than Drupal. Thanks for your help and input. If anyone drops by here having this problem, I would recommend upgrading, as Jon says he hasn't seen this error in any of the newer versions of civi, and upgrading solved it for me. Leaving this open for now, if someone actually solves this for civi 4.4 and Drush 6, then they can provide an answer.

  • 1
    What databases are defined in your civicrm.settings.php? Can you confirm that you have installed CiviCRM and Drupal in different databases? In some installations they can share a database, just with different table prefixes (which might explain why the same database is coming out twice). – John Jul 31 '15 at 14:13
  • Both the Drupal and civi database are defined in civicrm.settings.php, and they are in different databases. – Anders Iversen Jul 31 '15 at 16:32
  • Please give your drush and CiviCRM versions? I've seen this problem, mostly with older versions of drush. – Jon G - Megaphone Tech Aug 3 '15 at 4:47
  • Drush is version 6.6.0 CiviCRM is version 4.4.5 – Anders Iversen Aug 3 '15 at 9:02
  • 1
    Anders - I would update to the latest CiviCRM 4.4LTS version - I've seen that fix this problem in at least one instance. – Jon G - Megaphone Tech Aug 4 '15 at 18:40
3

One answer to your question is that you can use the sql-dump drush command to dump your civicrm database by using this option:

 --database : The DB connection key if using multiple connections in settings.php.

For that to work, you'd have to edit your drupal settings file to include something like:

$database['civicrm'] = array('default' => array('driver' => .. etc.

A second answer is that the civicrm-sql-dump drush command does not use the drupal settings file, but the civicrm settings file, to get the db name and credentials, so the fact you're getting the same dump from both suggests that you might not be using a separate db for civicrm as you think. Maybe you're looking at the wrong civicrm.settings.php file?

It does look like you want to revert to the 6.x drush. I haven't ever seen the behaviour you describe, but I tend to use bash scripts for mysql backups anyway, to keep things simpler.

1

Just to submit as an answer rather than comment - I can confirm that I no longer see this behavior on any of my Civi installs, which are running 4.4.19 or 4.6.8. I saw this a bunch in 4.3 and earlier versions of 4.4, though only with drush, never with wp-cli.

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.