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);
}
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);
}
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.");
}
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());
}
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));
}
Aggregations