$this->addOption( 'dst', 'Backend where files should be copied to', true, true );
$this->addOption( 'containers', 'Pipe separated list of containers', true, true );
$this->addOption( 'subdir', 'Only do items in this child directory', false, true );
- $this->addOption( 'ratefile', 'File to check periodically for batch size.', false, true );
+ $this->addOption( 'ratefile', 'File to check periodically for batch size', false, true );
+ $this->addOption( 'skiphash', 'Skip SHA-1 sync checks for files' );
+ $this->addOption( 'missingonly', 'Only copy files missing from destination listing' );
$this->setBatchSize( 50 );
}
$this->output( "Doing container '$container'...\n" );
}
- $dir = $src->getRootStoragePath() . "/$backendRel";
- $srcPathsRel = $src->getFileList( array( 'dir' => $dir ) );
+ $srcPathsRel = $src->getFileList( array(
+ 'dir' => $src->getRootStoragePath() . "/$backendRel" ) );
if ( $srcPathsRel === null ) {
$this->error( "Could not list files in $container.", 1 ); // die
}
+ // Do a listing comparison if specified
+ if ( $this->hasOption( 'missingonly' ) ) {
+ $relFilesSrc = array();
+ $relFilesDst = array();
+ foreach ( $srcPathsRel as $srcPathRel ) {
+ $relFilesSrc[] = $srcPathRel;
+ }
+ $dstPathsRel = $dst->getFileList( array(
+ 'dir' => $dst->getRootStoragePath() . "/$backendRel" ) );
+ if ( $dstPathsRel === null ) {
+ $this->error( "Could not list files in $container.", 1 ); // die
+ }
+ foreach ( $dstPathsRel as $dstPathRel ) {
+ $relFilesDst[] = $dstPathRel;
+ }
+ // Only copy the missing files over in the next loop
+ $srcPathsRel = array_diff( $relFilesSrc, $relFilesDst );
+ $this->output( count( $srcPathsRel ) . " file(s) need to be copied.\n" );
+ unset( $relFilesSrc );
+ unset( $relFilesDst );
+ }
+
$batchPaths = array();
foreach ( $srcPathsRel as $srcPathRel ) {
// Check up on the rate file periodically to adjust the concurrency
) {
$ops = array();
$fsFiles = array();
+ $copiedRel = array(); // for output message
foreach ( $srcPathsRel as $srcPathRel ) {
$srcPath = $src->getRootStoragePath() . "/$backendRel/$srcPathRel";
$dstPath = $dst->getRootStoragePath() . "/$backendRel/$srcPathRel";
}
$fsFiles[] = $fsFile; // keep TempFSFile objects alive as needed
// Note: prepare() is usually fast for key/value backends
- $status = $dst->prepare( array( 'dir' => dirname( $dstPath ) ) );
+ $status = $dst->prepare( array( 'dir' => dirname( $dstPath ), 'bypassReadOnly' => 1 ) );
if ( !$status->isOK() ) {
$this->error( print_r( $status->getErrorsArray(), true ) );
$this->error( "Could not copy $srcPath to $dstPath.", 1 ); // die
}
$ops[] = array( 'op' => 'store',
'src' => $fsFile->getPath(), 'dst' => $dstPath, 'overwrite' => 1 );
+ $copiedRel[] = $srcPathRel;
}
- $status = $dst->doOperations( $ops, array( 'nonJournaled' => 1 ) );
+ $t_start = microtime( true );
+ $status = $dst->doQuickOperations( $ops, array( 'bypassReadOnly' => 1 ) );
+ if ( !$status->isOK() ) {
+ sleep( 10 ); // wait and retry copy again
+ $status = $dst->doQuickOperations( $ops, array( 'bypassReadOnly' => 1 ) );
+ }
+ $ellapsed_ms = floor( ( microtime( true ) - $t_start ) * 1000 );
if ( !$status->isOK() ) {
$this->error( print_r( $status->getErrorsArray(), true ) );
$this->error( "Could not copy file batch.", 1 ); // die
- } else {
- $this->output( "Copied these file(s):\n" . implode( "\n", $srcPathsRel ) . "\n\n" );
+ } elseif ( count( $copiedRel ) ) {
+ $this->output( "\nCopied these file(s) [{$ellapsed_ms}ms]:\n" .
+ implode( "\n", $copiedRel ) . "\n\n" );
}
}
protected function filesAreSame( FileBackend $src, FileBackend $dst, $sPath, $dPath ) {
+ $skipHash = $this->hasOption( 'skiphash' );
return (
( $src->fileExists( array( 'src' => $sPath, 'latest' => 1 ) )
=== $dst->fileExists( array( 'src' => $dPath, 'latest' => 1 ) ) // short-circuit
) && ( $src->getFileSize( array( 'src' => $sPath, 'latest' => 1 ) )
=== $dst->getFileSize( array( 'src' => $dPath, 'latest' => 1 ) ) // short-circuit
- ) && ( $src->getFileSha1Base36( array( 'src' => $sPath, 'latest' => 1 ) )
+ ) && ( $skipHash || ( $src->getFileSha1Base36( array( 'src' => $sPath, 'latest' => 1 ) )
=== $dst->getFileSha1Base36( array( 'src' => $dPath, 'latest' => 1 ) )
- )
+ ) )
);
}
}