Search in sources :

Example 1 with LocalFileRestorer

use of com.instaclustr.esop.local.LocalFileRestorer in project esop by instaclustr.

the class LocalBackupTest method testDownload.

@Test
public void testDownload() throws Exception {
    try {
        RestoreOperationRequest restoreOperationRequest = new RestoreOperationRequest();
        FileUtils.createDirectory(Paths.get(target("backup1") + "/cluster/test-dc/1/manifests").toAbsolutePath());
        restoreOperationRequest.storageLocation = new StorageLocation("file://" + target("backup1") + "/cluster/test-dc/1");
        Files.write(Paths.get("target/backup1/cluster/test-dc/1/manifests/snapshot-name-" + UUID.randomUUID().toString()).toAbsolutePath(), "hello".getBytes(), StandardOpenOption.CREATE_NEW);
        LocalFileRestorer localFileRestorer = new LocalFileRestorer(restoreOperationRequest);
        final Path downloadedFile = localFileRestorer.downloadNodeFileToDir(Paths.get("/tmp"), Paths.get("manifests"), s -> s.contains("snapshot-name-"));
        assertTrue(Files.exists(downloadedFile));
    } finally {
        deleteDirectory(Paths.get(target("backup1")));
        deleteDirectory(Paths.get(target("commitlog_download_dir")));
    }
}
Also used : Path(java.nio.file.Path) LocalFileRestorer(com.instaclustr.esop.local.LocalFileRestorer) RestoreOperationRequest(com.instaclustr.esop.impl.restore.RestoreOperationRequest) StorageLocation(com.instaclustr.esop.impl.StorageLocation) Test(org.testng.annotations.Test) AbstractBackupTest(com.instaclustr.esop.backup.embedded.AbstractBackupTest)

Example 2 with LocalFileRestorer

use of com.instaclustr.esop.local.LocalFileRestorer in project esop by instaclustr.

the class ListOperation method run0.

@Override
protected void run0() throws Exception {
    assert restorerFactoryMap != null;
    assert objectMapper != null;
    request.storageLocation.validate();
    Path localPath = request.cacheDir;
    if (!request.skipDownload && !Files.exists(localPath)) {
        FileUtils.createDirectory(localPath);
    }
    if (request.resolveNodes) {
        assert cassandraJMXService != null;
        CassandraSimpleTopologyResult simpleTopology = new CassandraSimpleTopology(cassandraJMXService).act();
        request.storageLocation = StorageLocation.update(request.storageLocation, simpleTopology.getClusterName(), simpleTopology.getDc(), simpleTopology.getHostId());
    }
    try (final StorageInteractor interactor = restorerFactoryMap.get(request.storageLocation.storageProvider).createListingInteractor(request)) {
        interactor.update(request.storageLocation, new LocalFileRestorer(getForLocalListing(request, request.cacheDir, request.storageLocation), objectMapper));
        final AllManifestsReport report = AllManifestsReport.report(interactor.listManifests());
        filterFromTimestamp(report, request.fromTimestamp);
        filterLastN(report, request.lastN);
        if (request.toRequest) {
            request.response = report;
        } else {
            try (final PrintStream ps = getOutputStream(request)) {
                print(report, request, ps);
            }
        }
    } catch (final Exception ex) {
        logger.error("Unable to perform listing! - " + ex.getMessage(), ex);
        this.addError(Error.from(ex));
    }
}
Also used : Path(java.nio.file.Path) CassandraSimpleTopology(com.instaclustr.esop.topology.CassandraSimpleTopology) PrintStream(java.io.PrintStream) CassandraSimpleTopologyResult(com.instaclustr.esop.topology.CassandraSimpleTopology.CassandraSimpleTopologyResult) StorageInteractor(com.instaclustr.esop.impl.StorageInteractor) LocalFileRestorer(com.instaclustr.esop.local.LocalFileRestorer) AllManifestsReport(com.instaclustr.esop.impl.Manifest.AllManifestsReport)

Example 3 with LocalFileRestorer

use of com.instaclustr.esop.local.LocalFileRestorer in project esop by instaclustr.

the class RemoveBackupOperation method run0.

@Override
protected void run0() throws Exception {
    assert restorerFactoryMap != null;
    assert objectMapper != null;
    request.validate(null);
    if (request.resolveNodes) {
        assert cassandraJMXService != null;
        CassandraSimpleTopologyResult simpleTopology = new CassandraSimpleTopology(cassandraJMXService).act();
        request.storageLocation = StorageLocation.update(request.storageLocation, simpleTopology.getClusterName(), simpleTopology.getDc(), simpleTopology.getHostId());
    }
    try (final StorageInteractor interactor = restorerFactoryMap.get(request.storageLocation.storageProvider).createDeletingInteractor(request)) {
        interactor.update(request.storageLocation, new LocalFileRestorer(getForLocalListing(request, request.cacheDir, request.storageLocation), objectMapper));
        for (final StorageLocation nodeLocation : getStorageLocations(interactor)) {
            logger.info("Looking for backups to delete for node {}", nodeLocation.nodePath());
            request.storageLocation = nodeLocation;
            interactor.update(nodeLocation, new LocalFileRestorer(getForLocalListing(request, request.cacheDir, request.storageLocation), objectMapper));
            final Optional<AllManifestsReport> reportOptional = getReport(interactor);
            if (!reportOptional.isPresent()) {
                logger.info("No backups found for {}", nodeLocation.nodePath());
                continue;
            }
            final AllManifestsReport report = reportOptional.get();
            logger.debug(report.toString());
            final List<ManifestReport> allBackupsToDelete = getBackupsToDelete(report);
            if (allBackupsToDelete.isEmpty()) {
                if (request.backupName != null) {
                    logger.info("There is not any {} backup to remove for node {}", request.backupName, nodeLocation);
                } else {
                    logger.info("There is not any backup to remove for node {}", nodeLocation);
                }
                continue;
            }
            logger.info("Removing backups for node {}: {}", nodeLocation.nodePath(), allBackupsToDelete.stream().map(mr -> mr.name).collect(Collectors.joining(",")));
            for (final ManifestReport mr : allBackupsToDelete) {
                interactor.delete(mr, request);
            }
        }
        if (!request.dry) {
            interactor.deleteTopology(request.backupName);
        } else {
            logger.info("Deletion of topology for {} was executed in dry mode", request.backupName);
        }
    } catch (final Exception ex) {
        logger.error("Unable to perform backup deletion! - " + ex.getMessage(), ex);
        this.addError(Error.from(ex));
    }
}
Also used : CassandraSimpleTopology(com.instaclustr.esop.topology.CassandraSimpleTopology) CassandraSimpleTopologyResult(com.instaclustr.esop.topology.CassandraSimpleTopology.CassandraSimpleTopologyResult) StorageInteractor(com.instaclustr.esop.impl.StorageInteractor) LocalFileRestorer(com.instaclustr.esop.local.LocalFileRestorer) ManifestReport(com.instaclustr.esop.impl.Manifest.ManifestReporter.ManifestReport) AllManifestsReport(com.instaclustr.esop.impl.Manifest.AllManifestsReport) StorageLocation(com.instaclustr.esop.impl.StorageLocation)

Aggregations

LocalFileRestorer (com.instaclustr.esop.local.LocalFileRestorer)3 AllManifestsReport (com.instaclustr.esop.impl.Manifest.AllManifestsReport)2 StorageInteractor (com.instaclustr.esop.impl.StorageInteractor)2 StorageLocation (com.instaclustr.esop.impl.StorageLocation)2 CassandraSimpleTopology (com.instaclustr.esop.topology.CassandraSimpleTopology)2 CassandraSimpleTopologyResult (com.instaclustr.esop.topology.CassandraSimpleTopology.CassandraSimpleTopologyResult)2 Path (java.nio.file.Path)2 AbstractBackupTest (com.instaclustr.esop.backup.embedded.AbstractBackupTest)1 ManifestReport (com.instaclustr.esop.impl.Manifest.ManifestReporter.ManifestReport)1 RestoreOperationRequest (com.instaclustr.esop.impl.restore.RestoreOperationRequest)1 PrintStream (java.io.PrintStream)1 Test (org.testng.annotations.Test)1