Doing an

drush "@$ALIAS" archive-dump --destination=$TEMPFILE --tar-options="--exclude=drushrc.php"

on an Aegir managed site I get VHOST specific code in settings.php like

  /**
   * The database credentials are stored in the Apache vhost config
- cut -
   * This is a security measure implemented by the Aegir project.
   */
  $databases['default']['default'] = array(
    'driver' => $_SERVER['db_type'],
    'database' => $_SERVER['db_name'],
    'username' => $_SERVER['db_user'],
    'password' => $_SERVER['db_passwd'],
    'host' => $_SERVER['db_host'],
    'port' => $_SERVER['db_port'],
  );
  $db_url['default'] = $_SERVER['db_type'] . '://' . $_SERVER['db_user'] . ':' . $_SERVER['db_passwd'] . '@' . $_SERVER['db_host'] . ':' . $_SERVER['db_port'] . '/' . $_SERVER['db_name'];

which causes notices on every page for the restored site on a non-Aegir install.

    Notice: Undefined index: db_type in include_once() (line 24 of /path/to/site/settings.php).
    Notice: Undefined index: db_name in include_once() (line 25 of /path/to/site/settings.php).
    Notice: Undefined index: db_user in include_once() (line 26 of /path/to/site/settings.php).
    Notice: Undefined index: db_passwd in include_once() (line 27 of /path/to/site/settings.php).
    Notice: Undefined index: db_host in include_once() (line 28 of /path/to/site/settings.php).
    Notice: Undefined index: db_port in include_once() (line 29 of /path/to/site/settings.php).
    Notice: Undefined index: db_type in include_once() (line 31 of /path/to/site/settings.php).
    Notice: Undefined index: db_user in include_once() (line 31 of /path/to/site/settings.php).
    Notice: Undefined index: db_passwd in include_once() (line 31 of /path/to/site/settings.php).
    Notice: Undefined index: db_host in include_once() (line 31 of /path/to/site/settings.php).
    Notice: Undefined index: db_port in include_once() (line 31 of /path/to/site/settings.php).
    Notice: Undefined index: db_name in include_once() (line 31 of /path/to/site/settings.php).

We could wrap this by testing for

if (isset($_SERVER['db_name'])) {
  /**
   * The database credentials are stored in the Apache vhost config
- cut -
   */
  $databases['default']['default'] = array(
- cut-
  );
  $db_url['default'] = $_SERVER['db_type'] . '://' . $_SERVER['db_user'] . ':' . $_SERVER['db_passwd'] . '@' . $_SERVER['db_host'] . ':' . $_SERVER['d
b_port'] . '/' . $_SERVER['db_name'];
}

Running

drush archive-restore --destination=/path/to/www/root --db-url=mysql://x_dev:x_dev@localhost/x_dev /archives/backup-x_prod-latest.tar.gz

adds its own db connection to the end of settings.php

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

clemens.tolboom’s picture

Project: Hostmaster (Aegir) » Provision

This is done by Provision/Config/Drupal/provision_drupal_settings.tpl.php

clemens.tolboom’s picture

Version: 6.x-1.9 » 6.x-1.x-dev
Status: Active » Needs review
FileSize
2.21 KB

Patch adds an if wrapper testing on isset($_SERVER['db_name']) to allow drush archive-restore ... to append it's db connections string.

I removed two spaces and indented the whole code block.

clemens.tolboom’s picture

Issue summary: View changes

Tried to better report :)

clemens.tolboom’s picture

Issue summary: View changes

Added example of archive-restore in a non Aegir context.

helmo’s picture

Makes sence.

The performance penalty is only one additional if statement.

anarcat’s picture

Status: Needs review » Patch (to be ported)

I committed this fix to 2.x, I'll wait for jenkins to do its magic before merging into 1.x.

Thanks!

anarcat’s picture

Status: Patch (to be ported) » Fixed

merged in 1.x.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Added notices

  • Commit 0d82c33 on dev-drupal-8, 6.x-2.x, dev-ssl-ip-allocation-refactor, dev-1205458-move_sites_out_of_platforms, 7.x-3.x, dev-subdir-multiserver, 6.x-2.x-backports, dev-helmo-3.x by anarcat:
    #1786702 by clemens.tolboom - be nice to non-aegir backups like drush...