Differential D18679 Diff 44853 src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if ($applied === null) { | ||||
| '**Storage Not Initialized**: There is no database storage '. | '**Storage Not Initialized**: There is no database storage '. | ||||
| 'initialized in this storage namespace ("%s"). Use '. | 'initialized in this storage namespace ("%s"). Use '. | ||||
| '**%s** to initialize storage.', | '**%s** to initialize storage.', | ||||
| $namespace, | $namespace, | ||||
| './bin/storage upgrade')); | './bin/storage upgrade')); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| $databases = $api->getDatabaseList($patches, true); | $ref = $api->getRef(); | ||||
| $ref_key = $ref->getRefKey(); | |||||
| $schemata_map = id(new PhabricatorConfigSchemaQuery()) | |||||
| ->setAPIs(array($api)) | |||||
| ->setRefs(array($ref)) | |||||
| ->loadActualSchemata(); | |||||
| $schemata = $schemata_map[$ref_key]; | |||||
| $targets = array(); | |||||
| foreach ($schemata->getDatabases() as $database_name => $database) { | |||||
| foreach ($database->getTables() as $table_name => $table) { | |||||
| $targets[] = array( | |||||
| 'database' => $database_name, | |||||
| 'table' => $table_name, | |||||
| ); | |||||
| } | |||||
| } | |||||
| list($host, $port) = $this->getBareHostAndPort($api->getHost()); | list($host, $port) = $this->getBareHostAndPort($api->getHost()); | ||||
| $has_password = false; | $has_password = false; | ||||
| $password = $api->getPassword(); | $password = $api->getPassword(); | ||||
| if ($password) { | if ($password) { | ||||
| if (strlen($password->openEnvelope())) { | if (strlen($password->openEnvelope())) { | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public function didExecute(PhutilArgumentParser $args) { | ||||
| $argv[] = '-h'; | $argv[] = '-h'; | ||||
| $argv[] = $host; | $argv[] = $host; | ||||
| if ($port) { | if ($port) { | ||||
| $argv[] = '--port'; | $argv[] = '--port'; | ||||
| $argv[] = $port; | $argv[] = $port; | ||||
| } | } | ||||
| $argv[] = '--databases'; | $commands = array(); | ||||
| foreach ($databases as $database) { | foreach ($targets as $target) { | ||||
| $argv[] = $database; | $target_argv = $argv; | ||||
| } | |||||
| if ($has_password) { | if ($has_password) { | ||||
| $command = csprintf('mysqldump -p%P %Ls', $password, $argv); | $commands[] = csprintf( | ||||
joshuaspence: Shouldn't this be `$command = ...`? | |||||
aviveyUnsubmitted Not Done Inline ActionsFixed in T13004. avivey: Fixed in T13004. | |||||
joshuaspenceUnsubmitted Not Done Inline Actionsjoshuaspence: {icon thumbs-up} | |||||
| 'mysqldump -p%P %Ls -- %R %R', | |||||
| $password, | |||||
| $target_argv, | |||||
| $target['database'], | |||||
| $target['table']); | |||||
| } else { | } else { | ||||
| $command = csprintf('mysqldump %Ls', $argv); | $command = csprintf( | ||||
| 'mysqldump %Ls -- %R %R', | |||||
| $target_argv, | |||||
| $target['database'], | |||||
| $target['table']); | |||||
| } | } | ||||
| $commands[] = $command; | |||||
| } | |||||
| // Decrease the CPU priority of this process so it doesn't contend with | // Decrease the CPU priority of this process so it doesn't contend with | ||||
| // other more important things. | // other more important things. | ||||
| if (function_exists('proc_nice')) { | if (function_exists('proc_nice')) { | ||||
| proc_nice(19); | proc_nice(19); | ||||
| } | } | ||||
| // If we aren't writing to a file, just passthru the command. | |||||
| if ($output_file === null) { | |||||
| return phutil_passthru('%C', $command); | |||||
| } | |||||
| // If we are writing to a file, stream the command output to disk. This | // If we are writing to a file, stream the command output to disk. This | ||||
| // mode makes sure the whole command fails if there's an error (commonly, | // mode makes sure the whole command fails if there's an error (commonly, | ||||
| // a full disk). See T6996 for discussion. | // a full disk). See T6996 for discussion. | ||||
| if ($is_compress) { | if ($output_file === null) { | ||||
| $file = null; | |||||
| } else if ($is_compress) { | |||||
| $file = gzopen($output_file, 'wb1'); | $file = gzopen($output_file, 'wb1'); | ||||
| } else { | } else { | ||||
| $file = fopen($output_file, 'wb'); | $file = fopen($output_file, 'wb'); | ||||
| } | } | ||||
| if (!$file) { | if (!$file) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Failed to open file "%s" for writing.', | 'Failed to open file "%s" for writing.', | ||||
| $file)); | $file)); | ||||
| } | } | ||||
| try { | |||||
| foreach ($commands as $command) { | |||||
| $future = new ExecFuture('%C', $command); | $future = new ExecFuture('%C', $command); | ||||
| try { | |||||
| $iterator = id(new FutureIterator(array($future))) | $iterator = id(new FutureIterator(array($future))) | ||||
| ->setUpdateInterval(0.100); | ->setUpdateInterval(0.100); | ||||
| foreach ($iterator as $ready) { | foreach ($iterator as $ready) { | ||||
| list($stdout, $stderr) = $future->read(); | list($stdout, $stderr) = $future->read(); | ||||
| $future->discardBuffers(); | $future->discardBuffers(); | ||||
| if (strlen($stderr)) { | if (strlen($stderr)) { | ||||
| fwrite(STDERR, $stderr); | fwrite(STDERR, $stderr); | ||||
| } | } | ||||
| if (strlen($stdout)) { | if (strlen($stdout)) { | ||||
| if ($is_compress) { | if (!$file) { | ||||
| $ok = fwrite(STDOUT, $stdout); | |||||
| } else if ($is_compress) { | |||||
| $ok = gzwrite($file, $stdout); | $ok = gzwrite($file, $stdout); | ||||
| } else { | } else { | ||||
| $ok = fwrite($file, $stdout); | $ok = fwrite($file, $stdout); | ||||
| } | } | ||||
| if ($ok !== strlen($stdout)) { | if ($ok !== strlen($stdout)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Failed to write %d byte(s) to file "%s".', | 'Failed to write %d byte(s) to file "%s".', | ||||
| new PhutilNumber(strlen($stdout)), | new PhutilNumber(strlen($stdout)), | ||||
| $output_file)); | $output_file)); | ||||
| } | } | ||||
| } | } | ||||
| if ($ready !== null) { | if ($ready !== null) { | ||||
| $ready->resolvex(); | $ready->resolvex(); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| if ($is_compress) { | if (!$file) { | ||||
| $ok = true; | |||||
| } else if ($is_compress) { | |||||
| $ok = gzclose($file); | $ok = gzclose($file); | ||||
| } else { | } else { | ||||
| $ok = fclose($file); | $ok = fclose($file); | ||||
| } | } | ||||
| if ($ok !== true) { | if ($ok !== true) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Failed to close file "%s".', | 'Failed to close file "%s".', | ||||
| $output_file)); | $output_file)); | ||||
| } | } | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| // If we might have written a partial file to disk, try to remove it so | // If we might have written a partial file to disk, try to remove it so | ||||
| // we don't leave any confusing artifacts laying around. | // we don't leave any confusing artifacts laying around. | ||||
| try { | try { | ||||
| if ($file !== null) { | |||||
| Filesystem::remove($output_file); | Filesystem::remove($output_file); | ||||
| } | |||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| // Ignore any errors we hit. | // Ignore any errors we hit. | ||||
| } | } | ||||
| throw $ex; | throw $ex; | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||
Shouldn't this be $command = ...?