Restore a snapshot.
public restoreSnapshot ( string $repository, string $name, array $options = [], boolean $waitForCompletion = false ) : |
||
$repository | string | the name of the repository |
$name | string | the name of the snapshot |
$options | array | options for the restore operation |
$waitForCompletion | boolean | if true, the request will not return until the restore operation is complete |
return |
/** * @group functional */ public function testSnapshotAndRestore() { $repositoryName = 'testrepo'; $location = $this->_snapshotPath . 'backup2'; // register the repository $response = $this->_snapshot->registerRepository($repositoryName, 'fs', array('location' => $location)); $this->assertTrue($response->isOk()); // create a snapshot of our test index $snapshotName = 'test_snapshot_1'; $response = $this->_snapshot->createSnapshot($repositoryName, $snapshotName, array('indices' => $this->_index->getName()), true); // ensure that the snapshot was created properly $this->assertTrue($response->isOk()); $this->assertArrayHasKey('snapshot', $response->getData()); $data = $response->getData(); $this->assertContains($this->_index->getName(), $data['snapshot']['indices']); $this->assertEquals(1, sizeof($data['snapshot']['indices'])); // only the specified index should be present $this->assertEquals($snapshotName, $data['snapshot']['snapshot']); // retrieve data regarding the snapshot $response = $this->_snapshot->getSnapshot($repositoryName, $snapshotName); $this->assertContains($this->_index->getName(), $response['indices']); // delete our test index $this->_index->delete(); // restore the index from our snapshot $response = $this->_snapshot->restoreSnapshot($repositoryName, $snapshotName, array(), true); $this->assertTrue($response->isOk()); $this->_index->refresh(); $this->_index->optimize(); // ensure that the index has been restored $count = $this->_index->getType('test')->count(); $this->assertEquals(sizeof($this->_docs), $count); // delete the snapshot $response = $this->_snapshot->deleteSnapshot($repositoryName, $snapshotName); $this->assertTrue($response->isOk()); // ensure that the snapshot has been deleted $this->setExpectedException('Elastica\\Exception\\NotFoundException'); $this->_snapshot->getSnapshot($repositoryName, $snapshotName); }
public function testSnapshotAndRestore() { $repositoryName = "test_repository"; $location = "/tmp/{$repositoryName}"; // register the repository $response = $this->_snapshot->registerRepository($repositoryName, "fs", array("location" => $location)); $this->assertTrue($response->isOk()); // create a snapshot of our test index $snapshotName = "test_snapshot_1"; $response = $this->_snapshot->createSnapshot($repositoryName, $snapshotName, array("indices" => $this->_index->getName()), true); // ensure that the snapshot was created properly $this->assertTrue($response->isOk()); $this->assertArrayHasKey("snapshot", $response->getData()); $data = $response->getData(); $this->assertContains($this->_index->getName(), $data["snapshot"]["indices"]); $this->assertEquals(1, sizeof($data["snapshot"]["indices"])); // only the specified index should be present $this->assertEquals($snapshotName, $data["snapshot"]["snapshot"]); // retrieve data regarding the snapshot $response = $this->_snapshot->getSnapshot($repositoryName, $snapshotName); $this->assertContains($this->_index->getName(), $response["indices"]); // delete our test index $this->_index->delete(); // restore the index from our snapshot $response = $this->_snapshot->restoreSnapshot($repositoryName, $snapshotName, array(), true); $this->assertTrue($response->isOk()); $this->_index->refresh(); $this->_index->optimize(); // ensure that the index has been restored $count = $this->_index->getType("test")->count(); $this->assertEquals(sizeof($this->_docs), $count); // delete the snapshot $response = $this->_snapshot->deleteSnapshot($repositoryName, $snapshotName); $this->assertTrue($response->isOk()); // ensure that the snapshot has been deleted $this->setExpectedException('Elastica\\Exception\\NotFoundException'); $this->_snapshot->getSnapshot($repositoryName, $snapshotName); }
/** * ATTENTION cette méthode supprime l'index ElasticSearch * Par prudence il faut mettre les booléens à oui. * * @param string $repositoryName Le nom du répertoire du snapshot * @param string $snapshotName Le nom du snapshot * @param bool $delete_index Suppression de l'index [DEFAULT = FALSE] * @param bool $restore Restoration de l'index à partir du snapshot [DEFAULT = FALSE] * * @return void */ public function deleteIndexAndRestore($repositoryName, $snapshotName, $delete_index = false, $restore = false) { $this->loadIndex(); if ($delete_index) { // delete our index $this->deleteIndexSnapshot(); } if ($restore) { // restore the index from our snapshot $this->_snapshot->restoreSnapshot($repositoryName, $snapshotName, array(), true); // mbtrace if it's ok $this->_index->refresh(); $this->_index->optimize(); } }