Differential D18682 Diff 44854 src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
| Show All 25 Lines | $this | ||||
| ), | ), | ||||
| array( | array( | ||||
| 'name' => 'compress', | 'name' => 'compress', | ||||
| 'help' => pht( | 'help' => pht( | ||||
| 'With __--output__, write a compressed file to disk instead '. | 'With __--output__, write a compressed file to disk instead '. | ||||
| 'of a plaintext file.'), | 'of a plaintext file.'), | ||||
| ), | ), | ||||
| array( | array( | ||||
| 'name' => 'no-indexes', | |||||
| 'help' => pht( | |||||
| 'Do not dump data in rebuildable index tables. This means '. | |||||
| 'backups are smaller and faster, but you will need to manually '. | |||||
| 'rebuild indexes after performing a restore.'), | |||||
| ), | |||||
| array( | |||||
| 'name' => 'overwrite', | 'name' => 'overwrite', | ||||
| 'help' => pht( | 'help' => pht( | ||||
| 'With __--output__, overwrite the output file if it already '. | 'With __--output__, overwrite the output file if it already '. | ||||
| 'exists.'), | 'exists.'), | ||||
| ), | ), | ||||
| )); | )); | ||||
| } | } | ||||
| protected function isReadOnlyWorkflow() { | protected function isReadOnlyWorkflow() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function didExecute(PhutilArgumentParser $args) { | public function didExecute(PhutilArgumentParser $args) { | ||||
| $api = $this->getSingleAPI(); | $api = $this->getSingleAPI(); | ||||
| $patches = $this->getPatches(); | $patches = $this->getPatches(); | ||||
| $console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
| $with_indexes = !$args->getArg('no-indexes'); | |||||
| $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; | ||||
| } | } | ||||
| $ref = $api->getRef(); | $ref = $api->getRef(); | ||||
| $ref_key = $ref->getRefKey(); | $ref_key = $ref->getRefKey(); | ||||
| $schemata_map = id(new PhabricatorConfigSchemaQuery()) | $schemata_query = id(new PhabricatorConfigSchemaQuery()) | ||||
| ->setAPIs(array($api)) | ->setAPIs(array($api)) | ||||
| ->setRefs(array($ref)) | ->setRefs(array($ref)); | ||||
| ->loadActualSchemata(); | |||||
| $schemata = $schemata_map[$ref_key]; | $actual_map = $schemata_query->loadActualSchemata(); | ||||
| $expect_map = $schemata_query->loadExpectedSchemata(); | |||||
| $schemata = $actual_map[$ref_key]; | |||||
| $expect = $expect_map[$ref_key]; | |||||
| $targets = array(); | $targets = array(); | ||||
| foreach ($schemata->getDatabases() as $database_name => $database) { | foreach ($schemata->getDatabases() as $database_name => $database) { | ||||
| $expect_database = $expect->getDatabase($database_name); | |||||
| foreach ($database->getTables() as $table_name => $table) { | foreach ($database->getTables() as $table_name => $table) { | ||||
| // NOTE: It's possible for us to find tables in these database which | |||||
| // we don't expect to be there. For example, an older version of | |||||
| // Phabricator may have had a table that was later dropped. We assume | |||||
| // these are data tables and always dump them, erring on the side of | |||||
| // caution. | |||||
| $persistence = PhabricatorConfigTableSchema::PERSISTENCE_DATA; | |||||
| if ($expect_database) { | |||||
| $expect_table = $expect_database->getTable($table_name); | |||||
| if ($expect_table) { | |||||
| $persistence = $expect_table->getPersistenceType(); | |||||
| } | |||||
| } | |||||
| switch ($persistence) { | |||||
| case PhabricatorConfigTableSchema::PERSISTENCE_CACHE: | |||||
| // When dumping tables, leave the data in cache tables in the | |||||
| // database. This will be automatically rebuild after the data | |||||
| // is restored and does not need to be persisted in backups. | |||||
| $with_data = false; | |||||
| break; | |||||
| case PhabricatorConfigTableSchema::PERSISTENCE_INDEX: | |||||
| // When dumping tables, leave index data behind of the caller | |||||
| // specified "--no-indexes". These tables can be rebuilt manually | |||||
| // from other tables, but do not rebuild automatically. | |||||
| $with_data = $with_indexes; | |||||
| break; | |||||
| case PhabricatorConfigTableSchema::PERSISTENCE_DATA: | |||||
| default: | |||||
| $with_data = true; | |||||
| break; | |||||
| } | |||||
| $targets[] = array( | $targets[] = array( | ||||
| 'database' => $database_name, | 'database' => $database_name, | ||||
| 'table' => $table_name, | 'table' => $table_name, | ||||
| 'data' => $with_data, | |||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||
| list($host, $port) = $this->getBareHostAndPort($api->getHost()); | list($host, $port) = $this->getBareHostAndPort($api->getHost()); | ||||
| $has_password = false; | $has_password = false; | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if ($port) { | ||||
| $argv[] = '--port'; | $argv[] = '--port'; | ||||
| $argv[] = $port; | $argv[] = $port; | ||||
| } | } | ||||
| $commands = array(); | $commands = array(); | ||||
| foreach ($targets as $target) { | foreach ($targets as $target) { | ||||
| $target_argv = $argv; | $target_argv = $argv; | ||||
| if (!$target['data']) { | |||||
| $target_argv[] = '--no-data'; | |||||
| } | |||||
| if ($has_password) { | if ($has_password) { | ||||
| $commands[] = csprintf( | $commands[] = csprintf( | ||||
| 'mysqldump -p%P %Ls -- %R %R', | 'mysqldump -p%P %Ls -- %R %R', | ||||
| $password, | $password, | ||||
| $target_argv, | $target_argv, | ||||
| $target['database'], | $target['database'], | ||||
| $target['table']); | $target['table']); | ||||
| } else { | } else { | ||||
| ▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines | |||||