murblanc commented on a change in pull request #2250: URL: https://github.com/apache/lucene-solr/pull/2250#discussion_r580587364
########## File path: solr/core/src/java/org/apache/solr/cloud/api/collections/BackupCmd.java ########## @@ -77,74 +80,110 @@ public void call(ClusterState state, ZkNodeProps message, @SuppressWarnings({"ra } String backupName = message.getStr(NAME); String repo = message.getStr(CoreAdminParams.BACKUP_REPOSITORY); + boolean incremental = message.getBool(CoreAdminParams.BACKUP_INCREMENTAL, true); + String configName = ocmh.zkStateReader.readConfigName(collectionName); - Instant startTime = Instant.now(); + BackupProperties backupProperties = BackupProperties.create(backupName, collectionName, + extCollectionName, configName); CoreContainer cc = ocmh.overseer.getCoreContainer(); - BackupRepository repository = cc.newBackupRepository(repo); - BackupManager backupMgr = new BackupManager(repository, ocmh.zkStateReader); + try (BackupRepository repository = cc.newBackupRepository(repo)) { + + // Backup location + URI location = repository.createURI(message.getStr(CoreAdminParams.BACKUP_LOCATION)); + final URI backupPath = createAndValidateBackupPath(repository, incremental, location, backupName, collectionName); + + BackupManager backupMgr = (incremental) ? + BackupManager.forIncrementalBackup(repository, ocmh.zkStateReader, backupPath) : + BackupManager.forBackup(repository, ocmh.zkStateReader, backupPath); + + String strategy = message.getStr(CollectionAdminParams.INDEX_BACKUP_STRATEGY, CollectionAdminParams.COPY_FILES_STRATEGY); + switch (strategy) { + case CollectionAdminParams.COPY_FILES_STRATEGY: { + if (incremental) { + try { + incrementalCopyIndexFiles(backupPath, collectionName, message, results, backupProperties, backupMgr); + } catch (SolrException e) { + log.error("Error happened during incremental backup for collection:{}", collectionName, e); + ocmh.cleanBackup(repository, backupPath, backupMgr.getBackupId()); + throw e; + } + } else { + copyIndexFiles(backupPath, collectionName, message, results); + } + break; + } + case CollectionAdminParams.NO_INDEX_BACKUP_STRATEGY: { + break; + } + } - // Backup location - URI location = repository.createURI(message.getStr(CoreAdminParams.BACKUP_LOCATION)); - URI backupPath = repository.resolve(location, backupName); + log.info("Starting to backup ZK data for backupName={}", backupName); - //Validating if the directory already exists. - if (repository.exists(backupPath)) { - throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "The backup directory already exists: " + backupPath); - } + //Download the configs + backupMgr.downloadConfigDir(configName); - // Create a directory to store backup details. - repository.createDirectory(backupPath); + //Save the collection's state. Can be part of the monolithic clusterstate.json or a individual state.json Review comment: There's no such thing anymore in master as a "monolithic `clusterstate.json`". It was removed in [SOLR-12823](https://issues.apache.org/jira/browse/SOLR-12823) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org