Chad has uploaded a new change for review. https://gerrit.wikimedia.org/r/123115
Change subject: Make it possible to take snapshots of your index ...................................................................... Make it possible to take snapshots of your index Change-Id: I7aa718c5b5f9b24deb3c2fb86a8c3314be3b5720 --- M CirrusSearch.php A maintenance/backupIndexes.php 2 files changed, 94 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch refs/changes/15/123115/1 diff --git a/CirrusSearch.php b/CirrusSearch.php index c410344..b9b84ce 100644 --- a/CirrusSearch.php +++ b/CirrusSearch.php @@ -257,6 +257,17 @@ // How long to cache interwiki search results for (in seconds) $wgCirrusSearchInterwikiCacheTime = 7200; +// Configuration for backups, array format is as follows: +// array( +// 'my_backups' => array( 'type' => 'fs', 'location' => '/bar/baz/' ) +// ) +// +// See the Elasticsearch configuration for more settings you can give, note +// that type and location are required. +$wgCirrusSearchBackup = array( + 'my_backups' => array( 'type' => 'fs', 'location' => '/a/search-bak/' ) +); + $includes = __DIR__ . "/includes/"; $buildDocument = $includes . 'BuildDocument/'; /** diff --git a/maintenance/backupIndexes.php b/maintenance/backupIndexes.php new file mode 100644 index 0000000..3ec7464 --- /dev/null +++ b/maintenance/backupIndexes.php @@ -0,0 +1,83 @@ +<?php + +namespace CirrusSearch; +use \Maintenance; + +/** + * Check the number of documents in the search index against the number of pages + * in SiteStats. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +$IP = getenv( 'MW_INSTALL_PATH' ); +if( $IP === false ) { + $IP = __DIR__ . '/../../..'; +} +require_once( "$IP/maintenance/Maintenance.php" ); + +class BackupIndexes extends Maintenance { + public function __construct() { + parent::__construct(); + $this->mDescription = "Backup and restore indexes using the snapshot/restore feature of Elastic"; + $this->addOption( 'all', 'Backup all indexes, not just the one for this wiki' ); + $this->addOption( 'baseName', 'Base name of index, defaults to wiki id. Cannot be used with --all', false, true ); + $this->addOption( 'backupName', 'Name of the backup, otherwise defaults to cirrus-$timestamp', false, true ); + } + + public function execute() { + global $wgCirrusSearchBackup; + + if ( !$wgCirrusSearchBackup ) { + $this->output( "No backups configured, see \$wgCirrusSearchBackup\n" ); + return; + } + + $snapshot = new \Elastica\Snapshot( Connection::getClient() ); + foreach ( $wgCirrusSearchBackup as $name => $settings ) { + $this->maybeSetupRepo( $snapshot, $name, $settings ); + $this->backup( $snapshot, $name ); + } + } + + private function maybeSetupRepo( $snapshot, $name, $settings ) { + try { + $snapshot->getRepository( $name ); + } catch ( \Elastica\Exception\NotFoundException $e ) { + $this->output( "Backup repo '$name' does not exist, creating..." ); + $type = $settings['type']; + unset( $settings['type'] ); + $snapshot->registerRepository( $name, $type, $settings ); + $this->output( "done.\n" ); + } + } + + private function backup( $snapshot, $name ) { + $backupName = $this->getOption( 'backupName', 'cirrus-' . time() ); + $options = array( + 'ignore_unavailable' => true, + ); + if ( !$this->hasOption( 'all' ) ) { + $options['indices'] = $this->getOption( 'baseName', wfWikiId() ); + } + $this->output( "Creating snapshot '$backupName'..." ); + $snapshot->createSnapshot( $name, $backupName, $options, true ); + $this->output( "done.\n" ); + } +} + +$maintClass = "CirrusSearch\BackupIndexes"; +require_once RUN_MAINTENANCE_IF_MAIN; -- To view, visit https://gerrit.wikimedia.org/r/123115 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7aa718c5b5f9b24deb3c2fb86a8c3314be3b5720 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: master Gerrit-Owner: Chad <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
