Class Utils
- java.lang.Object
-
- org.jvnet.hudson.plugins.thinbackup.utils.Utils
-
public final class Utils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String
DIRECTORY_NAME_DATE_FORMAT
static String
DISPLAY_DATE_FORMAT
static int
FORCE_QUIETMODE_TIMEOUT_MINUTES
static String
THINBACKUP_TMP_DIR
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
convertToDirectoryNameDateFormat(String displayFormattedDate)
static String
expandEnvironmentVariables(String path)
static List<String>
getBackupsAsDates(File directory)
static List<File>
getBackupSetZipFiles(File parentDir)
static List<File>
getBackupTypeDirectories(File parentDir, ThinBackupPeriodicWork.BackupType backupType)
static Date
getDateFromBackupDirectory(File directory)
static Date
getDateFromBackupDirectoryName(String directoryName)
static File
getFormattedDirectory(File parent, ThinBackupPeriodicWork.BackupType backupType, Date date)
static File
getReferencedFullBackup(File diffBackup)
static List<File>
getReferencingDiffBackups(File fullBackup)
static List<BackupSet>
getValidBackupSets(File directory)
static List<BackupSet>
getValidBackupSetsFromDirectories(File directory)
static List<BackupSet>
getValidBackupSetsFromZips(File directory)
protected static String
internalExpandEnvironmentVariables(String path, Map<String,String> environmentVariables)
static void
moveOldBackupsToZipFile(File backupRoot, File currentBackup)
Moves all backup sets (that are not already zipped) other than the one containing currentBackup to ZIP files located in backupRoot.static void
waitUntilFileCanBeRead(File f)
static void
waitUntilIdle()
Waits until all Hudson slaves are idle.static void
waitUntilIdleAndSwitchToQuietMode(int timeout, TimeUnit unit)
Waits until all executors are idle and switch jenkins to quiet mode.
-
-
-
Field Detail
-
DISPLAY_DATE_FORMAT
public static final String DISPLAY_DATE_FORMAT
- See Also:
- Constant Field Values
-
DIRECTORY_NAME_DATE_FORMAT
public static final String DIRECTORY_NAME_DATE_FORMAT
- See Also:
- Constant Field Values
-
THINBACKUP_TMP_DIR
public static final String THINBACKUP_TMP_DIR
-
FORCE_QUIETMODE_TIMEOUT_MINUTES
public static final int FORCE_QUIETMODE_TIMEOUT_MINUTES
- See Also:
- Constant Field Values
-
-
Method Detail
-
waitUntilIdle
public static void waitUntilIdle()
Waits until all Hudson slaves are idle.
-
waitUntilIdleAndSwitchToQuietMode
public static void waitUntilIdleAndSwitchToQuietMode(int timeout, TimeUnit unit) throws IOException
Waits until all executors are idle and switch jenkins to quiet mode. If it takes to long that all executors are idle because in the mean time other jobs are executed the timeout ensure that the quiet mode is forced. But if timeout is set to -1, it will never force jenkins to quiet mode.- Parameters:
timeout
- specifies when a quiet mode is forced. 0 = no timeout; -1 = disable timer, never force jenkins to quiet mode.unit
- specifies the time unit for the value of timeout.- Throws:
IOException
- ?
-
getDateFromBackupDirectory
public static Date getDateFromBackupDirectory(File directory)
- Parameters:
directory
- directory to get the date from- Returns:
- the date component of a directory name formatted in the thinBackup standard
-
getDateFromBackupDirectoryName
public static Date getDateFromBackupDirectoryName(String directoryName)
- Parameters:
directoryName
- directory name to get the date from- Returns:
- the date component of a directory name formatted in the thinBackup standard
-
convertToDirectoryNameDateFormat
public static String convertToDirectoryNameDateFormat(String displayFormattedDate) throws ParseException
- Parameters:
displayFormattedDate
- a String in the display format date- Returns:
- the string formatted in the directory names' date format
- Throws:
ParseException
- if the beginning of the specified parameter cannot be parsed.
-
getFormattedDirectory
public static File getFormattedDirectory(File parent, ThinBackupPeriodicWork.BackupType backupType, Date date)
- Parameters:
parent
- root directory of all backupsbackupType
- type of backupdate
- date of backup- Returns:
- a reference to a file in the given parent directory with a name formatted like "<BACKUP_TYPE>-yyyy-MM-dd_HH-mm".
-
getBackupTypeDirectories
public static List<File> getBackupTypeDirectories(File parentDir, ThinBackupPeriodicWork.BackupType backupType)
- Parameters:
parentDir
- root directory of all backupsbackupType
- type of backup- Returns:
- an unordered list of backup directories of the given backup type.
-
getBackupSetZipFiles
public static List<File> getBackupSetZipFiles(File parentDir)
- Parameters:
parentDir
- root directory of all backups- Returns:
- an unordered list of zipped backupsets in the given directory.
-
getReferencedFullBackup
public static File getReferencedFullBackup(File diffBackup)
- Parameters:
diffBackup
- diff backup- Returns:
- the full backup referenced by the given diff backup, or null if none can be found.
-
getReferencingDiffBackups
@NonNull public static List<File> getReferencingDiffBackups(File fullBackup)
- Parameters:
fullBackup
- fill backup- Returns:
- a list of all diff backups which reference the given full backup.
-
getBackupsAsDates
public static List<String> getBackupsAsDates(File directory)
- Parameters:
directory
- root directory of all backups- Returns:
- a list of backups in the given directory (both FULL and DIFF), displayed as the respective backup date, from both directories and ZIP files, ordered descending by the date encoded in the backups' name.
-
getValidBackupSetsFromDirectories
public static List<BackupSet> getValidBackupSetsFromDirectories(File directory)
- Parameters:
directory
- root directory of all backups- Returns:
- a list of valid (@see BackupSet#isValid) backup sets that exists as directories (not as ZIP files) in the given directory, ordered ascending by the backup date of the BackupSets' full backup.
-
getValidBackupSetsFromZips
public static List<BackupSet> getValidBackupSetsFromZips(File directory)
- Parameters:
directory
- root directory of all backups- Returns:
- a list of valid (@see BackupSet#isValid) backup sets that exists as ZIP files (not as directories) in the given directory, ordered ascending by the backup date of the BackupSets' full backup.
-
getValidBackupSets
public static List<BackupSet> getValidBackupSets(File directory)
- Parameters:
directory
- root directory of all backups- Returns:
- a list of valid (@see BackupSet#isValid) backup sets in the given directory, ordered ascending by the backup date of the BackupSets' full backup.
-
moveOldBackupsToZipFile
public static void moveOldBackupsToZipFile(File backupRoot, File currentBackup)
Moves all backup sets (that are not already zipped) other than the one containing currentBackup to ZIP files located in backupRoot.- Parameters:
backupRoot
- root directory of all backupscurrentBackup
- specified which backup should be omitted from being moved. If null, all backups are moved to ZIP files.
-
expandEnvironmentVariables
public static String expandEnvironmentVariables(String path) throws EnvironmentVariableNotDefinedException
-
internalExpandEnvironmentVariables
protected static String internalExpandEnvironmentVariables(String path, Map<String,String> environmentVariables) throws EnvironmentVariableNotDefinedException
-
waitUntilFileCanBeRead
public static void waitUntilFileCanBeRead(File f)
-
-