diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-09-11 16:15:15 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-09-11 16:15:15 -0400 |
commit | 96a5d76821ef9b41d44ad13a1709447c81c341d1 (patch) | |
tree | ea613e21949170ed854fecbe137cf7aeb6ccf92a | |
parent | 335d92c443e23df5912f31f6310b8dbb5b23fda3 (diff) | |
parent | c03fe0d5c592a72b9be4404297c6404422529ccb (diff) | |
download | mongo-96a5d76821ef9b41d44ad13a1709447c81c341d1.tar.gz |
Merge branch 'master' of git@github.com:mongodb/mongo
-rw-r--r-- | tools/dump.cpp | 38 | ||||
-rw-r--r-- | tools/files.cpp | 7 | ||||
-rw-r--r-- | tools/restore.cpp | 28 |
3 files changed, 37 insertions, 36 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; diff --git a/tools/files.cpp b/tools/files.cpp index 6a81cece337..a422be55c7d 100644 --- a/tools/files.cpp +++ b/tools/files.cpp @@ -46,9 +46,10 @@ public: out << "usage: " << _name << " [options] command [filename]" << endl; out << "command:" << endl; out << " one of (list|search|put|get)" << endl; - out << " list - list all files. takes an optional filename. " << endl; - out << " listed files must start with the filename." << endl; - out << " search - search all files for something that contains the string" << endl; + out << " list - list all files. takes an optional prefix " << endl; + out << " which listed filenames must begin with." << endl; + out << " search - search all files. takes an optional substring " << endl; + out << " which listed filenames must contain." << endl; out << " put - add a file" << endl; out << " get - get a file" << endl; } diff --git a/tools/restore.cpp b/tools/restore.cpp index 615de0bd185..5d2d795dd35 100644 --- a/tools/restore.cpp +++ b/tools/restore.cpp @@ -37,13 +37,13 @@ public: ; addPositionArg( "dir" , 1 ); } - + int run(){ auth(); drillDown( getParam( "dir" ) ); return 0; } - + void drillDown( path root ) { if ( is_directory( root ) ) { @@ -56,15 +56,15 @@ public: } return; } - + if ( ! ( endsWith( root.string().c_str() , ".bson" ) || endsWith( root.string().c_str() , ".bin" ) ) ) { cerr << "don't know what to do with [" << root.string() << "]" << endl; return; } - + out() << root.string() << endl; - + string ns; { string dir = root.branch_path().string(); @@ -73,39 +73,39 @@ public: else ns += dir.substr( dir.find_last_of( "/" ) + 1 ); } - + { string l = root.leaf(); l = l.substr( 0 , l.find_last_of( "." ) ); ns += "." + l; } - + if ( boost::filesystem::file_size( root ) == 0 ) { out() << "file " + root.native_file_string() + " empty, skipping" << endl; return; } out() << "\t going into namespace [" << ns << "]" << endl; - + MemoryMappedFile mmf; long fileLength; assert( mmf.map( root.string().c_str() , fileLength ) ); - + log(1) << "\t file size: " << fileLength << endl; char * data = (char*)mmf.viewOfs(); long read = 0; - + long num = 0; - + int msgDelay = (int)(1000 * ( 1 + ( mmf.length() / ( 1024.0 * 1024 * 400 ) ) ) ); log(1) << "\t msg delay: " << msgDelay << endl; while ( read < mmf.length() ) { BSONObj o( data ); - + conn().insert( ns.c_str() , o ); - + read += o.objsize(); data += o.objsize(); @@ -113,7 +113,7 @@ public: if ( logLevel > 0 && num < 10 || ! ( num % msgDelay ) ) out() << "read " << read << "/" << mmf.length() << " bytes so far. (" << (int)( (read * 100) / mmf.length()) << "%) " << num << " objects" << endl; } - + out() << "\t " << num << " objects" << endl; } }; |