Search in sources :

Example 51 with Config

use of org.neo4j.kernel.configuration.Config in project neo4j by neo4j.

the class BackupTool method runBackupWithLegacyArgs.

private BackupOutcome runBackupWithLegacyArgs(Args args) throws ToolFailureException {
    String from = args.get(FROM).trim();
    String to = args.get(TO).trim();
    Config tuningConfiguration = readConfiguration(args);
    boolean forensics = args.getBoolean(FORENSICS, false, true);
    ConsistencyCheck consistencyCheck = parseConsistencyChecker(args);
    long timeout = args.getDuration(TIMEOUT, BackupClient.BIG_READ_TIMEOUT);
    URI backupURI = resolveBackupUri(from, args);
    HostnamePort hostnamePort = newHostnamePort(backupURI);
    return executeBackup(hostnamePort, new File(to), consistencyCheck, tuningConfiguration, timeout, forensics);
}
Also used : Config(org.neo4j.kernel.configuration.Config) HostnamePort(org.neo4j.helpers.HostnamePort) URI(java.net.URI) File(java.io.File)

Example 52 with Config

use of org.neo4j.kernel.configuration.Config in project neo4j by neo4j.

the class BackupTool method runBackup.

private BackupOutcome runBackup(Args args) throws ToolFailureException {
    String host = args.get(HOST).trim();
    int port = args.getNumber(PORT, BackupServer.DEFAULT_PORT).intValue();
    String to = args.get(TO).trim();
    Config tuningConfiguration = readConfiguration(args);
    boolean forensics = args.getBoolean(FORENSICS, false, true);
    ConsistencyCheck consistencyCheck = parseConsistencyChecker(args);
    if (host.contains(":")) {
        if (!host.startsWith("[")) {
            host = "[" + host;
        }
        if (!host.endsWith("]")) {
            host += "]";
        }
    }
    long timeout = args.getDuration(TIMEOUT, BackupClient.BIG_READ_TIMEOUT);
    // a bit of validation
    URI backupURI = newURI(DEFAULT_SCHEME + "://" + host + ":" + port);
    HostnamePort hostnamePort = newHostnamePort(backupURI);
    return executeBackup(hostnamePort, new File(to), consistencyCheck, tuningConfiguration, timeout, forensics);
}
Also used : Config(org.neo4j.kernel.configuration.Config) HostnamePort(org.neo4j.helpers.HostnamePort) URI(java.net.URI) File(java.io.File)

Example 53 with Config

use of org.neo4j.kernel.configuration.Config in project neo4j by neo4j.

the class OnlineBackupCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    final HostnamePort address;
    final Path folder;
    final String name;
    final boolean fallbackToFull;
    final boolean doConsistencyCheck;
    final Optional<Path> additionalConfig;
    final Path reportDir;
    final long timeout;
    final boolean checkGraph;
    final boolean checkIndexes;
    final boolean checkLabelScanStore;
    final boolean checkPropertyOwners;
    try {
        address = toHostnamePort(new HostnamePort("localhost", 6362)).apply(arguments.parse("from", args));
        folder = arguments.parseMandatoryPath("backup-dir", args);
        name = arguments.parse("name", args);
        fallbackToFull = arguments.parseBoolean("fallback-to-full", args);
        doConsistencyCheck = arguments.parseBoolean("check-consistency", args);
        timeout = parseTimeout(args);
        additionalConfig = arguments.parseOptionalPath("additional-config", args);
        reportDir = arguments.parseOptionalPath("cc-report-dir", args).orElseThrow(() -> new IllegalArgumentException("cc-report-dir must be a path"));
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    // Make sure destination exists
    if (!outsideWorld.fileSystem().isDirectory(folder.toFile())) {
        throw new CommandFailed(String.format("Directory '%s' does not exist.", folder));
    }
    if (!outsideWorld.fileSystem().isDirectory(reportDir.toFile())) {
        throw new CommandFailed(String.format("Directory '%s' does not exist.", reportDir));
    }
    File destination = folder.resolve(name).toFile();
    Config config = loadConfig(additionalConfig);
    boolean done = false;
    try {
        // We can remove the loading from config file in 4.0
        if (arguments.has("cc-graph", args)) {
            checkGraph = arguments.parseBoolean("cc-graph", args);
        } else {
            checkGraph = ConsistencyCheckSettings.consistency_check_graph.from(config);
        }
        if (arguments.has("cc-indexes", args)) {
            checkIndexes = arguments.parseBoolean("cc-indexes", args);
        } else {
            checkIndexes = ConsistencyCheckSettings.consistency_check_indexes.from(config);
        }
        if (arguments.has("cc-label-scan-store", args)) {
            checkLabelScanStore = arguments.parseBoolean("cc-label-scan-store", args);
        } else {
            checkLabelScanStore = ConsistencyCheckSettings.consistency_check_label_scan_store.from(config);
        }
        if (arguments.has("cc-property-owners", args)) {
            checkPropertyOwners = arguments.parseBoolean("cc-property-owners", args);
        } else {
            checkPropertyOwners = ConsistencyCheckSettings.consistency_check_property_owners.from(config);
        }
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    File[] listFiles = outsideWorld.fileSystem().listFiles(destination);
    if (listFiles != null && listFiles.length > 0) {
        outsideWorld.stdOutLine("Destination is not empty, doing incremental backup...");
        try {
            backupService.doIncrementalBackup(address.getHost(), address.getPort(), destination, timeout, config);
            done = true;
        } catch (Exception e) {
            if (fallbackToFull) {
                outsideWorld.stdErrLine("Incremental backup failed: " + e.getMessage());
                String renamed = renameExistingBackup(folder, name);
                outsideWorld.stdErrLine(String.format("Old backup renamed to '%s'.", renamed));
            } else {
                throw new CommandFailed("Backup failed: " + e.getMessage(), e);
            }
        }
    }
    if (!done) {
        outsideWorld.stdOutLine("Doing full backup...");
        try {
            backupService.doFullBackup(address.getHost(), address.getPort(), destination, ConsistencyCheck.NONE, config, timeout, false);
        } catch (Exception e) {
            throw new CommandFailed("Backup failed: " + e.getMessage(), e);
        }
    }
    if (doConsistencyCheck) {
        try {
            outsideWorld.stdOutLine("Doing consistency check...");
            ConsistencyCheckService.Result ccResult = consistencyCheckService.runFullConsistencyCheck(destination, config, ProgressMonitorFactory.textual(outsideWorld.errorStream()), FormattedLogProvider.toOutputStream(outsideWorld.outStream()), outsideWorld.fileSystem(), false, reportDir.toFile(), new CheckConsistencyConfig(checkGraph, checkIndexes, checkLabelScanStore, checkPropertyOwners));
            if (!ccResult.isSuccessful()) {
                throw new CommandFailed(String.format("Inconsistencies found. See '%s' for details.", ccResult.reportFile()), STATUS_CC_INCONSISTENT);
            }
        } catch (Throwable e) {
            if (e instanceof CommandFailed) {
                throw (CommandFailed) e;
            }
            throw new CommandFailed("Failed to do consistency check on backup: " + e.getMessage(), e, STATUS_CC_ERROR);
        }
    }
    outsideWorld.stdOutLine("Backup complete.");
}
Also used : Path(java.nio.file.Path) OptionalCanonicalPath(org.neo4j.commandline.arguments.common.OptionalCanonicalPath) MandatoryCanonicalPath(org.neo4j.commandline.arguments.common.MandatoryCanonicalPath) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) Config(org.neo4j.kernel.configuration.Config) HostnamePort(org.neo4j.helpers.HostnamePort) Converters.toHostnamePort(org.neo4j.kernel.impl.util.Converters.toHostnamePort) IOException(java.io.IOException) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) CommandFailed(org.neo4j.commandline.admin.CommandFailed) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) File(java.io.File)

Example 54 with Config

use of org.neo4j.kernel.configuration.Config in project neo4j by neo4j.

the class BackupServiceIT method shouldDoFullBackupOnIncrementalFallbackToFullIfNoBackupFolderExists.

@Test
public void shouldDoFullBackupOnIncrementalFallbackToFullIfNoBackupFolderExists() throws Exception {
    // Given
    defaultBackupPortHostParams();
    Config defaultConfig = dbRule.getConfigCopy();
    dbRule.setConfig(GraphDatabaseSettings.keep_logical_logs, "false");
    GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
    BackupService backupService = backupService();
    createAndIndexNode(db, 1);
    // when
    backupService.doIncrementalBackupOrFallbackToFull(BACKUP_HOST, backupPort, backupDir.getAbsoluteFile(), ConsistencyCheck.NONE, defaultConfig, BackupClient.BIG_READ_TIMEOUT, false);
    // then
    db.shutdown();
    assertEquals(getDbRepresentation(), getBackupDbRepresentation());
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Config(org.neo4j.kernel.configuration.Config) Test(org.junit.Test)

Example 55 with Config

use of org.neo4j.kernel.configuration.Config in project neo4j by neo4j.

the class BackupToolTest method passesOnConfigurationIfProvided.

@Test
public void passesOnConfigurationIfProvided() throws Exception {
    // given
    File configFile = testDirectory.file("neo4j.conf");
    Properties properties = new Properties();
    properties.setProperty(ConsistencyCheckSettings.consistency_check_property_owners.name(), "true");
    properties.store(new FileWriter(configFile), null);
    String[] args = new String[] { "-host", "localhost", "-to", "my_backup", "-config", configFile.getPath() };
    BackupService service = mock(BackupService.class);
    PrintStream systemOut = mock(PrintStream.class);
    // when
    new BackupTool(service, systemOut).run(args);
    // then
    ArgumentCaptor<Config> config = ArgumentCaptor.forClass(Config.class);
    verify(service).doIncrementalBackupOrFallbackToFull(anyString(), anyInt(), eq(new File("my_backup")), any(ConsistencyCheck.class), config.capture(), anyLong(), eq(false));
    assertTrue(config.getValue().get(ConsistencyCheckSettings.consistency_check_property_owners));
}
Also used : PrintStream(java.io.PrintStream) Config(org.neo4j.kernel.configuration.Config) FileWriter(java.io.FileWriter) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Aggregations

Config (org.neo4j.kernel.configuration.Config)264 Test (org.junit.Test)184 File (java.io.File)54 PageCache (org.neo4j.io.pagecache.PageCache)35 InstanceId (org.neo4j.cluster.InstanceId)26 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)25 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)25 LogProvider (org.neo4j.logging.LogProvider)20 Executor (java.util.concurrent.Executor)19 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)19 Timeouts (org.neo4j.cluster.timeout.Timeouts)19 HashMap (java.util.HashMap)18 URI (java.net.URI)17 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)17 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)17 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)17 IOException (java.io.IOException)16 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)15 BoltConnector (org.neo4j.kernel.configuration.BoltConnector)15 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)15