| | |
| | | |
| | | |
| | | |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | import java.text.DateFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | |
| | | import org.opends.server.types.ErrorLogCategory; |
| | | import org.opends.server.types.ErrorLogSeverity; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.NullOutputStream; |
| | | import org.opends.server.types.RestoreConfig; |
| | | import org.opends.server.util.args.ArgumentException; |
| | | import org.opends.server.util.args.ArgumentParser; |
| | |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | int retCode = mainRestoreDB(args); |
| | | int retCode = mainRestoreDB(args, true, System.out, System.err); |
| | | |
| | | if(errorLogPublisher != null) |
| | | { |
| | |
| | | */ |
| | | public static int mainRestoreDB(String[] args) |
| | | { |
| | | return mainRestoreDB(args, true); |
| | | return mainRestoreDB(args, true, System.out, System.err); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param args The command-line arguments provided to this |
| | | * program. |
| | | * @param initializeServer Indicates whether to initialize the server. |
| | | * @param outStream The output stream to use for standard output, or |
| | | * {@code null} if standard output is not needed. |
| | | * @param errStream The output stream to use for standard error, or |
| | | * {@code null} if standard error is not needed. |
| | | * |
| | | * @return The error code. |
| | | */ |
| | | public static int mainRestoreDB(String[] args, boolean initializeServer) |
| | | public static int mainRestoreDB(String[] args, boolean initializeServer, |
| | | OutputStream outStream, |
| | | OutputStream errStream) |
| | | { |
| | | PrintStream out; |
| | | if (outStream == null) |
| | | { |
| | | out = NullOutputStream.printStream(); |
| | | } |
| | | else |
| | | { |
| | | out = new PrintStream(outStream); |
| | | } |
| | | |
| | | PrintStream err; |
| | | if (errStream == null) |
| | | { |
| | | err = NullOutputStream.printStream(); |
| | | } |
| | | else |
| | | { |
| | | err = new PrintStream(errStream); |
| | | } |
| | | |
| | | // Define the command-line arguments that may be used with this program. |
| | | BooleanArgument displayUsage = null; |
| | | BooleanArgument listBackups = null; |
| | |
| | | int msgID = MSGID_CANNOT_INITIALIZE_ARGS; |
| | | String message = getMessage(msgID, ae.getMessage()); |
| | | |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | int msgID = MSGID_ERROR_PARSING_ARGS; |
| | | String message = getMessage(msgID, ae.getMessage()); |
| | | |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | System.err.println(argParser.getUsage()); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(argParser.getUsage()); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | { |
| | | int msgID = MSGID_SERVER_BOOTSTRAP_ERROR; |
| | | String message = getMessage(msgID, getExceptionMessage(e)); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | { |
| | | int msgID = MSGID_CANNOT_LOAD_CONFIG; |
| | | String message = getMessage(msgID, ie.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_CANNOT_LOAD_CONFIG; |
| | | String message = getMessage(msgID, getExceptionMessage(e)); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | { |
| | | int msgID = MSGID_CANNOT_LOAD_SCHEMA; |
| | | String message = getMessage(msgID, ce.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | catch (InitializationException ie) |
| | | { |
| | | int msgID = MSGID_CANNOT_LOAD_SCHEMA; |
| | | String message = getMessage(msgID, ie.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_CANNOT_LOAD_SCHEMA; |
| | | String message = getMessage(msgID, getExceptionMessage(e)); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | { |
| | | int msgID = MSGID_CANNOT_INITIALIZE_CORE_CONFIG; |
| | | String message = getMessage(msgID, ce.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | catch (InitializationException ie) |
| | | { |
| | | int msgID = MSGID_CANNOT_INITIALIZE_CORE_CONFIG; |
| | | String message = getMessage(msgID, ie.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_CANNOT_INITIALIZE_CORE_CONFIG; |
| | | String message = getMessage(msgID, getExceptionMessage(e)); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | { |
| | | int msgID = MSGID_CANNOT_INITIALIZE_CRYPTO_MANAGER; |
| | | String message = getMessage(msgID, ce.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | catch (InitializationException ie) |
| | | { |
| | | int msgID = MSGID_CANNOT_INITIALIZE_CRYPTO_MANAGER; |
| | | String message = getMessage(msgID, ie.getMessage()); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_CANNOT_INITIALIZE_CRYPTO_MANAGER; |
| | | String message = getMessage(msgID, getExceptionMessage(e)); |
| | | System.err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | err.println(wrapText(message, MAX_LINE_WIDTH)); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | { |
| | | errorLogPublisher = |
| | | new ThreadFilterTextErrorLogPublisher(Thread.currentThread(), |
| | | new TextWriter.STDOUT()); |
| | | new TextWriter.STREAM(out)); |
| | | ErrorLogger.addErrorLogPublisher(errorLogPublisher); |
| | | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | System.err.println("Error installing the custom error logger: " + |
| | | stackTraceToSingleLineString(e)); |
| | | err.println("Error installing the custom error logger: " + |
| | | stackTraceToSingleLineString(e)); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | int msgID = MSGID_RESTOREDB_LIST_BACKUP_ID; |
| | | String message = getMessage(msgID, backupInfo.getBackupID()); |
| | | System.out.println(message); |
| | | out.println(message); |
| | | |
| | | msgID = MSGID_RESTOREDB_LIST_BACKUP_DATE; |
| | | message = getMessage(msgID, |
| | | dateFormat.format(backupInfo.getBackupDate())); |
| | | System.out.println(message); |
| | | out.println(message); |
| | | |
| | | msgID = MSGID_RESTOREDB_LIST_INCREMENTAL; |
| | | message = getMessage(msgID, String.valueOf(backupInfo.isIncremental())); |
| | | System.out.println(message); |
| | | out.println(message); |
| | | |
| | | msgID = MSGID_RESTOREDB_LIST_COMPRESSED; |
| | | message = getMessage(msgID, String.valueOf(backupInfo.isCompressed())); |
| | | System.out.println(message); |
| | | out.println(message); |
| | | |
| | | msgID = MSGID_RESTOREDB_LIST_ENCRYPTED; |
| | | message = getMessage(msgID, String.valueOf(backupInfo.isEncrypted())); |
| | | System.out.println(message); |
| | | out.println(message); |
| | | |
| | | byte[] hash = backupInfo.getUnsignedHash(); |
| | | msgID = MSGID_RESTOREDB_LIST_HASHED; |
| | | message = getMessage(msgID, String.valueOf(hash != null)); |
| | | System.out.println(message); |
| | | out.println(message); |
| | | |
| | | byte[] signature = backupInfo.getSignedHash(); |
| | | msgID = MSGID_RESTOREDB_LIST_SIGNED; |
| | | message = getMessage(msgID, String.valueOf(signature != null)); |
| | | System.out.println(message); |
| | | out.println(message); |
| | | |
| | | StringBuilder dependencyList = new StringBuilder(); |
| | | HashSet<String> dependencyIDs = backupInfo.getDependencies(); |
| | |
| | | |
| | | msgID = MSGID_RESTOREDB_LIST_DEPENDENCIES; |
| | | message = getMessage(msgID, dependencyList.toString()); |
| | | System.out.println(message); |
| | | out.println(message); |
| | | |
| | | System.out.println(); |
| | | out.println(); |
| | | } |
| | | |
| | | return 1; |