mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 09:06:21 +01:00
minor: whitespace
This commit is contained in:
parent
eae40d3e62
commit
bf5faae277
@ -33,13 +33,13 @@ public:
|
||||
("out,o" , po::value<string>() , "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" ) );
|
||||
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;
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user