01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.db;
07:
08: import java.sql.Connection;
09: import java.sql.Statement;
10:
11: import org.h2.test.TestBase;
12: import org.h2.tools.Restore;
13:
14: /**
15: * Test for the BACKUP SQL statement.
16: */
17: public class TestBackup extends TestBase {
18:
19: public void test() throws Exception {
20: if (config.memory || config.logMode == 0) {
21: return;
22: }
23: testBackup();
24: }
25:
26: private void testBackup() throws Exception {
27: deleteDb("backup");
28: Connection conn1, conn2, conn3;
29: Statement stat1, stat2, stat3;
30: conn1 = getConnection("backup");
31: stat1 = conn1.createStatement();
32: stat1
33: .execute("create table test(id int primary key, name varchar(255))");
34: stat1
35: .execute("insert into test values(1, 'first'), (2, 'second')");
36: stat1
37: .execute("create table testlob(id int primary key, b blob, c clob)");
38: stat1
39: .execute("insert into testlob values(1, space(10000), repeat('00', 10000))");
40: conn2 = getConnection("backup");
41: stat2 = conn2.createStatement();
42: stat2.execute("insert into test values(3, 'third')");
43: conn2.setAutoCommit(false);
44: stat2
45: .execute("insert into test values(4, 'fourth (uncommitted)')");
46: stat2.execute("insert into testlob values(2, ' ', '00')");
47:
48: stat1.execute("backup to '" + baseDir + "/backup.zip'");
49: conn2.rollback();
50: compareDatabases(stat1, stat2);
51:
52: Restore.execute(baseDir + "/backup.zip", baseDir, "restored",
53: true);
54: conn3 = getConnection("restored");
55: stat3 = conn3.createStatement();
56: compareDatabases(stat1, stat3);
57:
58: conn1.close();
59: conn2.close();
60: conn3.close();
61: }
62:
63: }
|