[FileBackend] Added "ratefile" option for backend copy script.
[lhc/web/wiklou.git] / maintenance / copyFileBackend.php
index 530b5ca..78ffb20 100644 (file)
@@ -42,6 +42,7 @@ class CopyFileBackend extends Maintenance {
                $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->setBatchSize( 50 );
        }
 
@@ -51,6 +52,8 @@ class CopyFileBackend extends Maintenance {
                $containers = explode( '|', $this->getOption( 'containers' ) );
                $subDir = $this->getOption( rtrim( 'subdir', '/' ), '' );
 
+               $rateFile = $this->getOption( 'ratefile' );
+
                $count = 0;
                foreach ( $containers as $container ) {
                        if ( $subDir != '' ) {
@@ -69,6 +72,11 @@ class CopyFileBackend extends Maintenance {
 
                        $batchPaths = array();
                        foreach ( $srcPathsRel as $srcPathRel ) {
+                               // Check up on the rate file periodically to adjust the concurrency
+                               if ( $rateFile && ( !$count || ( $count % 500 ) == 0 ) ) {
+                                       $this->mBatchSize = max( 1, (int)file_get_contents( $rateFile ) );
+                                       $this->output( "Batch size is now {$this->mBatchSize}.\n" );
+                               }
                                $batchPaths[$srcPathRel] = 1; // remove duplicates
                                if ( count( $batchPaths ) >= $this->mBatchSize ) {
                                        $this->copyFileBatch( array_keys( $batchPaths ), $backendRel, $src, $dst );