Quick hacky script to initialize site_stats row where missing.
[lhc/web/wiklou.git] / maintenance / dumpBackup.php
index bc4ce7a..a15fbf2 100644 (file)
@@ -22,7 +22,9 @@
  * @subpackage SpecialPage
  */
 
-$options = array( 'full', 'current' );
+$originalDir = getcwd();
+
+$optionsWithArgs = array( 'server', 'pagelist' );
 
 require_once( 'commandLine.inc' );
 require_once( 'SpecialExport.php' );
@@ -32,6 +34,8 @@ class BackupDumper {
        var $reporting = true;
        var $pageCount = 0;
        var $revCount  = 0;
+       var $server    = null; // use default
+       var $pages     = null; // all pages
        
        function BackupDumper() {
                $this->stderr = fopen( "php://stderr", "wt" );
@@ -47,13 +51,23 @@ class BackupDumper {
                
                $this->startTime = wfTime();
                
+               $dbr =& wfGetDB( DB_SLAVE );
+               $this->maxCount = $dbr->selectField( 'page', 'MAX(page_id)', '', 'BackupDumper::dump' );
+               $this->startTime = wfTime();
+               
                $db =& $this->backupDb();
                $exporter = new WikiExporter( $db, $history, MW_EXPORT_STREAM );
                $exporter->setPageCallback( array( &$this, 'reportPage' ) );
-               $exporter->setRevCallback( array( &$this, 'revCount' ) );
+               $exporter->setRevisionCallback( array( &$this, 'revCount' ) );
                
                $exporter->openStream();
-               $exporter->allPages();
+
+               if ( is_null( $this->pages ) ) {
+                       $exporter->allPages();
+               } else {
+                       $exporter->pagesByName( $this->pages );
+               }
+
                $exporter->closeStream();
                
                $this->report( true );
@@ -61,10 +75,20 @@ class BackupDumper {
        
        function &backupDb() {
                global $wgDBadminuser, $wgDBadminpassword;
-               global $wgDBserver, $wgDBname;
-               $db =& new Database( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+               global $wgDBname;
+               $db =& new Database( $this->backupServer(), $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+               $timeout = 3600 * 24;
+               $db->query( "SET net_read_timeout=$timeout" );
+               $db->query( "SET net_write_timeout=$timeout" );
                return $db;
        }
+       
+       function backupServer() {
+               global $wgDBserver;
+               return $this->server
+                       ? $this->server
+                       : $wgDBserver;
+       }
 
        function reportPage( $page ) {
                $this->pageCount++;
@@ -84,14 +108,20 @@ class BackupDumper {
        function showReport() {
                if( $this->reporting ) {
                        $delta = wfTime() - $this->startTime;
+                       $now = wfTimestamp( TS_DB );
                        if( $delta ) {
                                $rate = $this->pageCount / $delta;
                                $revrate = $this->revCount / $delta;
+                               $portion = $this->pageCount / $this->maxCount;
+                               $eta = $this->startTime + $delta / $portion;
+                               $etats = wfTimestamp( TS_DB, intval( $eta ) );
                        } else {
                                $rate = '-';
                                $revrate = '-';
+                               $etats = '-';
                        }
-                       $this->progress( "$this->pageCount ($rate pages/sec $revrate revs/sec)" );
+                       global $wgDBname;
+                       $this->progress( "$now: $wgDBname $this->pageCount, ETA $etats ($rate pages/sec $revrate revs/sec)" );
                }
        }
        
@@ -105,8 +135,25 @@ if( isset( $options['quiet'] ) ) {
        $dumper->reporting = false;
 }
 if( isset( $options['report'] ) ) {
-       $dumper->reportingInterval = IntVal( $options['report'] );
+       $dumper->reportingInterval = intval( $options['report'] );
+}
+if( isset( $options['server'] ) ) {
+       $dumper->server = $options['server'];
+}
+
+if ( isset( $options['pagelist'] ) ) {
+       $olddir = getcwd();
+       chdir( $originalDir );
+       $pages = file( $options['pagelist'] );
+       chdir( $olddir );
+       if ( $pages === false ) {
+               print "Unable to open file {$options['pagelist']}\n";
+               exit;
+       }
+       $pages = array_map( 'trim', $pages );
+       $dumper->pages = array_filter( $pages, create_function( '$x', 'return $x !== "";' ) );
 }
+
 if( isset( $options['full'] ) ) {
        $dumper->dump( MW_EXPORT_FULL );
 } elseif( isset( $options['current'] ) ) {
@@ -130,4 +177,4 @@ END
 );
 }
 
-?>
\ No newline at end of file
+?>