Commit 1cd6ca69 authored by Adrian Rossouw's avatar Adrian Rossouw

fix backup task

stop the generation of drushrc.php when a site context is being saved.
parent e4355a9d
......@@ -163,8 +163,10 @@ class provisionService_db extends provisionService {
}
function import_site_database() {
$dump_file = d()->root . '/sites/' . d()->uri . '/database.sql';
function import_site_database($dump_file = null) {
if (is_null($dump_file)) {
$dump_file = d()->root . '/sites/' . d()->uri . '/database.sql';
}
$creds = $this->fetch_site_credentials();
......
......@@ -73,7 +73,7 @@ class provisionService_db_mysql extends provisionService_db_pdo {
$cmd = sprintf("mysql --defaults-file=/dev/fd/3 %s", escapeshellcmd($db_name));
$this->safe_shell_exec($cmd, $db_host, $db_user, $db_passwd);
$this->safe_shell_exec($cmd, $db_host, $db_user, $db_passwd, $dump_file);
drush_log(sprintf("Importing database using command: %s", $cmd));
......@@ -94,7 +94,7 @@ class provisionService_db_mysql extends provisionService_db_pdo {
// non-readable by the webserver.
umask(0077);
// Mixed copy-paste of drush_shell_exec and provision_shell_exec.
$cmd = sprintf("mysqldump --defaults-file=/dev/fd/3 -rsites/%s/database.sql %s", escapeshellcmd(drush_get_option('uri')), escapeshellcmd(drush_get_option('db_name')));
$cmd = sprintf("mysqldump --defaults-file=/dev/fd/3 -rsites/%s/database.sql %s", escapeshellcmd(d($this->context)->uri), escapeshellcmd(drush_get_option('db_name')));
$this->safe_shell_exec($cmd, drush_get_option('db_host'), urldecode(drush_get_option('db_user')), urldecode(drush_get_option('db_passwd')));
......@@ -106,7 +106,7 @@ class provisionService_db_mysql extends provisionService_db_pdo {
umask(0022);
}
function safe_shell_exec($cmd, $db_host, $db_user, $db_passwd) {
function safe_shell_exec($cmd, $db_host, $db_user, $db_passwd, $dump_file = null) {
# we go through all this trouble to hide the password from the commandline, it's the most secure way (apart from writing a temporary file, which would create conflicts in parallel runs)
$mycnf = sprintf('[client]
host=%s
......@@ -114,8 +114,10 @@ user=%s
password=%s
', $db_host, $db_user, $db_passwd);
$stdin_spec = (!is_null($dump_file)) ? array("file", $dump_file, "r") : array("pipe", "r");
$descriptorspec = array(
0 => array("file", $dump_file, "r"),
0 => $stdin_spec,
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w"), // stderr is a file to write to
3 => array("pipe", "r"), // fd3 is our special file descriptor where we pass credentials
......
......@@ -9,7 +9,7 @@ function drush_db_pre_provision_restore() {
}
function drush_db_provision_restore() {
provision_service('db')->import_site_database();
provision_service('db')->import_site_database(d()->root . '/sites/' . d()->uri . '.restore/database.sql');
}
......
......@@ -36,12 +36,12 @@ function drush_provision_drupal_provision_backup_validate($backup_file = NULL) {
}
if (!$backup_file) {
$suggested = drush_get_option('backup_path') . '/' . drush_get_option('uri') . '-' . date("Ymd.His", mktime()) . '.tar.gz';
$suggested = d()->platform->server->backup_path . '/' . d()->uri . '-' . date("Ymd.His", mktime()) . '.tar.gz';
// Use format of mysite.com-2008-01-02, if already existing, add number.
while (is_file($suggested)) {
$count++;
$suggested = drush_get_option('backup_path') . '/' . drush_get_option('uri') . '-' . date('Ymd.His', mktime()) . '_' . $count . '.tar.gz';
$suggested = d()->platform->server->backup_path . '/' . d()->uri . '-' . date('Ymd.His', mktime()) . '_' . $count . '.tar.gz';
}
drush_set_option('backup_file', $suggested);
}
......
......@@ -98,8 +98,11 @@ function provision_drupal_drush_exit() {
if (preg_match("/^provision-/", $command[0])) {
if (PROVISION_CONTEXT_SITE) {
if (drush_get_option('installed')) {
drush_set_option('site_id', drush_get_option('site_id'), 'site');
provision_save_site_data();
// dont generate the drushrc.php on provision-save commands.
if (!preg_match("/^provision-save/", $command[0])) {
drush_set_option('site_id', drush_get_option('site_id'), 'site');
provision_save_site_data();
}
}
}
elseif (PROVISION_CONTEXT_PLATFORM) {
......@@ -209,7 +212,7 @@ class provisionConfig_drupal_settings extends provisionConfig {
$this->data['extra_config'] = "# Extra configuration from modules:\n";
$this->data['extra_config'] .= join("\n", drush_command_invoke_all('provision_drupal_config', $this->data['uri'], $this->data));
$this->group = drush_get_option('web_group');
$this->group = $this->platform->server->web_group;
}
}
......@@ -243,11 +246,11 @@ function _provision_drupal_create_directories($url = NULL, $profile = NULL) {
$mkdir["sites/$url/files/images"] = 02770;
$mkdir["sites/$url/files/pictures"] = 02770;
# the owner/group of those directories will be changed recursively
$chown["sites/$url/files"] = drush_get_option('script_user');
$chgrp["sites/$url/files"] = drush_get_option('web_group');
$chown["sites/$url/private"] = drush_get_option('script_user');
$chgrp["sites/$url/private/files"] = drush_get_option('web_group');
$chgrp["sites/$url/private/temp"] = drush_get_option('web_group');
$chown["sites/$url/files"] = d()->platform->server->script_user;
$chgrp["sites/$url/files"] = d()->platform->server->web_group;
$chown["sites/$url/private"] = d()->platform->server->script_user;
$chgrp["sites/$url/private/files"] = d()->platform->server->web_group;
$chgrp["sites/$url/private/temp"] = d()->platform->server->web_group;
}
foreach ($mkdir as $path => $perm) {
......@@ -269,7 +272,7 @@ function _provision_drupal_create_directories($url = NULL, $profile = NULL) {
foreach ($chgrp as $path => $group) {
provision_service('file')->chgrp($path, $group, TRUE)
->succeed('Changed group ownership of <code>@path</code> to @gid')
->fail('Could not change group ownership <code>@path</code>');
->fail('Could not change group ownership <code>@path</code> to @gid');
}
}
......
......@@ -44,7 +44,6 @@ function drush_provision_drupal_provision_verify() {
drush_set_option('sites', array_keys((array) provision_drupal_find_sites()), 'drupal');
drush_log(dt("This platform is running @short_name @version", array('@short_name' => 'drupal', '@version' => VERSION)));
drush_set_option('packages', _scrub_object(provision_find_packages()), 'drupal');
_provision_drupal_create_directories('all');
}
elseif (PROVISION_CONTEXT_SITE) {
drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment