Index: trunk/phase3/maintenance/sqlite.php |
— | — | @@ -28,6 +28,7 @@ |
29 | 29 | $this->mDescription = "Performs some operations specific to SQLite database backend"; |
30 | 30 | $this->addOption( 'vacuum', 'Clean up database by removing deleted pages. Decreases database file size' ); |
31 | 31 | $this->addOption( 'integrity', 'Check database for integrity' ); |
| 32 | + $this->addOption( 'backup-to', 'Backup database to the given file', false, true ); |
32 | 33 | } |
33 | 34 | |
34 | 35 | public function execute() { |
— | — | @@ -40,11 +41,17 @@ |
41 | 42 | |
42 | 43 | $this->db = wfGetDB( DB_MASTER ); |
43 | 44 | |
44 | | - if ( $this->hasOption( 'vacuum' ) ) |
| 45 | + if ( $this->hasOption( 'vacuum' ) ) { |
45 | 46 | $this->vacuum(); |
| 47 | + } |
46 | 48 | |
47 | | - if ( $this->hasOption( 'integrity' ) ) |
| 49 | + if ( $this->hasOption( 'integrity' ) ) { |
48 | 50 | $this->integrityCheck(); |
| 51 | + } |
| 52 | + |
| 53 | + if ( $this->hasOption( 'backup-to' ) ) { |
| 54 | + $this->backup( $this->getOption( 'backup-to' ) ); |
| 55 | + } |
49 | 56 | } |
50 | 57 | |
51 | 58 | private function vacuum() { |
— | — | @@ -77,6 +84,21 @@ |
78 | 85 | $this->output( $row->integrity_check ); |
79 | 86 | } |
80 | 87 | } |
| 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 | + } |
81 | 103 | } |
82 | 104 | |
83 | 105 | $maintClass = "SqliteMaintenance"; |