r62760 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62759‎ | r62760 | r62761 >
Date:08:25, 21 February 2010
Author:maxsem
Status:ok
Tags:
Comment:
maintenance/sqlite.php: added an option for safe backup
Modified paths:
  • /trunk/phase3/maintenance/sqlite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/sqlite.php
@@ -28,6 +28,7 @@
2929 $this->mDescription = "Performs some operations specific to SQLite database backend";
3030 $this->addOption( 'vacuum', 'Clean up database by removing deleted pages. Decreases database file size' );
3131 $this->addOption( 'integrity', 'Check database for integrity' );
 32+ $this->addOption( 'backup-to', 'Backup database to the given file', false, true );
3233 }
3334
3435 public function execute() {
@@ -40,11 +41,17 @@
4142
4243 $this->db = wfGetDB( DB_MASTER );
4344
44 - if ( $this->hasOption( 'vacuum' ) )
 45+ if ( $this->hasOption( 'vacuum' ) ) {
4546 $this->vacuum();
 47+ }
4648
47 - if ( $this->hasOption( 'integrity' ) )
 49+ if ( $this->hasOption( 'integrity' ) ) {
4850 $this->integrityCheck();
 51+ }
 52+
 53+ if ( $this->hasOption( 'backup-to' ) ) {
 54+ $this->backup( $this->getOption( 'backup-to' ) );
 55+ }
4956 }
5057
5158 private function vacuum() {
@@ -77,6 +84,21 @@
7885 $this->output( $row->integrity_check );
7986 }
8087 }
 88+
 89+ private function backup( $fileName ) {
 90+ $this->output( "Backing up database:\n Locking..." );
 91+ $this->db->query( 'BEGIN IMMEDIATE TRANSACTION', __METHOD__ );
 92+ $ourFile = $this->db->mDatabaseFile;
 93+ $this->output( " Copying database file $ourFile to $fileName... " );
 94+ wfSuppressWarnings( false );
 95+ if ( !copy( $ourFile, $fileName ) ) {
 96+ $err = error_get_last();
 97+ $this->error( " {$err['message']}" );
 98+ }
 99+ wfSuppressWarnings( true );
 100+ $this->output( " Releasing lock...\n" );
 101+ $this->db->query( 'COMMIT TRANSACTION', __METHOD__ );
 102+ }
81103 }
82104
83105 $maintClass = "SqliteMaintenance";

Status & tagging log