BackupDirectory.java revision 4bf97a0d53caa31340e8ffdccba31cdc4cf02dbd
/*
* 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-2008 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* This class defines a data structure for holding information about a
* filesystem directory that contains data for one or more backups associated
* with a backend. Only backups for a single backend may be placed in any given
* directory.
*/
mayInstantiate = true,
mayExtend = false,
mayInvoke = true)
public final class BackupDirectory
{
/**
* The name of the property that will be used to provide the DN of
* the configuration entry for the backend associated with the
* backups in this directory.
*/
/**
* The DN of the configuration entry for the backend with which this
* backup directory is associated.
*/
private final DN configEntryDN;
/**
* The set of backups in the specified directory. The iteration
* order will be the order in which the backups were created.
*/
/** The filesystem path to the backup directory. */
/**
* Creates a new backup directory object with the provided information.
*
* @param path
* The path to the directory containing the backup file(s).
* @param configEntryDN
* The DN of the configuration entry for the backend with which this
* backup directory is associated.
*/
{
}
/**
* Creates a new backup directory object with the provided information.
*
* @param path
* The path to the directory containing the backup file(s).
* @param configEntryDN
* The DN of the configuration entry for the backend with which this
* backup directory is associated.
* @param backups
* Information about the set of backups available within the
* specified directory.
*/
{
this.configEntryDN = configEntryDN;
{
}
else
{
this.backups = new LinkedHashMap<>();
}
}
/**
* Retrieves the path to the directory containing the backup file(s).
*
* @return The path to the directory containing the backup file(s).
*/
{
return path;
}
/**
* Retrieves the DN of the configuration entry for the backend with which this
* backup directory is associated.
*
* @return The DN of the configuration entry for the backend with which this
* backup directory is associated.
*/
public DN getConfigEntryDN()
{
return configEntryDN;
}
/**
* Retrieves the set of backups in this backup directory, as a mapping between
* the backup ID and the associated backup info. The iteration order for the
* map will be the order in which the backups were created.
*
* @return The set of backups in this backup directory.
*/
{
return backups;
}
/**
* Retrieves the backup info structure for the backup with the specified ID.
*
* @param backupID
* The backup ID for the structure to retrieve.
* @return The requested backup info structure, or <CODE>null</CODE> if no such
* structure exists.
*/
{
}
/**
* Retrieves the most recent backup for this backup directory, according to
* the backup date.
*
* @return The most recent backup for this backup directory, according to the
* backup date, or <CODE>null</CODE> if there are no backups in the
* backup directory.
*/
public BackupInfo getLatestBackup()
{
{
if (latestBackup == null
{
}
}
return latestBackup;
}
/**
* Adds information about the provided backup to this backup directory.
*
* @param backupInfo
* The backup info structure for the backup to be added.
* @throws ConfigException
* If another backup already exists with the same backup ID.
*/
{
{
}
}
/**
* Removes the backup with the specified backup ID from this backup directory.
*
* @param backupID
* The backup ID for the backup to remove from this backup directory.
* @throws ConfigException
* If it is not possible to remove the requested backup for some
* reason (e.g., no such backup exists, or another backup is
* dependent on it).
*/
{
{
}
{
{
throw new ConfigException(ERR_BACKUPDIRECTORY_UNRESOLVED_DEPENDENCY.get(backupID, path, backup.getBackupID()));
}
}
}
/**
* Retrieves a path to the backup descriptor file that should be used for this
* backup directory.
*
* @return A path to the backup descriptor file that should be used for this
* backup directory.
*/
public String getDescriptorPath()
{
}
/**
* Writes the descriptor with the information contained in this structure to
* disk in the appropriate directory.
*
* @throws IOException
* If a problem occurs while writing to disk.
*/
public void writeBackupDirectoryDescriptor() throws IOException
{
// First make sure that the target directory exists. If it doesn't, then try to create it.
// We'll write to a temporary file so that we won't destroy the live copy if a problem occurs.
{
// The first line in the file will only contain the DN of the configuration entry for the associated backend.
// Iterate through all of the backups and add them to the file.
{
{
}
}
// At this point, the file should be complete so flush and close it.
}
// If previous backup descriptor file exists, then rename it.
// Rename the new descriptor file to match the previous one.
try
{
}
catch (Exception e)
{
logger.traceException(e);
}
}
private void createDirectoryIfNotExists() throws IOException
{
{
try
{
}
catch (Exception e)
{
logger.traceException(e);
LocalizableMessage message = ERR_BACKUPDIRECTORY_CANNOT_CREATE_DIRECTORY.get(path, getExceptionMessage(e));
}
}
else if (!dir.isDirectory())
{
}
}
private void renameOldBackupDescriptorFile(File descriptorFile, String descriptorFilePath) throws IOException
{
if (descriptorFile.exists())
{
if (savedDescriptorFile.exists())
{
try
{
}
catch (Exception e)
{
logger.traceException(e);
}
}
try
{
}
catch (Exception e)
{
logger.traceException(e);
LocalizableMessage message = ERR_BACKUPDIRECTORY_CANNOT_RENAME_CURRENT_DESCRIPTOR.get(descriptorFilePath,
}
}
}
/**
* Reads the backup descriptor file in the specified path and uses the
* information it contains to create a new backup directory structure.
*
* @param path
* The path to the directory containing the backup descriptor file to
* read.
* @return The backup directory structure created from the contents of the
* descriptor file.
* @throws IOException
* If a problem occurs while trying to read the contents of the
* descriptor file.
* @throws ConfigException
* If the contents of the descriptor file cannot be parsed to create
* a backup directory structure.
*/
public static BackupDirectory readBackupDirectoryDescriptor(String path) throws IOException, ConfigException
{
// Make sure that the descriptor file exists.
{
}
// Open the file for reading.
// The first line should be the DN of the associated configuration entry.
{
{
}
{
}
try
{
}
catch (DirectoryException de)
{
}
catch (Exception e)
{
throw new ConfigException(message, e);
}
// Create the backup directory structure from what we know so far.
// Iterate through the rest of the file and create the backup info structures.
// Blank lines will be considered delimiters.
{
{
continue;
}
// We are on a delimiter blank line.
}
return backupDirectory;
}
}
private static void readBackupFromLines(BackupDirectory backupDirectory, List<String> lines) throws ConfigException
{
{
}
}
}