Class DatabaseBackup

java.lang.Object
utils.DatabaseBackup

public class DatabaseBackup extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    Directory where timestamped backups are stored.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor to prevent instantiation of this utility class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    createBackup(String dbFilePath)
    Create a timestamped copy of the database file under the backups folder.
    static void
    restoreBackup(String backupFilePath, String dbFilePath)
    Restore a backup file to the live database location by copying the file.
    static boolean
    verifyBackup(String backupFilePath)
    Basic existence check for a backup file.
    static boolean
    verifyBackupIntegrity(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).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • DatabaseBackup

      private DatabaseBackup()
      Private constructor to prevent instantiation of this utility class.
  • Method Details

    • createBackup

      public static void createBackup(String dbFilePath) throws IOException
      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

      public static void restoreBackup(String backupFilePath, String dbFilePath) throws IOException
      Restore a backup file to the live database location by copying the file.
      Parameters:
      backupFilePath - path to the archived backup file
      dbFilePath - destination path for the live database file
      Throws:
      IOException - when file operations fail
    • verifyBackup

      public static boolean verifyBackup(String backupFilePath)
      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

      public static boolean verifyBackupIntegrity(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).
      Parameters:
      backupFilePath - path to the backup file
      Returns:
      true when the backup appears valid