RestoreDB.java revision 4e4b322332130bf466e3bdbd9cd7c4ca832d1049
/*
* 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 legal-notices/CDDLv1_0.txt
* 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 legal-notices/CDDLv1_0.txt.
* 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.
* Portions Copyright 2012-2015 ForgeRock AS.
*/
/**
* This program provides a utility that may be used to restore a binary backup
* of a Directory Server backend generated using the BackUpDB tool. 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).
*/
/**
* The main method for RestoreDB tool.
*
* @param args The command-line arguments provided to this program.
*/
{
if(retCode != 0)
{
}
}
/**
* Processes the command-line arguments and invokes the restore process.
*
* @param args The command-line arguments provided to this program.
*
* @return The error code.
*/
{
}
/**
* Processes the command-line arguments and invokes the restore 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. */
private BooleanArgument displayUsage;
private BooleanArgument listBackups;
private BooleanArgument verifyOnly;
private StringArgument backupIDString;
private StringArgument configClass;
private StringArgument configFile;
private StringArgument backupDirectory;
{
// Create the command-line argument parser for use with this program.
createArgParser("org.opends.server.tools.RestoreDB",
// 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);
false, true, INFO_BACKUPDIR_PLACEHOLDER.get(),
listBackups = new BooleanArgument(
"listbackups", 'l', "listBackups",
verifyOnly = new BooleanArgument(
"verifyonly", OPTION_SHORT_DRYRUN,
}
catch (ArgumentException ae)
{
return 1;
}
// Init the default values so that they can appear also on the usage.
try
{
}
catch (ConfigException ce)
{
// Ignore.
}
// Parse the command-line arguments provided to this program.
try
{
}
catch (ArgumentException ae)
{
return 1;
}
catch (ClientException 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;
}
return 1;
}
// Checks the version - if upgrade required, the tool is unusable
try
{
checkVersion();
}
catch (InitializationException e)
{
return 1;
}
}
/** {@inheritDoc} */
{
}
{
{
}
}
/** {@inheritDoc} */
public String getTaskObjectclass() {
return "ds-task-restore";
}
/** {@inheritDoc} */
public Class<?> getTaskClass() {
return RestoreTask.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 | InitializationException e)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server core configuration.
try
{
}
catch (ConfigException | InitializationException e)
{
return 1;
}
catch (Exception e)
{
return 1;
}
// Initialize the Directory Server crypto manager.
try
{
}
catch (ConfigException | InitializationException e)
{
return 1;
}
catch (Exception e)
{
return 1;
}
try
{
}
catch(Exception e)
{
}
}
// Open the backup directory and make sure it is valid.
try
{
}
catch (Exception e)
{
logger.error(ERR_RESTOREDB_CANNOT_READ_BACKUP_DIRECTORY, backupDirectory.getValue(), getExceptionMessage(e));
return 1;
}
// If we're just going to be listing backups, then do that now.
if (listBackups.isPresent())
{
{
if (! dependencyIDs.isEmpty())
{
{
}
}
else
{
}
}
return 0;
}
// If a backup ID was specified, then make sure it is valid. If none was
// provided, then choose the latest backup from the archive. Encrypted
// or signed backups cannot be restored to a local (offline) server
// instance.
{
if (backupInfo == null)
{
return 1;
}
if (backupIDString.isPresent())
{
if (backupInfo == null)
{
return 1;
}
}
return 1;
}
}
// Get the DN of the backend configuration entry from the backup and load
// the associated backend from the configuration.
// Get information about the backends defined in the server and determine
// which to use for the restore.
for (int i=0; i < numBackends; i++)
{
{
backend = b;
break;
}
}
{
return 1;
}
{
return 1;
}
// Create the restore config object from the information available.
verifyOnly.isPresent());
// Acquire an exclusive lock for the backend.
try
{
{
return 1;
}
}
catch (Exception e)
{
return 1;
}
// Perform the restore.
try
{
}
catch (DirectoryException de)
{
logger.error(ERR_RESTOREDB_ERROR_DURING_BACKUP, backupID, backupDir.getPath(), de.getMessageObject());
}
catch (Exception e)
{
logger.error(ERR_RESTOREDB_ERROR_DURING_BACKUP, backupID, backupDir.getPath(), getExceptionMessage(e));
}
// Release the exclusive lock on the backend.
try
{
{
}
}
catch (Exception e)
{
}
return 0;
}
/** {@inheritDoc} */
}
}