Merge "Fix order of expected, actual in some tests"
[lhc/web/wiklou.git] / maintenance / syncFileBackend.php
index 158019b..aade17e 100644 (file)
@@ -21,7 +21,7 @@
  * @ingroup Maintenance
  */
 
-require_once( __DIR__ . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
 
 /**
  * Maintenance script that syncs one file backend to another based on
@@ -40,6 +40,7 @@ class SyncFileBackend extends Maintenance {
                $this->addOption( 'posdir', 'Directory to read/record journal positions', false, true );
                $this->addOption( 'posdump', 'Just dump current journal position into the position dir.' );
                $this->addOption( 'postime', 'For position dumps, get the ID at this time', false, true );
+               $this->addOption( 'backoff', 'Stop at entries younger than this age (sec).', false, true );
                $this->addOption( 'verbose', 'Verbose mode', false, false, 'v' );
                $this->setBatchSize( 50 );
        }
@@ -88,7 +89,13 @@ class SyncFileBackend extends Maintenance {
                } else {
                        $startFromPosFile = false;
                }
-               $end = $this->getOption( 'end', INF );
+
+               if ( $this->hasOption( 'backoff' ) ) {
+                       $time = time() - $this->getOption( 'backoff', 0 );
+                       $end = (int)$src->getJournal()->getPositionAtTime( $time );
+               } else {
+                       $end = $this->getOption( 'end', INF );
+               }
 
                $this->output( "Synchronizing backend '{$dst->getName()}' to '{$src->getName()}'...\n" );
                $this->output( "Starting journal position is $start.\n" );
@@ -214,6 +221,9 @@ class SyncFileBackend extends Maintenance {
                        return $status;
                }
 
+               $src->preloadFileStat( array( 'srcs' => $sPaths, 'latest' => 1 ) );
+               $dst->preloadFileStat( array( 'srcs' => $dPaths, 'latest' => 1 ) );
+
                $ops = array();
                $fsFiles = array();
                foreach ( $sPaths as $i => $sPath ) {
@@ -289,4 +299,4 @@ class SyncFileBackend extends Maintenance {
 }
 
 $maintClass = "SyncFileBackend";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;