Class DatabaseBackup
java.lang.Object
utils.DatabaseBackup
Utilities for creating, restoring and validating simple file-based backups
of the H2 database used by the application.
These methods perform straightforward file copy operations and basic
verification based on file existence and size. They are intended for small
desktop deployments and are not a replacement for enterprise backup tools.
- Since:
- 1.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringDirectory where timestamped backups are stored. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation of this utility class. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateBackup(String dbFilePath) Create a timestamped copy of the database file under the backups folder.static voidrestoreBackup(String backupFilePath, String dbFilePath) Restore a backup file to the live database location by copying the file.static booleanverifyBackup(String backupFilePath) Basic existence check for a backup file.static booleanverifyBackupIntegrity(String backupFilePath) More thorough verification that attempts to copy the backup to a temporary location and checks that the temporary file is usable (non-zero size).
-
Field Details
-
BACKUP_DIR
-
-
Constructor Details
-
DatabaseBackup
private DatabaseBackup()Private constructor to prevent instantiation of this utility class.
-
-
Method Details
-
createBackup
Create a timestamped copy of the database file under the backups folder. A simple GUI confirmation is shown on success.- Parameters:
dbFilePath- path to the live database file- Throws:
IOException- when file operations fail
-
restoreBackup
Restore a backup file to the live database location by copying the file.- Parameters:
backupFilePath- path to the archived backup filedbFilePath- destination path for the live database file- Throws:
IOException- when file operations fail
-
verifyBackup
Basic existence check for a backup file. Returns true when file exists and has non-zero length.- Parameters:
backupFilePath- path to backup file- Returns:
- true if file exists and is non-empty
-
verifyBackupIntegrity
More thorough verification that attempts to copy the backup to a temporary location and checks that the temporary file is usable (non-zero size).- Parameters:
backupFilePath- path to the backup file- Returns:
- true when the backup appears valid
-