From dc0cff95d5c42511ca2957b7c8469831983d7e2e Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Thu, 23 Aug 2007 17:46:41 +0000
Subject: [PATCH] Expands the interfaces of backup and restore with arguments for specifying an LDAP connection that can be used to schedule these operations as tasks in addition to the current behavior of operating locally.
---
opends/src/server/org/opends/server/tools/RestoreDB.java | 115 +++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 99 insertions(+), 16 deletions(-)
diff --git a/opends/src/server/org/opends/server/tools/RestoreDB.java b/opends/src/server/org/opends/server/tools/RestoreDB.java
index 3a4b540..91b4171 100644
--- a/opends/src/server/org/opends/server/tools/RestoreDB.java
+++ b/opends/src/server/org/opends/server/tools/RestoreDB.java
@@ -41,6 +41,7 @@
import org.opends.server.api.Backend;
import org.opends.server.api.ErrorLogPublisher;
import org.opends.server.config.ConfigException;
+import static org.opends.server.config.ConfigConstants.*;
import org.opends.server.core.CoreConfigManager;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.LockFileManager;
@@ -55,17 +56,22 @@
import org.opends.server.types.InitializationException;
import org.opends.server.types.NullOutputStream;
import org.opends.server.types.RestoreConfig;
+import org.opends.server.types.RawAttribute;
import org.opends.server.util.args.ArgumentException;
-import org.opends.server.util.args.ArgumentParser;
import org.opends.server.util.args.BooleanArgument;
import org.opends.server.util.args.StringArgument;
+import org.opends.server.util.args.LDAPConnectionArgumentParser;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import static org.opends.server.tools.ToolConstants.*;
+import org.opends.server.tools.tasks.TaskTool;
import org.opends.server.admin.std.server.BackendCfg;
+import org.opends.server.protocols.asn1.ASN1OctetString;
+import org.opends.server.protocols.ldap.LDAPAttribute;
+import org.opends.server.tasks.RestoreTask;
/**
@@ -74,8 +80,8 @@
* be a process that is intended to run separate from Directory Server and not
* internally within the server process (e.g., via the tasks interface).
*/
-public class RestoreDB
-{
+public class RestoreDB extends TaskTool {
+
private static ErrorLogPublisher errorLogPublisher = null;
/**
* The main method for RestoreDB tool.
@@ -127,6 +133,24 @@
OutputStream outStream,
OutputStream errStream)
{
+ RestoreDB tool = new RestoreDB();
+ return tool.process(args, initializeServer, outStream, errStream);
+ }
+
+
+ // Define the command-line arguments that may be used with this program.
+ private BooleanArgument displayUsage = null;
+ private BooleanArgument listBackups = null;
+ private BooleanArgument verifyOnly = null;
+ private StringArgument backupIDString = null;
+ private StringArgument configClass = null;
+ private StringArgument configFile = null;
+ private StringArgument backupDirectory = null;
+
+
+ private int process(String[] args, boolean initializeServer,
+ OutputStream outStream, OutputStream errStream)
+ {
PrintStream out;
if (outStream == null)
{
@@ -147,21 +171,11 @@
err = new PrintStream(errStream);
}
- // Define the command-line arguments that may be used with this program.
- BooleanArgument displayUsage = null;
- BooleanArgument listBackups = null;
- BooleanArgument verifyOnly = null;
- StringArgument backupIDString = null;
- StringArgument configClass = null;
- StringArgument configFile = null;
- StringArgument backupDirectory = null;
-
-
// Create the command-line argument parser for use with this program.
Message toolDescription = INFO_RESTOREDB_TOOL_DESCRIPTION.get();
- ArgumentParser argParser =
- new ArgumentParser("org.opends.server.tools.RestoreDB",
- toolDescription, false);
+ LDAPConnectionArgumentParser argParser =
+ new LDAPConnectionArgumentParser("org.opends.server.tools.RestoreDB",
+ toolDescription, false);
// Initialize all the command-line argument types and register them with the
@@ -251,6 +265,75 @@
}
+ if (listBackups.isPresent() && argParser.isLdapOperation()) {
+ Message message = ERR_LDAP_CONN_INCOMPATIBLE_ARGS.get(
+ listBackups.getLongIdentifier());
+ err.println(wrapText(message, MAX_LINE_WIDTH));
+ return 1;
+ }
+
+ return process(argParser, initializeServer, out, err);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addTaskAttributes(List<RawAttribute> attributes)
+ {
+ ArrayList<ASN1OctetString> values;
+
+ if (backupDirectory.getValue() != null &&
+ !backupDirectory.getValue().equals(
+ backupDirectory.getDefaultValue())) {
+ values = new ArrayList<ASN1OctetString>(1);
+ values.add(new ASN1OctetString(backupDirectory.getValue()));
+ attributes.add(
+ new LDAPAttribute(ATTR_BACKUP_DIRECTORY_PATH, values));
+ }
+
+ if (backupIDString.getValue() != null &&
+ !backupIDString.getValue().equals(
+ backupIDString.getDefaultValue())) {
+ values = new ArrayList<ASN1OctetString>(1);
+ values.add(new ASN1OctetString(backupIDString.getValue()));
+ attributes.add(
+ new LDAPAttribute(ATTR_BACKUP_ID, values));
+ }
+
+ if (verifyOnly.getValue() != null &&
+ !verifyOnly.getValue().equals(
+ verifyOnly.getDefaultValue())) {
+ values = new ArrayList<ASN1OctetString>(1);
+ values.add(new ASN1OctetString(verifyOnly.getValue()));
+ attributes.add(
+ new LDAPAttribute(ATTR_TASK_RESTORE_VERIFY_ONLY, values));
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getTaskObjectclass() {
+ return "ds-task-restore";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Class getTaskClass() {
+ return RestoreTask.class;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected int processLocal(boolean initializeServer,
+ PrintStream out,
+ PrintStream err) {
+
+
// Perform the initial bootstrap of the Directory Server and process the
// configuration.
DirectoryServer directoryServer = DirectoryServer.getInstance();
--
Gitblit v1.10.0