| | |
| | | import static java.util.Collections.*; |
| | | |
| | | import static org.opends.messages.BackendMessages.*; |
| | | import static org.opends.messages.CoreMessages.ERR_BACKUPINFO_CANNOT_DECODE; |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | |
| | | private final NewBackupParams newBackupParams; |
| | | private final CryptoEngine cryptoEngine; |
| | | |
| | | NewBackupArchive(String backendID, NewBackupParams backupParams, CryptoEngine crypt) |
| | | NewBackupArchive(String backendID, NewBackupParams backupParams, CryptoEngine crypt) throws DirectoryException |
| | | { |
| | | this.backendID = backendID; |
| | | this.newBackupParams = backupParams; |
| | |
| | | { |
| | | Map<String, String> properties = backupParams.baseBackupInfo.getBackupProperties(); |
| | | latestFileName = properties.get(PROPERTY_LAST_LOGFILE_NAME); |
| | | latestFileSize = Long.parseLong(properties.get(PROPERTY_LAST_LOGFILE_SIZE)); |
| | | latestFileSize = parseLatestFileSize(backupParams, properties.get(PROPERTY_LAST_LOGFILE_SIZE)); |
| | | } |
| | | archiveFilename = BACKUP_BASE_FILENAME + backendID + "-" + backupParams.backupID; |
| | | } |
| | | |
| | | /** Returns the size recorded by the base backup for the last file it archived. */ |
| | | private static long parseLatestFileSize(NewBackupParams backupParams, String size) throws DirectoryException |
| | | { |
| | | try |
| | | { |
| | | return Long.parseLong(size); |
| | | } |
| | | catch (NumberFormatException e) |
| | | { |
| | | throw new DirectoryException(DirectoryServer.getCoreConfigManager().getServerErrorResultCode(), |
| | | ERR_BACKUPINFO_CANNOT_DECODE.get(backupParams.backupDir.getPath(), |
| | | PROPERTY_LAST_LOGFILE_SIZE + ": " + size), e); |
| | | } |
| | | } |
| | | |
| | | String getArchiveFilename() |
| | | { |
| | | return archiveFilename; |
| | |
| | | { |
| | | final File baseFile = new File(basePath).getCanonicalFile(); |
| | | final File[] existingFiles = baseFile.getParentFile().listFiles(); |
| | | final Pattern pattern = Pattern.compile(baseFile + "\\d*"); |
| | | final Pattern pattern = Pattern.compile(Pattern.quote(baseFile.getPath()) + "\\d*"); |
| | | int highestNumber = 0; |
| | | for (File file : existingFiles) |
| | | { |
| | |
| | | if (pattern.matcher(name).matches()) |
| | | { |
| | | String numberAsString = name.substring(baseFile.getPath().length()); |
| | | int number = numberAsString.isEmpty() ? 0 : Integer.valueOf(numberAsString); |
| | | int number = parseSuffixNumber(numberAsString); |
| | | highestNumber = number > highestNumber ? number : highestNumber; |
| | | } |
| | | } |
| | | return highestNumber; |
| | | } |
| | | |
| | | /** |
| | | * Returns the number held by the provided file name suffix, or 0 if the suffix is empty or holds a |
| | | * number which is too big to have been generated by this class. |
| | | */ |
| | | private static int parseSuffixNumber(final String numberAsString) |
| | | { |
| | | if (numberAsString.isEmpty()) |
| | | { |
| | | return 0; |
| | | } |
| | | try |
| | | { |
| | | return Integer.parseInt(numberAsString); |
| | | } |
| | | catch (NumberFormatException e) |
| | | { |
| | | logger.trace("Ignoring file suffix \"%s\" which is too big to have been generated by this class", |
| | | numberAsString); |
| | | return 0; |
| | | } |
| | | } |
| | | } |