summaryrefslogtreecommitdiff
path: root/tools/dump.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/dump.cpp')
-rw-r--r--tools/dump.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/tools/dump.cpp b/tools/dump.cpp
index 27e19938173..9e263cce8f0 100644
--- a/tools/dump.cpp
+++ b/tools/dump.cpp
@@ -30,16 +30,16 @@ class Dump : public Tool {
public:
Dump() : Tool( "dump" , "*" ){
add_options()
- ("out,o" , po::value<string>() , "output directory" )
+ ("out,o", po::value<string>()->default_value("dump"), "output directory")
;
}
-
+
void doCollection( const string coll , path outputFile ) {
cout << "\t" << coll << " to " << outputFile.string() << endl;
-
+
int out = open( outputFile.string().c_str() , O_WRONLY | O_CREAT | O_TRUNC , 0666 );
assert( out );
-
+
auto_ptr<DBClientCursor> cursor = conn( true ).query( coll.c_str() , Query().snapshot() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout );
int num = 0;
@@ -48,17 +48,17 @@ public:
write( out , obj.objdata() , obj.objsize() );
num++;
}
-
+
cout << "\t\t " << num << " objects" << endl;
-
+
close( out );
- }
-
+ }
+
void go( const string db , const path outdir ) {
cout << "DATABASE: " << db << "\t to \t" << outdir.string() << endl;
create_directories( outdir );
-
+
string sns = db + ".system.namespaces";
auto_ptr<DBClientCursor> cursor = conn( true ).query( sns.c_str() , Query() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout );
@@ -66,37 +66,37 @@ public:
BSONObj obj = cursor->next();
if ( obj.toString().find( ".$" ) != string::npos )
continue;
-
+
const string name = obj.getField( "name" ).valuestr();
const string filename = name.substr( db.size() + 1 );
-
+
if ( _coll.length() > 0 && db + "." + _coll != name && _coll != name )
continue;
-
+
doCollection( name.c_str() , outdir / ( filename + ".bson" ) );
-
+
}
-
+
}
int run(){
- path root( getParam( "out" , "dump" ) );
+ path root( getParam("out") );
string db = _db;
-
+
if ( db == "*" ){
cout << "all dbs" << endl;
auth( "admin" );
-
+
BSONObj res = conn( true ).findOne( "admin.$cmd" , BSON( "listDatabases" << 1 ) );
BSONObj dbs = res.getField( "databases" ).embeddedObjectUserCheck();
set<string> keys;
dbs.getFieldNames( keys );
for ( set<string>::iterator i = keys.begin() ; i != keys.end() ; i++ ) {
string key = *i;
-
+
BSONObj dbobj = dbs.getField( key ).embeddedObjectUserCheck();
-
+
const char * dbName = dbobj.getField( "name" ).valuestr();
if ( (string)dbName == "local" )
continue;