Differential D15714 Diff 37865 src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
| <?php | <?php | ||||
| final class PhabricatorStorageManagementDumpWorkflow | final class PhabricatorStorageManagementDumpWorkflow | ||||
| extends PhabricatorStorageManagementWorkflow { | extends PhabricatorStorageManagementWorkflow { | ||||
| protected function didConstruct() { | protected function didConstruct() { | ||||
| $this | $this | ||||
| ->setName('dump') | ->setName('dump') | ||||
| ->setExamples('**dump** [__options__]') | ->setExamples('**dump** [__options__]') | ||||
| ->setSynopsis(pht('Dump all data in storage to stdout.')); | ->setSynopsis(pht('Dump all data in storage to stdout.')) | ||||
| ->setArguments( | |||||
| array( | |||||
| array( | |||||
| 'name' => 'for-replica', | |||||
| 'help' => pht( | |||||
| 'Add __--dump-slave__ to the __mysqldump__ command, '. | |||||
| 'generating a CHANGE MASTER statement in the output.'), | |||||
| ), | |||||
| )); | |||||
| } | } | ||||
| public function didExecute(PhutilArgumentParser $args) { | public function didExecute(PhutilArgumentParser $args) { | ||||
| $api = $this->getAPI(); | $api = $this->getAPI(); | ||||
| $patches = $this->getPatches(); | $patches = $this->getPatches(); | ||||
| $console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
| $applied = $api->getAppliedPatches(); | $applied = $api->getAppliedPatches(); | ||||
| if ($applied === null) { | if ($applied === null) { | ||||
| $namespace = $api->getNamespace(); | $namespace = $api->getNamespace(); | ||||
| $console->writeErr( | $console->writeErr( | ||||
| pht( | pht( | ||||
| '**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); | $databases = $api->getDatabaseList($patches, true); | ||||
| list($host, $port) = $this->getBareHostAndPort($api->getHost()); | list($host, $port) = $this->getBareHostAndPort($api->getHost()); | ||||
| $flag_password = ''; | |||||
| $password = $api->getPassword(); | $password = $api->getPassword(); | ||||
| if ($password) { | if ($password) { | ||||
| if (strlen($password->openEnvelope())) { | if (strlen($password->openEnvelope())) { | ||||
| $flag_password = csprintf('-p%P', $password); | $has_password = true; | ||||
| } | } | ||||
| } | } | ||||
| $flag_port = $port | $argv = array(); | ||||
| ? csprintf('--port %d', $port) | $argv[] = '--hex-blob'; | ||||
| : ''; | $argv[] = '--single-transaction'; | ||||
| $argv[] = '--default-character-set=utf8'; | |||||
| return phutil_passthru( | |||||
| 'mysqldump --hex-blob --single-transaction --default-character-set=utf8 '. | if ($args->getArg('for-replica')) { | ||||
| '-u %s %C -h %s %C --databases %Ls', | $argv[] = '--dump-slave'; | ||||
| $api->getUser(), | } | ||||
| $flag_password, | |||||
| $host, | $argv[] = '-u'; | ||||
| $flag_port, | $argv[] = $api->getUser(); | ||||
| $databases); | $argv[] = '-h'; | ||||
| $argv[] = $host; | |||||
| if ($port) { | |||||
| $argv[] = '--port'; | |||||
| $argv[] = $port; | |||||
| } | |||||
| $argv[] = '--databases'; | |||||
| foreach ($databases as $database) { | |||||
| $argv[] = $database; | |||||
| } | |||||
| if ($has_password) { | |||||
| $err = phutil_passthru('mysqldump -p%P %Ls', $password, $argv); | |||||
| } else { | |||||
| $err = phutil_passthru('mysqldump %Ls', $argv); | |||||
| } | |||||
| return $err; | |||||
| } | } | ||||
| } | } | ||||