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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Pathprotected static final DateTimeFormatterprotected booleanstatic final intprotected final Stringprotected final Pathprotected static boolean -
Constructor Summary
ConstructorsConstructorDescriptionBackupManager(Path backups, Path toBackup, boolean deleteOldBackups, String prefix) -
Method Summary
Modifier and TypeMethodDescriptionprotected Collection<org.kingdoms.managers.backup.ZipEntryCreator> addToZip()voidconfigureRestorer(BackupInfo info) deleteOldBackups(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.getLock()protected PathGets a new path with the format ofgetRegularZipPath()including an additional
number with the format of (x) where x is starts from 1 only if
getRegularZipPath()already exists.abstract org.kingdoms.utils.fs.walker.visitors.PathVisitorThe files and folders to include from the folder.protected PathGets the backup ZIP path for today.protected PathgetZip()Gets the final ZIP path.booleanChecks if the backup file for today exists considering
multi backup files if enabled.booleanprotected StringmultiZipSuffix(int number) voidUncompresses all the files from the given path to the given directory asynchronous.voidsetAutomatic(boolean automatic) protected booleanshouldBeDeleted(Path path, int time, TimeUnit timeUnit) Checks if the specified backup file should be deleted if it's an old backup.final voidvoidtakeBackup(Path to) The default method to take a clean backup.intCompresses all the files in the given directory oftoBackupasynchronous.
-
Field Details
-
DATE_PATTERN
-
METHOD
public static final int METHOD- See Also:
-
useMultiBackups
protected static boolean useMultiBackups -
backups
-
toBackup
-
prefix
-
isAutomatic
protected boolean isAutomatic
-
-
Constructor Details
-
BackupManager
-
-
Method Details
-
isAutomatic
public boolean isAutomatic() -
setAutomatic
public void setAutomatic(boolean automatic) -
getDate
Gets the concurrent date usingDATE_PATTERNformat.- Returns:
- today's date.
- Since:
- 1.0.0
-
getLock
-
restore
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.replaceExisting- currently doesn't work. Will always replace.- Since:
- 1.0.0
-
takeBackup
public final void takeBackup() -
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
-
multiZipSuffix
-
getMultiZipName
Gets a new path with the format ofgetRegularZipPath()including an additional
number with the format of (x) where x is starts from 1 only if
getRegularZipPath()already exists.- Returns:
- a new path if
getRegularZipPath()already exists, otherwisegetRegularZipPath()with no additional number. - Since:
- 1.0.0
-
addToZip
-
getPathVisitor
public abstract org.kingdoms.utils.fs.walker.visitors.PathVisitor getPathVisitor()The files and folders to include from the folder. -
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
-
getRegularZipPath
Gets the backup ZIP path for today.- Returns:
- a path including today's date with ZIP file extension.
- Since:
- 1.0.0
-
getBackupsFolder
-
getToBackupRootFolder
-
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
-
configureRestorer
-