Class BackupHelper

java.lang.Object
io.github.zhengzhengyiyi.util.BackupHelper

public class BackupHelper extends Object
Utility class for creating backups of configuration files. Provides functionality to create compressed backups of config directories.
  • Constructor Details

    • BackupHelper

      public BackupHelper()
  • Method Details

    • backupConfigFile

      public static Path backupConfigFile(Path configFile)
      Creates a backup of the specified configuration file. The backup is stored in a backups subdirectory with a timestamp.
      Parameters:
      configFile - the configuration file to backup
      Returns:
      the path to the created backup file, or null if backup failed
    • backupEntireConfigDirectory

      public static Path backupEntireConfigDirectory()
      Creates a compressed backup of the entire config directory. The backup is stored as a ZIP file in the backups subdirectory.
      Returns:
      the path to the created ZIP backup file, or null if backup failed
    • backupDirectoryToZip

      public static Path backupDirectoryToZip(Path directory, String backupName)
      Creates a compressed backup of a specific directory.
      Parameters:
      directory - the directory to backup
      backupName - the base name for the backup file
      Returns:
      the path to the created ZIP file, or null if backup failed
    • getConfigBackupDirectory

      public static Path getConfigBackupDirectory()
      Gets the path to the backups directory for the main config directory.
      Returns:
      the path to the config backups directory
    • listBackups

      public static Path[] listBackups() throws IOException
      Lists all available backups in the backup directory.
      Returns:
      an array of backup files, sorted by modification time (newest first)
      Throws:
      IOException - if the backup directory cannot be read
    • cleanupOldBackups

      public static int cleanupOldBackups(int maxBackups) throws IOException
      Deletes old backups beyond the specified maximum count.
      Parameters:
      maxBackups - the maximum number of backups to keep
      Returns:
      the number of backups deleted
      Throws:
      IOException - if an error occurs during deletion