Package org.kingdoms.managers.backup
Class BackupManager
java.lang.Object
org.kingdoms.managers.backup.BackupManager
- Direct Known Subclasses:
KingdomsBackup
BackupManager - v1.0 - A powerful concurrent file compression using NIO.2.
Java 8 NIO.2: https://docs.oracle.com/javase/tutorial/essential/io/fileio.html
The simplest way of doing this is to use takeBackup().
You can also override the method and handle it yourself.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Pathprotected static final DateTimeFormatterprotected final Pathprotected static boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Collection<Path>addToZip()Can be either aPathorInputStreamdeleteOldBackups(int time, TimeUnit timeUnit) Deletes all the backups that are older than the specified time.
Note thatgetMultiZipName()will replace the deleted files when
checking through the files.getDate()Gets the concurrent date usingDATE_PATTERNformat.Gets a new path with the format ofgetZipPath()including an additional
number with the format of (x) where x is starts from 1 only if
getZipPath()already exists.getZip()Gets the final ZIP path.Gets the backup ZIP path for today.booleanChecks if the backup file for today exists considering
multi backup files if enabled.abstract booleanisBlacklistedDirectory(Path file) abstract BackupManager.DirVisitStateisWhitelistedDirectory(Path file) When taking a backup from the files in the directory, only the contents inside these
directories will be checked and passed toisWhitelistedFile(Path)abstract booleanisWhitelistedFile(Path file) When taking a backup from the files in the directory, only these files are accepted.booleanshouldBeDeleted(Path path, int time, TimeUnit timeUnit) Checks if the specified backup file should be deleted if it's an old backup.voidThe default method to take a clean backup.unzipFiles(Path zip, Path unzipTo) Uncompresses all the files from the given path to the given directory asynchronous.zipFiles()Compresses all the files in the given directory oftoBackupasynchronous.
-
Field Details
-
DATE_PATTERN
-
useMultiBackups
protected static boolean useMultiBackups -
backups
-
toBackup
-
-
Constructor Details
-
BackupManager
-
-
Method Details
-
getDate
Gets the concurrent date usingDATE_PATTERNformat.- Returns:
- today's date.
- Since:
- 1.0.0
-
unzipFiles
Uncompresses all the files from the given path to the given directory asynchronous.- Parameters:
zip- the ZIP file path.unzipTo- the directory to copy the uncompressed files to.- Since:
- 1.0.0
- See Also:
-
takeBackup
public void takeBackup()The default method to take a clean backup. You can override for a custom handler.- Since:
- 1.0.0
-
zipFiles
Compresses all the files in the given directory oftoBackupasynchronous.- Returns:
- the amount of files that were successfully backed up.
- Since:
- 1.0.0
- See Also:
-
getMultiZipName
Gets a new path with the format ofgetZipPath()including an additional
number with the format of (x) where x is starts from 1 only if
getZipPath()already exists.- Returns:
- a new path if
getZipPath()already exists, otherwisegetZipPath()with no additional number. - Since:
- 1.0.0
-
isWhitelistedDirectory
When taking a backup from the files in the directory, only the contents inside these
directories will be checked and passed toisWhitelistedFile(Path)- Parameters:
file- the directory that we're about to enter.- Since:
- 1.0.0
-
isBlacklistedDirectory
-
isWhitelistedFile
When taking a backup from the files in the directory, only these files are accepted.- Parameters:
file- the file that we're about to backup.- Returns:
- true if the specified path should be accepted.
- Since:
- 1.0.0
-
addToZip
Can be either aPathorInputStream- Returns:
-
shouldBeDeleted
Checks if the specified backup file should be deleted if it's an old backup.- Parameters:
path- the backup file's path.time- any files older than this time.timeUnit- the time unit for time parameter.- Returns:
- true if this backup should be deleted, otherwise false.
- Since:
- 1.0.0
-
deleteOldBackups
Deletes all the backups that are older than the specified time.
Note thatgetMultiZipName()will replace the deleted files when
checking through the files. It's recommended to changeDATE_PATTERNto use
"yyyy-MM-dd hh" to display the hours as well. This task is asynchronous.- Parameters:
time- any files older than this time.timeUnit- the time unit for time parameter.- Since:
- 1.0.0
-
getZipPath
Gets the backup ZIP path for today.- Returns:
- a path including today's date with ZIP file extension.
- Since:
- 1.0.0
-
getZip
Gets the final ZIP path.- Returns:
- default ZIP path or multi ZIP path if enabled.
- Since:
- 1.0.0
- See Also:
-
hasBackupToday
public boolean hasBackupToday()Checks if the backup file for today exists considering
multi backup files if enabled. So you shouldn't use this method
when taking a backup if you enabled multi backups.- Returns:
- true if the backup file exists, otherwise false.
- Since:
- 1.0.0
-