Keywords: SYSCS_FREEZE_DATABASE system procedure, SYSCS_UNFREEZE_DATABASE system procedure

# Using operating system commands with the freeze and unfreeze system procedures to perform an online backup

Typically, these procedures are used to speed up the copy operation involved in an online backup. In this scenario, Derby does not perform the copy operation for you. You use the SYSCS_UTIL.SYSCS_FREEZE_DATABASE procedure to lock the database, and then you explicitly copy the database directory by using operating system commands.

For example, because the UNIX tar command uses operating system file-copying routines, and the SYSCS_UTIL.SYSCS_BACKUP_DATABASE procedure uses java I/O calls with additional internal synchronization that allow updates during the backup, the tar command might provide faster backups than the SYSCS_UTIL.SYSCS_BACKUP_DATABASE procedure.

To use operating system commands for online database backups, call the SYSCS_UTIL.SYSCS_FREEZE_DATABASE system procedure. The SYSCS_UTIL.SYSCS_FREEZE_DATABASE system procedure puts the database into a state in which it can be safely copied. After the database has been copied, use the SYSCS_UTIL.SYSCS_UNFREEZE_DATABASE system procedure to continue working with the database. Only after SYSCS_UTIL.SYSCS_UNFREEZE_DATABASE has been specified can transactions once again write to the database. Read operations can proceed while the database is "frozen."

Note: To ensure a consistent backup of the database, Derby might block applications that attempt to write to a frozen database until the backup is completed and the SYSCS_UTIL.SYSCS_UNFREEZE_DATABASE system procedure is called.

The following example demonstrates how the freeze and unfreeze procedures are used to surround an operating system copy command:

    public static void backUpDatabaseWithFreeze(Connection conn)
    	throws SQLException
    {
    Statement s = conn.createStatement();
    s.executeUpdate(
        "CALL SYSCS_UTIL.SYSCS_FREEZE_DATABASE()");
    //copy the database directory during this interval
    s.executeUpdate(
        "CALL SYSCS_UTIL.SYSCS_UNFREEZE_DATABASE()");
    s.close();
    }

Parent topic: Online backups
Related concepts
Using the backup procedure to perform an online backup