$this->addOption( 'src', 'Backend containing the source files', true, true );
$this->addOption( 'dst', 'Backend where files should be copied to', true, true );
$this->addOption( 'containers', 'Pipe separated list of containers', true, true );
$this->addOption( 'src', 'Backend containing the source files', true, true );
$this->addOption( 'dst', 'Backend where files should be copied to', true, true );
$this->addOption( 'containers', 'Pipe separated list of containers', true, true );
$srcPathsRel = $this->getListingDiffRel( $src, $dst, $backendRel );
$this->output( count( $srcPathsRel ) . " file(s) need to be copied.\n" );
} else {
$srcPathsRel = $this->getListingDiffRel( $src, $dst, $backendRel );
$this->output( count( $srcPathsRel ) . " file(s) need to be copied.\n" );
} else {
'dir' => $src->getRootStoragePath() . "/$backendRel",
'adviseStat' => true // avoid HEADs
'dir' => $src->getRootStoragePath() . "/$backendRel",
'adviseStat' => true // avoid HEADs
if ( $srcPathsRel === null ) {
$this->error( "Could not list files in $container.", 1 ); // die
}
if ( $srcPathsRel === null ) {
$this->error( "Could not list files in $container.", 1 ); // die
}
if ( $this->getOption( 'prestat' ) && !$this->hasOption( 'missingonly' ) ) {
// Build the stat cache for the destination files
$this->output( "\tBuilding destination stat cache..." );
if ( $this->getOption( 'prestat' ) && !$this->hasOption( 'missingonly' ) ) {
// Build the stat cache for the destination files
$this->output( "\tBuilding destination stat cache..." );
'dir' => $dst->getRootStoragePath() . "/$backendRel",
'adviseStat' => true // avoid HEADs
'dir' => $dst->getRootStoragePath() . "/$backendRel",
'adviseStat' => true // avoid HEADs
if ( $dstPathsRel === null ) {
$this->error( "Could not list files in $container.", 1 ); // die
}
if ( $dstPathsRel === null ) {
$this->error( "Could not list files in $container.", 1 ); // die
}
foreach ( $dstPathsRel as $dstPathRel ) {
$path = $dst->getRootStoragePath() . "/$backendRel/$dstPathRel";
foreach ( $dstPathsRel as $dstPathRel ) {
$path = $dst->getRootStoragePath() . "/$backendRel/$dstPathRel";
}
$this->output( "done [" . count( $this->statCache ) . " file(s)]\n" );
}
$this->output( "\tCopying file(s)...\n" );
$count = 0;
}
$this->output( "done [" . count( $this->statCache ) . " file(s)]\n" );
}
$this->output( "\tCopying file(s)...\n" );
$count = 0;
foreach ( $srcPathsRel as $srcPathRel ) {
// Check up on the rate file periodically to adjust the concurrency
if ( $rateFile && ( !$count || ( $count % 500 ) == 0 ) ) {
foreach ( $srcPathsRel as $srcPathRel ) {
// Check up on the rate file periodically to adjust the concurrency
if ( $rateFile && ( !$count || ( $count % 500 ) == 0 ) ) {
$batchPaths[$srcPathRel] = 1; // remove duplicates
if ( count( $batchPaths ) >= $this->mBatchSize ) {
$this->copyFileBatch( array_keys( $batchPaths ), $backendRel, $src, $dst );
$batchPaths[$srcPathRel] = 1; // remove duplicates
if ( count( $batchPaths ) >= $this->mBatchSize ) {
$this->copyFileBatch( array_keys( $batchPaths ), $backendRel, $src, $dst );
}
++$count;
}
if ( count( $batchPaths ) ) { // left-overs
$this->copyFileBatch( array_keys( $batchPaths ), $backendRel, $src, $dst );
}
++$count;
}
if ( count( $batchPaths ) ) { // left-overs
$this->copyFileBatch( array_keys( $batchPaths ), $backendRel, $src, $dst );
foreach ( $delPathsRel as $delPathRel ) {
// Check up on the rate file periodically to adjust the concurrency
if ( $rateFile && ( !$count || ( $count % 500 ) == 0 ) ) {
foreach ( $delPathsRel as $delPathRel ) {
// Check up on the rate file periodically to adjust the concurrency
if ( $rateFile && ( !$count || ( $count % 500 ) == 0 ) ) {
$batchPaths[$delPathRel] = 1; // remove duplicates
if ( count( $batchPaths ) >= $this->mBatchSize ) {
$this->delFileBatch( array_keys( $batchPaths ), $backendRel, $dst );
$batchPaths[$delPathRel] = 1; // remove duplicates
if ( count( $batchPaths ) >= $this->mBatchSize ) {
$this->delFileBatch( array_keys( $batchPaths ), $backendRel, $dst );
}
++$count;
}
if ( count( $batchPaths ) ) { // left-overs
$this->delFileBatch( array_keys( $batchPaths ), $backendRel, $dst );
}
++$count;
}
if ( count( $batchPaths ) ) { // left-overs
$this->delFileBatch( array_keys( $batchPaths ), $backendRel, $dst );
* @return array (rel paths in $src minus those in $dst)
*/
protected function getListingDiffRel( FileBackend $src, FileBackend $dst, $backendRel ) {
* @return array (rel paths in $src minus those in $dst)
*/
protected function getListingDiffRel( FileBackend $src, FileBackend $dst, $backendRel ) {
if ( $srcPathsRel === null ) {
$this->error( "Could not list files in source container.", 1 ); // die
}
if ( $srcPathsRel === null ) {
$this->error( "Could not list files in source container.", 1 ); // die
}
if ( $dstPathsRel === null ) {
$this->error( "Could not list files in destination container.", 1 ); // die
}
// Get the list of destination files
if ( $dstPathsRel === null ) {
$this->error( "Could not list files in destination container.", 1 ); // die
}
// Get the list of destination files
foreach ( $dstPathsRel as $dstPathRel ) {
$relFilesDstSha1[sha1( $dstPathRel )] = 1;
}
unset( $dstPathsRel ); // free
// Get the list of missing files
foreach ( $dstPathsRel as $dstPathRel ) {
$relFilesDstSha1[sha1( $dstPathRel )] = 1;
}
unset( $dstPathsRel ); // free
// Get the list of missing files
foreach ( $srcPathsRel as $srcPathRel ) {
if ( !isset( $relFilesDstSha1[sha1( $srcPathRel )] ) ) {
$missingPathsRel[] = $srcPathRel;
foreach ( $srcPathsRel as $srcPathRel ) {
if ( !isset( $relFilesDstSha1[sha1( $srcPathRel )] ) ) {
$missingPathsRel[] = $srcPathRel;
protected function copyFileBatch(
array $srcPathsRel, $backendRel, FileBackend $src, FileBackend $dst
) {
protected function copyFileBatch(
array $srcPathsRel, $backendRel, FileBackend $src, FileBackend $dst
) {
$wikiId = $src->getWikiId();
// Download the batch of source files into backend cache...
if ( $this->hasOption( 'missingonly' ) ) {
$wikiId = $src->getWikiId();
// Download the batch of source files into backend cache...
if ( $this->hasOption( 'missingonly' ) ) {
foreach ( $srcPathsRel as $srcPathRel ) {
$srcPaths[] = $src->getRootStoragePath() . "/$backendRel/$srcPathRel";
}
$t_start = microtime( true );
foreach ( $srcPathsRel as $srcPathRel ) {
$srcPaths[] = $src->getRootStoragePath() . "/$backendRel/$srcPathRel";
}
$t_start = microtime( true );
$elapsed_ms = floor( ( microtime( true ) - $t_start ) * 1000 );
$this->output( "\n\tDownloaded these file(s) [{$elapsed_ms}ms]:\n\t" .
implode( "\n\t", $srcPaths ) . "\n\n" );
$elapsed_ms = floor( ( microtime( true ) - $t_start ) * 1000 );
$this->output( "\n\tDownloaded these file(s) [{$elapsed_ms}ms]:\n\t" .
implode( "\n\t", $srcPaths ) . "\n\n" );
- $src->clearCache( array( $srcPath ) );
- if ( $src->fileExists( array( 'src' => $srcPath, 'latest' => 1 ) ) === false ) {
+ $src->clearCache( [ $srcPath ] );
+ if ( $src->fileExists( [ 'src' => $srcPath, 'latest' => 1 ] ) === false ) {
$this->error( "$wikiId: File '$srcPath' was listed but does not exist." );
} else {
$this->error( "$wikiId: Could not get local copy of $srcPath." );
$this->error( "$wikiId: File '$srcPath' was listed but does not exist." );
} else {
$this->error( "$wikiId: Could not get local copy of $srcPath." );
}
$fsFiles[] = $fsFile; // keep TempFSFile objects alive as needed
// Note: prepare() is usually fast for key/value backends
}
$fsFiles[] = $fsFile; // keep TempFSFile objects alive as needed
// Note: prepare() is usually fast for key/value backends
if ( !$status->isOK() ) {
$this->error( print_r( $status->getErrorsArray(), true ) );
$this->error( "$wikiId: Could not copy $srcPath to $dstPath.", 1 ); // die
}
if ( !$status->isOK() ) {
$this->error( print_r( $status->getErrorsArray(), true ) );
$this->error( "$wikiId: Could not copy $srcPath to $dstPath.", 1 ); // die
}
- $ops[] = array( 'op' => 'store',
- 'src' => $fsFile->getPath(), 'dst' => $dstPath, 'overwrite' => 1 );
+ $ops[] = [ 'op' => 'store',
+ 'src' => $fsFile->getPath(), 'dst' => $dstPath, 'overwrite' => 1 ];
$copiedRel[] = $srcPathRel;
}
// Copy in the batch of source files...
$t_start = microtime( true );
$copiedRel[] = $srcPathRel;
}
// Copy in the batch of source files...
$t_start = microtime( true );
protected function delFileBatch(
array $dstPathsRel, $backendRel, FileBackend $dst
) {
protected function delFileBatch(
array $dstPathsRel, $backendRel, FileBackend $dst
) {
$wikiId = $dst->getWikiId();
// Determine what files need to be copied over...
foreach ( $dstPathsRel as $dstPathRel ) {
$dstPath = $dst->getRootStoragePath() . "/$backendRel/$dstPathRel";
$wikiId = $dst->getWikiId();
// Determine what files need to be copied over...
foreach ( $dstPathsRel as $dstPathRel ) {
$dstPath = $dst->getRootStoragePath() . "/$backendRel/$dstPathRel";
$deletedRel[] = $dstPathRel;
}
// Delete the batch of source files...
$t_start = microtime( true );
$deletedRel[] = $dstPathRel;
}
// Delete the batch of source files...
$t_start = microtime( true );
*/
protected function filesAreSame( FileBackend $src, FileBackend $dst, $sPath, $dPath ) {
$skipHash = $this->hasOption( 'skiphash' );
*/
protected function filesAreSame( FileBackend $src, FileBackend $dst, $sPath, $dPath ) {
$skipHash = $this->hasOption( 'skiphash' );
$dPathSha1 = sha1( $dPath );
if ( $this->statCache !== null ) {
// All dst files are already in stat cache
$dPathSha1 = sha1( $dPath );
if ( $this->statCache !== null ) {
// All dst files are already in stat cache
} else {
// This is the slowest method which does many per-file HEADs (unless an object
// store tracks SHA-1 in listings).
} else {
// This is the slowest method which does many per-file HEADs (unless an object
// store tracks SHA-1 in listings).
- $same = ( $src->getFileSha1Base36( array( 'src' => $sPath, 'latest' => 1 ) )
- === $dst->getFileSha1Base36( array( 'src' => $dPath, 'latest' => 1 ) ) );
+ $same = ( $src->getFileSha1Base36( [ 'src' => $sPath, 'latest' => 1 ] )
+ === $dst->getFileSha1Base36( [ 'src' => $dPath, 'latest' => 1 ] ) );