Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SERVER-6961 Added system.indexes.bson back to mongodump for pre 2.2 m…
…ongorestore
  • Loading branch information
sverch committed Oct 29, 2012
1 parent 6e96617 commit 9541d2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/mongo/tools/dump.cpp
Expand Up @@ -218,9 +218,12 @@ class Dump : public Tool {
error() << "Cannot dump " << name << ". Collection has '/' or null in the collection name." << endl; error() << "Cannot dump " << name << ". Collection has '/' or null in the collection name." << endl;
continue; continue;
} }


// Don't dump indexes
if ( endsWith(name.c_str(), ".system.indexes") ) { if ( endsWith(name.c_str(), ".system.indexes") ) {
// Create system.indexes.bson for compatibility with pre 2.2 mongorestore
const string filename = name.substr( db.size() + 1 );
writeCollectionFile( name.c_str() , outdir / ( filename + ".bson" ) );
// Don't dump indexes as *.metadata.json
continue; continue;
} }


Expand Down
9 changes: 8 additions & 1 deletion src/mongo/tools/restore.cpp
Expand Up @@ -177,6 +177,7 @@ class Restore : public BSONTool {
} }


void drillDown( boost::filesystem::path root, bool use_db, bool use_coll, bool top_level=false ) { void drillDown( boost::filesystem::path root, bool use_db, bool use_coll, bool top_level=false ) {
bool json_metadata = false;
LOG(2) << "drillDown: " << root.string() << endl; LOG(2) << "drillDown: " << root.string() << endl;


// skip hidden files and directories // skip hidden files and directories
Expand Down Expand Up @@ -209,6 +210,11 @@ class Restore : public BSONTool {
} }
} }


// Ignore system.indexes.bson if we have *.metadata.json files
if ( endsWith( p.string().c_str() , ".metadata.json" ) ) {
json_metadata = true;
}

// don't insert oplog // don't insert oplog
if (top_level && !use_db && p.leaf() == "oplog.bson") if (top_level && !use_db && p.leaf() == "oplog.bson")
continue; continue;
Expand All @@ -220,8 +226,9 @@ class Restore : public BSONTool {
} }
} }


if (!indexes.empty()) if (!indexes.empty() && !json_metadata) {
drillDown(indexes, use_db, use_coll); drillDown(indexes, use_db, use_coll);
}


return; return;
} }
Expand Down

0 comments on commit 9541d2b

Please sign in to comment.