QED数据库使用笔记之备份数据

来源:互联网 发布:php memcached 扩展 编辑:程序博客网 时间:2024/05/16 13:47

//第一种方法

QED requires zero administration. Still, sometimes you *want* to administer your data -- with QED, the database is simply a directory in the filesystem containing files accessed via a JDBC url using the QED JDBC driver. If you want, you can use file system backups (ideally when the datbase is closed, but even a snapshot of a running database should be recoverable using QED's restart logic.) to backup your database.

For more direct control over the database (as well as for a smaller backup file), QED includes the utility classes XmlDump, XmlLoad. These classes can be run from the command line:

# my handy java+qed alias :-)alias qjava=java -classpath $QED/lib/qed.jar:$QED/lib/antlr.jar    # dump the db to a compressed xml fileqjava -Djdbc.url=jdbc:qed:mydb com.quadcap.sql.tools.XmlDump db.xml.gz# reload the db from the filerm -rf mydbqjava '-Djdbc.url=jdbc:qed:mydb;create=true' /      com.quadcap.sql.tools.XmlLoad db.xml.gz
//第二种方法

You can also call XmlDump/XmlLoad from your application:

import java.io.*;import java.sql.Connection;import com.quadcap.sql.tools.XmlDump;void dumpDb(Connection conn, String outfile) {    FileOutputStream fos = new FileOutputStream(outfile);    OutputStreamWriter ow = new OutputStreamWriter(fos);    BufferedWriter bw = new BufferedWriter(ow);    XmlDump dump = new XmlDump(conn);    dump.dumpTables(bw);    bw.close();}