summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/tool/data/dumprestore6/foo.bsonbin0 -> 44 bytes
-rw-r--r--jstests/tool/data/dumprestore6/system.indexes.bsonbin0 -> 144 bytes
-rw-r--r--jstests/tool/dumprestore6.js27
-rw-r--r--tools/restore.cpp5
4 files changed, 31 insertions, 1 deletions
diff --git a/jstests/tool/data/dumprestore6/foo.bson b/jstests/tool/data/dumprestore6/foo.bson
new file mode 100644
index 00000000000..b8f8f99e6bf
--- /dev/null
+++ b/jstests/tool/data/dumprestore6/foo.bson
Binary files differ
diff --git a/jstests/tool/data/dumprestore6/system.indexes.bson b/jstests/tool/data/dumprestore6/system.indexes.bson
new file mode 100644
index 00000000000..dde25da302a
--- /dev/null
+++ b/jstests/tool/data/dumprestore6/system.indexes.bson
Binary files differ
diff --git a/jstests/tool/dumprestore6.js b/jstests/tool/dumprestore6.js
new file mode 100644
index 00000000000..d8b349e9589
--- /dev/null
+++ b/jstests/tool/dumprestore6.js
@@ -0,0 +1,27 @@
+// dumprestore6.js
+// Test restoring from a dump with an old index version
+
+t = new ToolTest( "dumprestore6" );
+
+c = t.startDB( "foo" );
+db = t.db
+assert.eq( 0 , c.count() , "setup1" );
+
+t.runTool("restore", "--dir", "jstests/tool/data/dumprestore6", "--db", "jstests_tool_dumprestore6")
+
+assert.soon( "c.findOne()" , "no data after sleep" );
+assert.eq( 1 , c.count() , "after restore" );
+assert.eq( 1 , db.system.indexes.findOne({name:'a_1'}).v, "index version wasn't updated")
+assert.eq( 1, c.count({v:0}), "dropped the 'v' field from a non-index collection")
+
+db.dropDatabase()
+assert.eq( 0 , c.count() , "after drop" );
+
+t.runTool("restore", "--dir", "jstests/tool/data/dumprestore6", "--db", "jstests_tool_dumprestore6", "--keepIndexVersion")
+
+assert.soon( "c.findOne()" , "no data after sleep2" );
+assert.eq( 1 , c.count() , "after restore2" );
+assert.eq( 0 , db.system.indexes.findOne({name:'a_1'}).v, "index version wasn't maintained")
+assert.eq( 1, c.count({v:0}), "dropped the 'v' field from a non-index collection")
+
+t.stop();
diff --git a/tools/restore.cpp b/tools/restore.cpp
index 9adf90bd209..c08c14fa87b 100644
--- a/tools/restore.cpp
+++ b/tools/restore.cpp
@@ -39,6 +39,7 @@ class Restore : public BSONTool {
public:
bool _drop;
+ bool _keepIndexVersion;
string _curns;
string _curdb;
set<string> _users; // For restoring users with --drop
@@ -47,6 +48,7 @@ public:
add_options()
("drop" , "drop each collection before import" )
("oplogReplay" , "replay oplog for point-in-time restore")
+ ("keepIndexVersion" , "don't upgrade indexes to newest version")
;
add_hidden_options()
("dir", po::value<string>()->default_value("dump"), "directory to restore from")
@@ -69,6 +71,7 @@ public:
}
_drop = hasParam( "drop" );
+ _keepIndexVersion = hasParam("keepIndexVersion");
bool doOplog = hasParam( "oplogReplay" );
if (doOplog) {
@@ -265,7 +268,7 @@ public:
string s = _curdb + "." + n.coll;
bo.append("ns", s);
}
- else {
+ else if (strcmp(e.fieldName(), "v") != 0 || _keepIndexVersion) { // Remove index version number
bo.append(e);
}
}