ExportLDIF.java revision d20053afa42700e3ec7a6f6fb474622e8680f4cc
/*
* 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
*
*
* Portions Copyright 2006-2007 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. This will 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 ExportLDIF
{
/**
* 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.
*/
{
return mainExportLDIF(args, true);
}
/**
* 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.
*
* @return The error code.
*/
{
// Define the command-line arguments that may be used with this program.
// Create the command-line argument parser for use with this program.
new ArgumentParser("org.opends.server.tools.ExportLDIF",
toolDescription, false);
// Initialize all the command-line argument types and register them with the
// parser.
try
{
true, "{configClass}",
configClass.setHidden(true);
configFile.setHidden(true);
ldifFile =
signHash =
}
catch (ArgumentException ae)
{
return 1;
}
// Parse the command-line arguments provided to this program.
try
{
}
catch (ArgumentException ae)
{
return 1;
}
// If we should just display usage information, then print it and exit.
if (argParser.usageDisplayed())
{
return 0;
}
// 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)
{
return 1;
}
// FIXME -- Install a custom logger to capture information about the state
// of the export.
// Make sure that the Directory Server plugin initialization is performed.
try
{
}
catch (ConfigException ce)
{
return 1;
}
catch (InitializationException ie)
{
return 1;
}
catch (Exception 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)
{
de.getErrorMessage());
return 1;
}
catch (Exception e)
{
return 1;
}
}
}
if (includeFilterStrings == null)
{
}
else
{
{
try
{
}
catch (DirectoryException de)
{
de.getErrorMessage());
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;
}
}
{
msgID);
return 1;
}
else if (! backend.supportsLDIFExport())
{
msgID);
return 1;
}
if (excludeBranchStrings.isPresent())
{
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
catch (Exception e)
{
return 1;
}
{
}
}
}
if (includeBranchStrings.isPresent())
{
{
try
{
}
catch (DirectoryException de)
{
return 1;
}
catch (Exception 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)
{
msgID);
return 1;
}
// Get the set of base DNs for the backend as an array.
// Acquire a shared lock for the backend.
try
{
{
return 0;
}
}
catch (Exception e)
{
return 0;
}
// Launch the export.
try
{
}
catch (DirectoryException de)
{
msgID);
}
catch (Exception e)
{
msgID);
}
// Release the shared lock on the backend.
try
{
{
}
}
catch (Exception e)
{
}
// Clean up after the export by closing the export config.
return 0;
}
/**
* Retrieves information about the backends defined in the Directory Server
* configuration.
*
* @param backendList A list into which instantiated (but not initialized)
* backend instances will be placed.
* @param entryList A list into which the config entries associated with
* the backends will be placed.
* @param dnList A list into which the set of base DNs for each backend
* will be placed.
*/
{
// Get the base entry for all backend configuration.
try
{
}
catch (DirectoryException de)
{
msgID);
}
catch (Exception e)
{
msgID);
}
try
{
}
catch (ConfigException ce)
{
msgID);
}
catch (Exception e)
{
msgID);
}
// Iterate through the immediate children, attempting to parse them as
// backends.
{
// Get the backend ID attribute from the entry. If there isn't one, then
// skip the entry.
try
{
true, false, true);
{
continue;
}
else
{
}
}
catch (ConfigException ce)
{
ce.getMessage());
}
catch (Exception e)
{
}
// Get the backend class name attribute from the entry. If there isn't
// one, then just skip the entry.
try
{
true, false, false);
{
continue;
}
else
{
}
}
catch (ConfigException ce)
{
ce.getMessage());
}
catch (Exception e)
{
}
try
{
}
catch (Exception e)
{
}
try
{
}
catch (Exception e)
{
}
// Get the base DN attribute from the entry. If there isn't one, then
// just skip this entry.
try
{
true, true, true);
if (baseDNAttr == null)
{
}
else
{
}
}
catch (Exception e)
{
}
}
}
}