Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#2 | provision-be-nice-to-non-aegir-archive-dump-1786702-2.patch | 2.21 KB | clemens.tolboom |
Comments
Comment #1
clemens.tolboomThis is done by Provision/Config/Drupal/provision_drupal_settings.tpl.php
Comment #2
clemens.tolboomPatch adds an if wrapper testing on
isset($_SERVER['db_name'])
to allowdrush archive-restore ...
to append it's db connections string.I removed two spaces and indented the whole code block.
Comment #2.0
clemens.tolboomTried to better report :)
Comment #2.1
clemens.tolboomAdded example of archive-restore in a non Aegir context.
Comment #3
helmo CreditAttribution: helmo commentedMakes sence.
The performance penalty is only one additional if statement.
Comment #4
anarcat CreditAttribution: anarcat commentedI committed this fix to 2.x, I'll wait for jenkins to do its magic before merging into 1.x.
Thanks!
Comment #5
anarcat CreditAttribution: anarcat commentedmerged in 1.x.
Comment #6.0
(not verified) CreditAttribution: commentedAdded notices