Commit db82f625 authored by Adrian Rossouw's avatar Adrian Rossouw

got restore working. i think.

parent 1cd6ca69
......@@ -140,8 +140,10 @@ class provisionService_db extends provisionService {
/**
* Remove the database and user account for the supplied credentials
*/
function destroy_site_database() {
$creds = $this->fetch_site_credentials();
function destroy_site_database($creds = array()) {
if (!sizeof($creds)) {
$creds = $this->fetch_site_credentials();
}
extract($creds);
if ( $this->database_exists($db_name) ) {
......
......@@ -73,11 +73,11 @@ 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, $dump_file);
$success = $this->safe_shell_exec($cmd, $db_host, $db_user, $db_passwd, $dump_file);
drush_log(sprintf("Importing database using command: %s", $cmd));
if ($return_value != 0) {
if (!$success) {
drush_set_error('PROVISION_DB_IMPORT_FAILED', dt("Database import failed: %output", array('%output' => $output)));
}
}
......@@ -94,12 +94,10 @@ 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(d($this->context)->uri), escapeshellcmd(drush_get_option('db_name')));
$cmd = sprintf("mysqldump --defaults-file=/dev/fd/3 -r%s/sites/%s/database.sql %s", escapeshellcmd(d($this->context)->root), escapeshellcmd(d($this->context)->uri), escapeshellcmd(drush_get_option('db_name')));
$success = $this->safe_shell_exec($cmd, drush_get_option('db_host'), urldecode(drush_get_option('db_user')), urldecode(drush_get_option('db_passwd')));
$this->safe_shell_exec($cmd, drush_get_option('db_host'), urldecode(drush_get_option('db_user')), urldecode(drush_get_option('db_passwd')));
$result = ($return_value == 0);
if (!$result && !drush_get_option('force', false)) {
if (!$success && !drush_get_option('force', false)) {
drush_set_error('PROVISION_BACKUP_FAILED', dt("Could not generate database backup from mysqldump"));
}
// Reset the umask to normal permissions.
......@@ -138,7 +136,7 @@ password=%s
// XXX: failed to execute? unsure when this happens
$return_value = -1;
}
dlm($output);
return ($return_value == 0);
}
......
......@@ -5,6 +5,8 @@ function drush_db_provision_restore_validate() {
}
function drush_db_pre_provision_restore() {
drush_set_option('old_db_creds', provision_service('db')->fetch_site_credentials());
provision_service('db')->create_site_database();
}
......@@ -34,7 +36,7 @@ function drush_db_post_provision_restore() {
->succeed('Removed dump file @path after restoring from it')
->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
provision_service('db')->destroy_site_database();
provision_service('db')->destroy_site_database(drush_get_option('old_db_creds'));
// TODO - test this .. it's probably horribly broken .. deleting the newly restored db instead of the old one.
......
......@@ -236,6 +236,8 @@ class provisionService_file extends provisionService {
$this->tokens = array('@path1' => $path1, '@path2' => $path2);
$this->last_status = FALSE;
//TODO : Add error reasons.
$temp = $path1 . '.tmp';
if (!file_exists($path1)) {
......@@ -247,7 +249,7 @@ class provisionService_file extends provisionService {
elseif (rename($path1, $temp)) {
if (rename($path2, $path1)) {
if (rename($temp, $path2)) {
$this->last_status = $path2; // path1 is now path2
$this->last_status = TRUE; // path1 is now path2
}
else {
// same .. just in reverse
......@@ -259,7 +261,6 @@ class provisionService_file extends provisionService {
$this->last_status = rename($temp, $path1);
}
}
$this->last_status = FALSE;
return $this;
}
......
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