/*
* 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-2008 Sun Microsystems, Inc.
*/
/**
* This class provides an implementation of a Directory Server task that can
* be used to restore a binary backup of a Directory Server backend.
*/
{
/**
* The tracer object for the debug logger.
*/
/**
* Stores mapping between configuration attribute name and its label.
*/
static {
}
// The task arguments.
private boolean verifyOnly;
/**
* {@inheritDoc}
*/
return INFO_TASK_RESTORE_NAME.get();
}
/**
* {@inheritDoc}
*/
}
/**
* {@inheritDoc}
*/
{
// If the client connection is available, then make sure the associated
// client has the BACKEND_RESTORE privilege.
{
{
message);
}
}
if (! backupDirectory.isAbsolute())
{
}
}
/**
* Acquire an exclusive lock on a backend.
* @param backend The backend on which the lock is to be acquired.
* @return true if the lock was successfully acquired.
*/
{
try
{
{
return false;
}
}
catch (Exception e)
{
return false;
}
return true;
}
/**
* Release a lock on a backend.
* @param backend The backend on which the lock is held.
* @return true if the lock was successfully released.
*/
{
try
{
{
return false;
}
}
catch (Exception e)
{
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
{
restoreConfig != null)
{
}
}
/**
* {@inheritDoc}
*/
public boolean isInterruptable() {
return true;
}
/**
* {@inheritDoc}
*/
{
// Open the backup directory and make sure it is valid.
try
{
}
catch (Exception e)
{
return TaskState.STOPPED_BY_ERROR;
}
// If a backup ID was specified, then make sure it is valid. If none was
// provided, then choose the latest backup from the archive.
{
if (backupInfo == null)
{
return TaskState.STOPPED_BY_ERROR;
}
}
else
{
if (latestBackup == null)
{
return TaskState.STOPPED_BY_ERROR;
}
else
{
}
}
// Get the DN of the backend configuration entry from the backup.
try
{
// Get the backend configuration entry.
}
catch (ConfigException e)
{
if (debugEnabled())
{
}
return TaskState.STOPPED_BY_ERROR;
}
// Get the backend ID from the configuration entry.
// Get the backend.
if (! backend.supportsRestore())
{
return TaskState.STOPPED_BY_ERROR;
}
// Create the restore config object from the information available.
// Notify the task listeners that a restore is going to start
// this must be done before disabling the backend to allow
// listener to get access to the backend configuration
// and to take appropriate actions.
// Disable the backend.
if ( !verifyOnly)
{
try
{
} catch (DirectoryException e)
{
if (debugEnabled())
{
}
logError(e.getMessageObject());
return TaskState.STOPPED_BY_ERROR;
}
}
// From here we must make sure to re-enable the backend before returning.
boolean errorsEncountered = false;
try
{
// Acquire an exclusive lock for the backend.
{
// From here we must make sure to release the backend exclusive lock.
try
{
// Perform the restore.
try
{
}
catch (DirectoryException de)
{
errorsEncountered = true;
}
catch (Exception e)
{
errorsEncountered = true;
}
}
finally
{
// Release the exclusive lock on the backend.
{
errorsEncountered = true;
}
}
}
}
finally
{
// Enable the backend.
if (! verifyOnly)
{
try
{
// it is necessary to retrieve the backend structure again
// because disabling and enabling it again may have resulted
// in a new backend being registered to the server.
} catch (DirectoryException e)
{
if (debugEnabled())
{
}
logError(e.getMessageObject());
errorsEncountered = true;
}
}
}
if (errorsEncountered)
{
return TaskState.COMPLETED_WITH_ERRORS;
}
else
{
return getFinalTaskState();
}
}
}