background image
<< Backing up and restoring databases | Unlogged Operations >>

Online backups

<< Backing up and restoring databases | Unlogged Operations >>
Derby Server and Administration Guide
61
xcopy d:\mydatabases\sample c:\mybackups\2005-06-01\sample /s /i
If you are not using Windows, substitute the appropriate operating system command for
copying a directory and all contents to a new location.
Note: On Windows systems, do not attempt to update a database while it is being
backed up in this way. Attempting to update a database during an offline backup will
generate a java.io.IOException. Using online backups prevents this from occurring.
For large systems, shutting down the database might not be convenient. To back up a
database without having to shut it down, you can use an online backup.
Online backups
Use online backups to back up a database while it is running, without blocking
transactions.
You can perform online backups by using several types of backup procedures or by using
operating systems commands with the freeze and unfreeze system procedures.
Using the backup procedure to perform an online backup:
Use the SYSCS_UTIL.SYSCS_BACKUP_DATABASE procedure to perform an online
backup of a database to a specified location.
The SYSCS_UTIL.SYSCS_BACKUP_DATABASE procedure takes a string argument
that represents the location in which to back up the database. Typically, you provide the
full path to the backup directory. (Relative paths are interpreted as relative to the current
directory, not to the derby.system.home directory.)
For example, to specify a backup location of
c:/mybackups/2005-06-01
for a
database that is currently open, use the following statement (forward slashes are used as
path separators in SQL commands):
CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE('c:/mybackups/2005-06-01')
The SYSCS_UTIL.SYSCS_BACKUP_DATABASE procedure puts the database into
a state in which it can be safely copied. The procedure then copies the entire original
database directory (including data files, online transaction log files, and jar files) to the
specified backup directory. Files that are not within the original database directory (for
example, derby.properties) are not copied. With the exception of a few cases mentioned
in
Unlogged Operations
, the procedure does not block concurrent transactions at any
time.
The following example shows how to back up a database to a directory with a name that
reflects the current date:
public static void backUpDatabase(Connection conn)throws SQLException
{
// Get today's date as a string:
java.text.SimpleDateFormat todaysDate =
new java.text.SimpleDateFormat("yyyy-MM-dd");
String backupdirectory = "c:/mybackups/" +
todaysDate.format((java.util.Calendar.getInstance()).getTime());
CallableStatement cs = conn.prepareCall("CALL
SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)");
cs.setString(1, backupdirectory);
cs.execute();
cs.close();
System.out.println("backed up database to "+backupdirectory);
}
For a database that was backed up on 2005-06-01, the previous commands copy the
current database to a directory of the same name in c:/mybackups/2005-06-01.