mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-28 01:32:42 +01:00
(stable) Add a "--copy" flag to "bin/files migrate"
Summary: Ref T11596. When exporting data from the Phacility cluster, we `bin/files migrate` data from S3 into a database dump on the `aux` tier. With current semantics, this //moves// the data and destroys it in S3. Add a `--copy` flag to //copy// the data instead. This leaves the old copy around, which is what we want for exports. Test Plan: - Ran `bin/files migrate` to go from `blob` to `disk` with `--copy`. Verified a copy was left in the database. - Copied it back, verified a copy was left on disk (total: 2 database copies, 1 disk copy). - Moved it back without copy, verified database was destroyed and disk was created (total: 1 database copy, 2 disk copies). - Moved it back without copy, verified local disk was destroyed and blob was created (total: 2 datbabase copies, 1 disk copy). Reviewers: chad Reviewed By: chad Maniphest Tasks: T11596 Differential Revision: https://secure.phabricator.com/D16497
This commit is contained in:
parent
bac8562884
commit
6725f3719d
2 changed files with 19 additions and 6 deletions
|
@ -36,6 +36,12 @@ final class PhabricatorFilesManagementMigrateWorkflow
|
||||||
'name' => 'all',
|
'name' => 'all',
|
||||||
'help' => pht('Migrate all files.'),
|
'help' => pht('Migrate all files.'),
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'copy',
|
||||||
|
'help' => pht(
|
||||||
|
'Copy file data instead of moving it: after migrating, do not '.
|
||||||
|
'remove the old data even if it is no longer referenced.'),
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'name' => 'names',
|
'name' => 'names',
|
||||||
'wildcard' => true,
|
'wildcard' => true,
|
||||||
|
@ -70,6 +76,8 @@ final class PhabricatorFilesManagementMigrateWorkflow
|
||||||
$min_size = (int)$args->getArg('min-size');
|
$min_size = (int)$args->getArg('min-size');
|
||||||
$max_size = (int)$args->getArg('max-size');
|
$max_size = (int)$args->getArg('max-size');
|
||||||
|
|
||||||
|
$is_copy = $args->getArg('copy');
|
||||||
|
|
||||||
$failed = array();
|
$failed = array();
|
||||||
$engines = PhabricatorFileStorageEngine::loadAllEngines();
|
$engines = PhabricatorFileStorageEngine::loadAllEngines();
|
||||||
$total_bytes = 0;
|
$total_bytes = 0;
|
||||||
|
@ -158,7 +166,7 @@ final class PhabricatorFilesManagementMigrateWorkflow
|
||||||
if ($is_dry_run) {
|
if ($is_dry_run) {
|
||||||
// Do nothing, this is a dry run.
|
// Do nothing, this is a dry run.
|
||||||
} else {
|
} else {
|
||||||
$file->migrateToEngine($target_engine);
|
$file->migrateToEngine($target_engine, $is_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
$total_files += 1;
|
$total_files += 1;
|
||||||
|
|
|
@ -422,7 +422,10 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
return self::buildFromFileData($data, $params);
|
return self::buildFromFileData($data, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function migrateToEngine(PhabricatorFileStorageEngine $engine) {
|
public function migrateToEngine(
|
||||||
|
PhabricatorFileStorageEngine $engine,
|
||||||
|
$make_copy) {
|
||||||
|
|
||||||
if (!$this->getID() || !$this->getStorageHandle()) {
|
if (!$this->getID() || !$this->getStorageHandle()) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
pht("You can not migrate a file which hasn't yet been saved."));
|
pht("You can not migrate a file which hasn't yet been saved."));
|
||||||
|
@ -446,10 +449,12 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
$this->setStorageHandle($new_handle);
|
$this->setStorageHandle($new_handle);
|
||||||
$this->save();
|
$this->save();
|
||||||
|
|
||||||
|
if (!$make_copy) {
|
||||||
$this->deleteFileDataIfUnused(
|
$this->deleteFileDataIfUnused(
|
||||||
$old_engine,
|
$old_engine,
|
||||||
$old_identifier,
|
$old_identifier,
|
||||||
$old_handle);
|
$old_handle);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue