简体   繁体   English

Java derby数据库上的数据库备份

[英]Database backup on Java derby database

I am writing a customer tracking program using java anad derby database. 我正在使用java anad derby数据库编写客户跟踪程序。 I need to back up this database and install it back when necessary. 我需要备份此数据库,并在必要时重新安装它。

How can this be done? 如何才能做到这一点?

According to Derby 根据德比

Offline backups 离线备份

To perform an offline backup of a database, use operating system commands to copy the database directory. 要执行数据库的脱机备份,请使用操作系统命令复制数据库目录。 You must shut down the database prior to performing an offline backup. 必须先关闭数据库,然后才能执行脱机备份。

For example, on Windows systems, the following operating system command backs up a (closed) database that is named sample and that is located in d:\\mydatabases by copying it to the directory c:\\mybackups\\2005-06-01 : 例如,在Windows系统上,以下操作系统命令通过将其复制到目录c:\\mybackups\\2005-06-01来备份名为sample且位于d:\\mydatabases的(封闭)数据库:

 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. 如果您没有使用Windows,请使用适当的操作系统命令替换目录和所有内容到新位置。

Online backups 在线备份

Use online backups to back up a database while it is running. 在数据库运行时,使用联机备份来备份数据库。 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. 使用SYSCS_UTIL.SYSCS_BACKUP_DATABASE过程可以将数据库在线备份到指定位置。 The SYSCS_UTIL.SYSCS_BACKUP_DATABASE procedure takes a string argument that represents the location in which to back up the database. SYSCS_UTIL.SYSCS_BACKUP_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.) (相对路径被解释为相对于当前目录,而不是相对于derby.system.home目录。)

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): 例如,要为当前打开的数据库指定c:/mybackups/2005-06-01的备份位置,请使用以下语句(正斜杠在SQL命令中用作路径分隔符):

 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, then copies the entire original database directory (including data files, online transaction log files, and jar files) to the specified backup directory. SYSCS_UTIL.SYSCS_BACKUP_DATABASE()过程将数据库置于可以安全复制的状态,然后将整个原始数据库目录(包括数据文件,联机事务日志文件和jar文件)复制到指定的备份目录。 Files that are not within the original database directory (for example, derby.properties) are not copied. 不在原始数据库目录中的文件(例如derby.properties)不会被复制。

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:/mybacksup/" + 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 . 对于在2005-06-01上备份的数据库,以前的命令将当前数据库复制到c:/mybackups/2005-06-01中具有相同名称的目录。 Uncommitted transactions do not appear in the backed-up database. 未提交的事务不会出现在备份的数据库中。

Note: Do not back up different databases with the same name to the same backup directory. 注意:不要将具有相同名称的不同数据库备份到同一备份目录。 If a database of the same name already exists in the backup directory, it is assumed to be an older version and is overwritten. 如果备份目录中已经存在相同名称的数据库,则认为该数据库是较旧的版本并被覆盖。

The SYSCS_UTIL.SYSCS_BACKUP_DATABASE procedure will issue an error if there are any unlogged operations in the same transaction as the backup procedure. 如果在与备份过程相同的事务中有任何未记录的操作,则SYSCS_UTIL.SYSCS_BACKUP_DATABASE过程将发出错误。 If any unlogged operations are in progress in other transactions in the system when the backup starts, this procedure will block until those transactions are complete before performing the backup. 如果开始备份时系统中其他事务中正在进行任何未记录的操作,则此过程将阻塞,直到这些事务完成后再执行备份。 Derby automatically converts unlogged operations to logged mode if they are started while the backup is in progress (except operations that maintain application jar files in the database). 如果未备份的操作在备份进行过程中启动,则Derby会自动将它们转换为已记录模式(在数据库中维护应用程序jar文件的操作除外)。 Procedures to install, replace, and remove jar files in a database are blocked while the backup is in progress. 在备份过程中,将阻止安装,替换和删除数据库中的jar文件的过程。

If you do not want backup to block until unlogged operations in other transactions are complete, use the SYSCS_UTIL.SYSCS_BACKUP_DATABASE_NOWAIT procedure. 如果您不希望备份在其他事务中未记录的操作完成之前阻塞,请使用SYSCS_UTIL.SYSCS_BACKUP_DATABASE_NOWAIT过程。 This procedure issues an error immediately at the 此过程立即在

Those links are dead,you can check the following documentation 这些链接已失效,您可以查看以下文档

Backing Up a Database in Apached 在Apached中备份数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM