ExportLDIF.java revision 4289
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
*/
/**
* This program provides a utility that may be used to export the contents of a
* Directory Server backend to an LDIF file. Depending on the arguments given,
* this program will either perform the export directly as a process that
* runs separate from Directory Server; or by scheduling a task to perform the
* action within the Directory Server via the tasks interface.
*/
public class ExportLDIF extends TaskTool {
/**
* The main method for ExportLDIF tool.
*
* @param args The command-line arguments provided to this program.
*/
{
if(retCode != 0)
{
}
}
/**
* Processes the command-line arguments and invokes the export process.
*
* @param args The command-line arguments provided to this program.
*
* @return The error code.
*/
{
}
/**
* Processes the command-line arguments and invokes the export process.
*
* @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.
*/
{
}
// Define the command-line arguments that may be used with this program.
{
}
else
{
}
{
}
else
{
}
// Create the command-line argument parser for use with this program.
createArgParser("org.opends.server.tools.ExportLDIF",
// Initialize all the command-line argument types and register them with the
// parser.
try
{
OPTION_LONG_CONFIG_CLASS, true, false,
true, INFO_CONFIGCLASS_PLACEHOLDER.get(),
configClass.setHidden(true);
null,
configFile.setHidden(true);
ldifFile =
OPTION_LONG_LDIF_FILE,true, false, true,
appendToLDIF = new BooleanArgument(
"appendldif", 'a', "appendToLDIF",
true, true, INFO_BRANCH_DN_PLACEHOLDER.get(),
true, true, INFO_BRANCH_DN_PLACEHOLDER.get(),
new StringArgument(
"includeattribute", 'i', "includeAttribute",
null,
new StringArgument(
"excludeattribute", 'e', "excludeAttribute",
null,
false, true, true, INFO_FILTER_PLACEHOLDER.get(),
false, true, true, INFO_FILTER_PLACEHOLDER.get(),
signHash =
}
catch (ArgumentException ae)
{
return 1;
}
// Parse the command-line arguments provided to this program.
try
{
}
catch (ArgumentException ae)
{
return 1;
}
catch (CLIException ce)
{
// No need to display the usage since the problem comes with a provided
// value.
return 1;
}
// If we should just display usage or version information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
return 0;
}
}
/**
* {@inheritDoc}
*/
{
//
// Required attributes
//
//
// Optional attributes
//
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
if (excludeOperationalAttrs.isPresent())
{
values));
}
}
/**
* {@inheritDoc}
*/
public String getTaskObjectclass() {
return "ds-task-export";
}
/**
* {@inheritDoc}
*/
public Class getTaskClass() {
return ExportTask.class;
}
/**
* {@inheritDoc}
*/
protected int processLocal(boolean initializeServer,
PrintStream err) {
// Perform the initial bootstrap of the Directory Server and process the
// configuration.
if (initializeServer)
{
try
{
}
catch (Exception e)
{
return 1;
}
try
{
configFile.getValue());
}
catch (InitializationException ie)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server schema elements.
try
{
}
catch (ConfigException ce)
{
return 1;
}
catch (InitializationException ie)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server core configuration.
try
{
}
catch (ConfigException ce)
{
return 1;
}
catch (InitializationException ie)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server crypto manager.
try
{
}
catch (ConfigException ce)
{
return 1;
}
catch (InitializationException ie)
{
return 1;
}
catch (Exception e)
{
getExceptionMessage(e));
return 1;
}
try
{
}
catch(Exception e)
{
}
// Make sure that the Directory Server plugin initialization is performed.
try
{
}
catch (ConfigException ce)
{
return 1;
}
catch (InitializationException ie)
{
return 1;
}
catch (Exception e)
{
getExceptionMessage(e));
return 1;
}
}
// filters. If so, then process them.
if (excludeAttributeStrings == null)
{
}
else
{
{
{
}
}
}
if (includeAttributeStrings == null)
{
}
else
{
{
{
}
}
}
if (excludeFilterStrings == null)
{
}
else
{
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
catch (Exception e)
{
return 1;
}
}
}
if (includeFilterStrings == null)
{
}
else
{
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
catch (Exception e)
{
return 1;
}
}
}
// Get information about the backends defined in the server. Iterate
// through them, finding the one backend that should be used for the export,
// and also finding backends with subordinate base DNs that should be
// excluded from the export.
for (int i=0; i < numBackends; i++)
{
{
continue;
}
{
backend = b;
}
else
{
return 1;
}
}
{
return 1;
}
else if (! backend.supportsLDIFExport())
{
return 1;
}
if (excludeBranchStrings.isPresent())
{
{
try
{
}
catch (DirectoryException de)
{
s, de.getMessageObject());
return 1;
}
catch (Exception e)
{
s, getExceptionMessage(e));
return 1;
}
{
}
}
}
if (includeBranchStrings.isPresent())
{
{
try
{
}
catch (DirectoryException de)
{
s, de.getMessageObject());
return 1;
}
catch (Exception e)
{
s, getExceptionMessage(e));
return 1;
}
{
return 1;
}
}
}
else
{
}
// Create the LDIF export configuration to use when reading the LDIF.
if (appendToLDIF.isPresent())
{
}
else
{
}
(! excludeOperationalAttrs.isPresent()));
// FIXME -- Should this be conditional?
try
{
}
catch (ArgumentException ae)
{
wrapColumn.getValue());
return 1;
}
// Get the set of base DNs for the backend as an array.
// Acquire a shared lock for the backend.
try
{
{
return 1;
}
}
catch (Exception e)
{
return 1;
}
boolean errorOccurred = false;
// Launch the export.
try
{
}
catch (DirectoryException de)
{
errorOccurred = true;
}
catch (Exception e)
{
errorOccurred = true;
}
// Release the shared lock on the backend.
try
{
{
}
}
catch (Exception e)
{
}
// Clean up after the export by closing the export config.
if (!errorOccurred)
{
return 0;
}
else
{
return 1;
}
}
/**
* {@inheritDoc}
*/
// NYI.
return null;
}
}