Class BackupManager

java.lang.Object
org.kingdoms.managers.backup.BackupManager
Direct Known Subclasses:
KingdomsBackup

public abstract class BackupManager extends Object
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 Details

    • DATE_PATTERN

      protected static final DateTimeFormatter DATE_PATTERN
    • METHOD

      public static final int METHOD
      See Also:
    • useMultiBackups

      protected static boolean useMultiBackups
    • backups

      protected final Path backups
    • toBackup

      protected final Path toBackup
    • prefix

      protected final String prefix
    • isAutomatic

      protected boolean isAutomatic
  • Constructor Details

    • BackupManager

      public BackupManager(Path backups, Path toBackup, boolean deleteOldBackups, String prefix)
  • Method Details

    • isAutomatic

      public boolean isAutomatic()
    • setAutomatic

      public void setAutomatic(boolean automatic)
    • getDate

      public String getDate()
      Gets the concurrent date using DATE_PATTERN format.
      Returns:
      today's date.
      Since:
      1.0.0
    • getLock

      public ReadWriteLock getLock()
    • restore

      public void restore(Path zip, Path unzipTo, boolean replaceExisting)
      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

      public void takeBackup(Path to)
      The default method to take a clean backup. You can override for a custom handler.
      Since:
      1.0.0
    • zipFiles

      public int zipFiles(Path zipTo)
      Compresses all the files in the given directory of toBackup asynchronous.
      Returns:
      the amount of files that were successfully backed up.
      Since:
      1.0.0
    • multiZipSuffix

      protected String multiZipSuffix(int number)
    • getMultiZipName

      protected Path getMultiZipName()
      Gets a new path with the format of getRegularZipPath() 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, otherwise getRegularZipPath() with no additional number.
      Since:
      1.0.0
    • addToZip

      protected Collection<org.kingdoms.managers.backup.ZipEntryCreator> addToZip()
    • getPathVisitor

      public abstract org.kingdoms.utils.fs.walker.visitors.PathVisitor getPathVisitor()
      The files and folders to include from the folder.
    • shouldBeDeleted

      protected boolean shouldBeDeleted(Path path, int time, TimeUnit timeUnit)
      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

      public CompletableFuture<Void> deleteOldBackups(int time, TimeUnit timeUnit)
      Deletes all the backups that are older than the specified time.

      Note that getMultiZipName() will replace the deleted files when
      checking through the files. It's recommended to change DATE_PATTERN to 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

      protected Path getRegularZipPath()
      Gets the backup ZIP path for today.
      Returns:
      a path including today's date with ZIP file extension.
      Since:
      1.0.0
    • getBackupsFolder

      public Path getBackupsFolder()
    • getToBackupRootFolder

      public Path getToBackupRootFolder()
    • getZip

      protected Path 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

      public void configureRestorer(BackupInfo info)