Package io.github.zhengzhengyiyi.util
Class BackupHelper
java.lang.Object
io.github.zhengzhengyiyi.util.BackupHelper
Utility class for creating backups of configuration files.
Provides functionality to create compressed backups of config directories.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PathbackupConfigFile(Path configFile) Creates a backup of the specified configuration file.static PathbackupDirectoryToZip(Path directory, String backupName) Creates a compressed backup of a specific directory.static PathCreates a compressed backup of the entire config directory.static intcleanupOldBackups(int maxBackups) Deletes old backups beyond the specified maximum count.static PathGets the path to the backups directory for the main config directory.static Path[]Lists all available backups in the backup directory.
-
Constructor Details
-
BackupHelper
public BackupHelper()
-
-
Method Details
-
backupConfigFile
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
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
Creates a compressed backup of a specific directory.- Parameters:
directory- the directory to backupbackupName- the base name for the backup file- Returns:
- the path to the created ZIP file, or null if backup failed
-
getConfigBackupDirectory
Gets the path to the backups directory for the main config directory.- Returns:
- the path to the config backups directory
-
listBackups
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
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
-