From 8ddc62d2e8c43f31f9029f631d8dc2623d2f2415 Mon Sep 17 00:00:00 2001 From: Anton Klaren Date: Fri, 23 Mar 2018 09:07:21 +0100 Subject: [PATCH] Include hostname in report filename --- .../commandline/dbms/DiagnosticsReportCommand.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/community/dbms/src/main/java/org/neo4j/commandline/dbms/DiagnosticsReportCommand.java b/community/dbms/src/main/java/org/neo4j/commandline/dbms/DiagnosticsReportCommand.java index 7f127e776bf4..e5c211b24078 100644 --- a/community/dbms/src/main/java/org/neo4j/commandline/dbms/DiagnosticsReportCommand.java +++ b/community/dbms/src/main/java/org/neo4j/commandline/dbms/DiagnosticsReportCommand.java @@ -25,6 +25,8 @@ import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.nio.file.Path; import java.text.SimpleDateFormat; import java.util.Date; @@ -117,8 +119,7 @@ public void execute( String[] stringArgs ) throws IncorrectUsage, CommandFailed Path destinationDir = new File( destinationArgument.parse( args ) ).toPath(); try { - SimpleDateFormat dumpFormat = new SimpleDateFormat( "yyyy-MM-dd_HHmmss" ); - Path reportFile = destinationDir.resolve( dumpFormat.format( new Date() ) + ".zip" ); + Path reportFile = destinationDir.resolve( getDefaultFilename() ); out.println( "Writing report to " + reportFile.toAbsolutePath().toString() ); reporter.dump( classifiers.get(), reportFile, progress, force ); } @@ -128,6 +129,14 @@ public void execute( String[] stringArgs ) throws IncorrectUsage, CommandFailed } } + private String getDefaultFilename() throws UnknownHostException + { + String hostName = InetAddress.getLocalHost().getHostName(); + String safeFilename = hostName.replaceAll( "[^a-zA-Z0-9._]+", "_" ); + SimpleDateFormat dumpFormat = new SimpleDateFormat( "yyyy-MM-dd_HHmmss" ); + return safeFilename + "-" + dumpFormat.format( new Date() ) + ".zip"; + } + private DiagnosticsReporterProgress buildProgress() { DiagnosticsReporterProgress progress;