From 6725f3719da3498670e07a1922762bbb4165764d Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 6 Sep 2016 07:29:59 -0700 Subject: [PATCH] (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 --- .../PhabricatorFilesManagementMigrateWorkflow.php | 10 +++++++++- .../files/storage/PhabricatorFile.php | 15 ++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php b/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php index 83978d9764..eda43e2ef3 100644 --- a/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php +++ b/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php @@ -36,6 +36,12 @@ final class PhabricatorFilesManagementMigrateWorkflow 'name' => 'all', '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( 'name' => 'names', 'wildcard' => true, @@ -70,6 +76,8 @@ final class PhabricatorFilesManagementMigrateWorkflow $min_size = (int)$args->getArg('min-size'); $max_size = (int)$args->getArg('max-size'); + $is_copy = $args->getArg('copy'); + $failed = array(); $engines = PhabricatorFileStorageEngine::loadAllEngines(); $total_bytes = 0; @@ -158,7 +166,7 @@ final class PhabricatorFilesManagementMigrateWorkflow if ($is_dry_run) { // Do nothing, this is a dry run. } else { - $file->migrateToEngine($target_engine); + $file->migrateToEngine($target_engine, $is_copy); } $total_files += 1; diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php index 8d81c3ae98..d301abceca 100644 --- a/src/applications/files/storage/PhabricatorFile.php +++ b/src/applications/files/storage/PhabricatorFile.php @@ -422,7 +422,10 @@ final class PhabricatorFile extends PhabricatorFileDAO return self::buildFromFileData($data, $params); } - public function migrateToEngine(PhabricatorFileStorageEngine $engine) { + public function migrateToEngine( + PhabricatorFileStorageEngine $engine, + $make_copy) { + if (!$this->getID() || !$this->getStorageHandle()) { throw new Exception( 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->save(); - $this->deleteFileDataIfUnused( - $old_engine, - $old_identifier, - $old_handle); + if (!$make_copy) { + $this->deleteFileDataIfUnused( + $old_engine, + $old_identifier, + $old_handle); + } return $this; }