Author: kmarsden
Date: Mon Nov 10 08:50:28 2008
New Revision: 712693
URL: http://svn.apache.org/viewvc?rev=712693&view=rev
Log:
DERBY-3035 Cannot restore backups without BACKUP.HISTORY file
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OfflineBackupTest.java
(with props)
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java?rev=712693&r1=712692&r2=712693&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java Mon Nov
10 08:50:28 2008
@@ -1140,7 +1140,10 @@
// if this is a roll-forward recovery, backup history file
// will already there in the database and will be the latest
// copy; if it exists, do not copy from backup.
- if (!privExists(dbHistoryFile))
+ // Backup history may not exist at all if we did an offline
+ // backup with os copy commands. In that case, don't try to
+ // copy the history file. (DERBY-3035)
+ if (privExists(backupHistoryFile) && !privExists(dbHistoryFile))
if (!privCopyFile(backupHistoryFile, dbHistoryFile))
throw StandardException.
newException(SQLState.RAWSTORE_ERROR_COPYING_FILE,
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OfflineBackupTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OfflineBackupTest.java?rev=712693&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OfflineBackupTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OfflineBackupTest.java
Mon Nov 10 08:50:28 2008
@@ -0,0 +1,85 @@
+/*
+
+Derby - Class org.apache.derbyTesting.functionTests.store.OfflineBackupTest
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.store;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+
+public class OfflineBackupTest extends BaseJDBCTestCase {
+
+
+ public OfflineBackupTest(String name) {
+ super(name);
+ }
+
+ public void testCreateFromRestoreFrom() throws SQLException, IOException {
+ getConnection();
+ TestConfiguration.getCurrent().shutdownDatabase();
+ File origdbloc = new File("system","wombat");
+ File backupdbloc = new File("system","wombatbackup");
+ PrivilegedFileOpsForTests.copy(origdbloc, backupdbloc);
+ Connection connCreateFrom = DriverManager.getConnection(
+ "jdbc:derby:wombatCreateFrom;createFrom=system/wombatbackup");
+ checkAllConsistency(connCreateFrom);
+ try {
+ DriverManager.getConnection("jdbc:derby:wombatCreateFrom;shutdown=true");
+ } catch (SQLException se) {
+ assertSQLState("Database shutdown", "08006", se);
+ }
+ Connection connRestoreFrom = DriverManager.getConnection(
+ "jdbc:derby:wombatRestoreFrom;restoreFrom=system/wombatbackup");
+ checkAllConsistency(connRestoreFrom);
+ try {
+ DriverManager.getConnection("jdbc:derby:wombatRestoreFrom;shutdown=true");
+ } catch (SQLException se) {
+ assertSQLState("Database shutdown", "08006", se);
+ }
+
+ removeDirectory(backupdbloc);
+ removeDirectory(new File("system","wombatCreateFrom"));
+ removeDirectory(new File("system","wombatRestoreFrom"));
+
+ }
+
+
+
+ public static Test suite() {
+
+ if (JDBC.vmSupportsJSR169())
+ return new TestSuite("Empty OfflineBackupTest (uses DriverManager)");
+ return TestConfiguration.embeddedSuite(OfflineBackupTest.class);
+ }
+
+
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OfflineBackupTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java?rev=712693&r1=712692&r2=712693&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
Mon Nov 10 08:50:28 2008
@@ -57,6 +57,7 @@
suite.addTest(PositionedStoreStreamTest.suite());
suite.addTest(OSReadOnlyTest.suite());
suite.addTest(BackupRestoreTest.suite());
+ suite.addTest(OfflineBackupTest.suite());
// Encryption only supported for Derby in J2SE/J2EE environments.
// J2ME (JSR169) does not support encryption.
if (JDBC.vmSupportsJDBC3()) {
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=712693&r1=712692&r2=712693&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Mon
Nov 10 08:50:28 2008
@@ -1295,6 +1295,46 @@
fail("types:" + expectedType + " and " + type + " are not equivalent");
}
+
+
+ /**
+ * Check consistency of all tables
+ *
+ * @param conn
+ * @throws SQLException
+ */
+ protected void checkAllConsistency(
+ Connection conn)
+ throws SQLException
+ {
+ Statement s = createStatement();
+
+ ResultSet rs =
+ s.executeQuery(
+ "select schemaname, tablename, SYSCS_UTIL.SYSCS_CHECK_TABLE(schemaname,
tablename) " +
+ "from sys.systables a, sys.sysschemas b where a.schemaid = b.schemaid");
+
+ int table_count = 0;
+
+ while (rs.next())
+ {
+ table_count++;
+
+ if (rs.getInt(3) != 1)
+ {
+ assertEquals("Bad return from consistency check of " +
+ rs.getString(1) + "." + rs.getString(2),1,rs.getInt(3));
+
+ }
+ }
+ assertTrue("Something wrong with consistency check query, found only " +
+ table_count + " tables.",table_count >= 5);
+
+ rs.close();
+ s.close();
+
+ conn.commit();
+ }
} // End class BaseJDBCTestCase
|