Java Code Examples for org.apache.solr.client.solrj.request.CollectionAdminRequest#Backup

The following examples show how to use org.apache.solr.client.solrj.request.CollectionAdminRequest#Backup . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrSnapshotsTool.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void exportSnapshot(String collectionName, String snapshotName, String destPath, Optional<String> backupRepo,
    Optional<String> asyncReqId) {
  try {
    CollectionAdminRequest.Backup backup = new CollectionAdminRequest.Backup(collectionName, snapshotName);
    backup.setCommitName(snapshotName);
    backup.setIndexBackupStrategy(CollectionAdminParams.COPY_FILES_STRATEGY);
    backup.setLocation(destPath);
    if (backupRepo.isPresent()) {
      backup.setRepositoryName(backupRepo.get());
    }
    // if asyncId is null, processAsync will block and throw an Exception with any error
    backup.processAsync(asyncReqId.orElse(null), solrClient);
  } catch (Exception e) {
    log.error("Failed to backup collection meta-data for collection {}", collectionName, e);
    CLIO.out("Failed to backup collection meta-data for collection " + collectionName
        + " due to following error : " + e.getLocalizedMessage());
    System.exit(1);
  }
}
 
Example 2
Source File: SolrSnapshotsTool.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void backupCollectionMetaData(String collectionName, String snapshotName, String backupLoc) throws SolrServerException, IOException {
  // Backup the collection meta-data
  CollectionAdminRequest.Backup backup = new CollectionAdminRequest.Backup(collectionName, snapshotName);
  backup.setIndexBackupStrategy(CollectionAdminParams.NO_INDEX_BACKUP_STRATEGY);
  backup.setLocation(backupLoc);
  CollectionAdminResponse resp = backup.process(solrClient);
  Preconditions.checkState(resp.getStatus() == 0, "The request failed. The status code is " + resp.getStatus());
}
 
Example 3
Source File: TestHdfsCloudBackupRestore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void testConfigBackupOnly(String configName, String collectionName) throws Exception {
  String backupName = "configonlybackup";
  CloudSolrClient solrClient = cluster.getSolrClient();

  CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(collectionName, backupName)
      .setRepositoryName(getBackupRepoName())
      .setIndexBackupStrategy(CollectionAdminParams.NO_INDEX_BACKUP_STRATEGY);
  backup.process(solrClient);

  Map<String,String> params = new HashMap<>();
  params.put("location", "/backup");
  params.put("solr.hdfs.home", hdfsUri + "/solr");

  HdfsBackupRepository repo = new HdfsBackupRepository();
  repo.init(new NamedList<>(params));
  BackupManager mgr = new BackupManager(repo, solrClient.getZkStateReader());

  URI baseLoc = repo.createURI("/backup");

  Properties props = mgr.readBackupProperties(baseLoc, backupName);
  assertNotNull(props);
  assertEquals(collectionName, props.getProperty(COLLECTION_NAME_PROP));
  assertEquals(backupName, props.getProperty(BACKUP_NAME_PROP));
  assertEquals(configName, props.getProperty(COLL_CONF));

  DocCollection collectionState = mgr.readCollectionState(baseLoc, backupName, collectionName);
  assertNotNull(collectionState);
  assertEquals(collectionName, collectionState.getName());

  URI configDirLoc = repo.resolve(baseLoc, backupName, ZK_STATE_DIR, CONFIG_STATE_DIR, configName);
  assertTrue(repo.exists(configDirLoc));

  Collection<String> expected = Arrays.asList(BACKUP_PROPS_FILE, ZK_STATE_DIR);
  URI backupLoc = repo.resolve(baseLoc, backupName);
  String[] dirs = repo.listAll(backupLoc);
  for (String d : dirs) {
    assertTrue(expected.contains(d));
  }
}
 
Example 4
Source File: TestLocalFSCloudBackupRestore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void errorBackup(CloudSolrClient solrClient)
    throws SolrServerException, IOException {
  CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(getCollectionName(), "poisionedbackup")
      .setLocation(getBackupLocation());
  if (random().nextBoolean()) {
    backup.setRepositoryName(poisioned);
  } // otherwise we hit default
  
  try {
    backup.process(solrClient);
    fail("This request should have failed since omitting repo, picks up default poisioned.");
  } catch (SolrException ex) {
    assertEquals(ErrorCode.SERVER_ERROR.code, ex.code());
  }
}
 
Example 5
Source File: AbstractCloudBackupRestoreTestCase.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testRestoreFailure() throws Exception {
  setTestSuffix("testfailure");
  replFactor = TestUtil.nextInt(random(), 1, 2);
  numTlogReplicas = TestUtil.nextInt(random(), 0, 1);
  numPullReplicas = TestUtil.nextInt(random(), 0, 1);

  CollectionAdminRequest.Create create =
      CollectionAdminRequest.createCollection(getCollectionName(), "conf1", NUM_SHARDS, replFactor, numTlogReplicas, numPullReplicas);

  if (NUM_SHARDS * (replFactor + numTlogReplicas + numPullReplicas) > cluster.getJettySolrRunners().size()) {
    create.setMaxShardsPerNode((int)Math.ceil(NUM_SHARDS * (replFactor + numTlogReplicas + numPullReplicas) / cluster.getJettySolrRunners().size())); //just to assert it survives the restoration
  }

  CloudSolrClient solrClient = cluster.getSolrClient();
  create.process(solrClient);

  indexDocs(getCollectionName(), false);


  String backupLocation = getBackupLocation();
  String backupName = BACKUPNAME_PREFIX + testSuffix;

  DocCollection backupCollection = solrClient.getZkStateReader().getClusterState().getCollection(getCollectionName());

  log.info("Triggering Backup command");

  {
    CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(getCollectionName(), backupName)
        .setLocation(backupLocation).setRepositoryName(getBackupRepoName());
    assertEquals(0, backup.process(solrClient).getStatus());
  }

  log.info("Triggering Restore command");

  String restoreCollectionName = getCollectionName() + "_restored";

  {
    CollectionAdminRequest.Restore restore = CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
        .setLocation(backupLocation).setRepositoryName(getBackupRepoName());
    if (backupCollection.getReplicas().size() > cluster.getJettySolrRunners().size()) {
      // may need to increase maxShardsPerNode (e.g. if it was shard split, then now we need more)
      restore.setMaxShardsPerNode((int)Math.ceil(backupCollection.getReplicas().size()/cluster.getJettySolrRunners().size()));
    }

    restore.setConfigName("confFaulty");
    assertEquals(RequestStatusState.FAILED, restore.processAndWait(solrClient, 30));
    assertThat("Failed collection is still in the clusterstate: " + cluster.getSolrClient().getClusterStateProvider().getClusterState().getCollectionOrNull(restoreCollectionName), 
        CollectionAdminRequest.listCollections(solrClient), not(hasItem(restoreCollectionName)));
  }
}