diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-03-05 13:07:29 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-03-05 13:07:29 -0500 |
commit | 8ec2fbf7eae13ca449af7381a6e03beba9a42a8b (patch) | |
tree | afaad091040e2ba0eb2c509ff4df837b5b1000d6 /tools | |
parent | 7969923944bcc61e53782f7f570bc35a4982f3b5 (diff) | |
download | mongo-8ec2fbf7eae13ca449af7381a6e03beba9a42a8b.tar.gz |
--drop and --objchek for restore
Diffstat (limited to 'tools')
-rw-r--r-- | tools/restore.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/tools/restore.cpp b/tools/restore.cpp index 8c2226b4d4e..3efefe1fdfa 100644 --- a/tools/restore.cpp +++ b/tools/restore.cpp @@ -31,9 +31,15 @@ namespace po = boost::program_options; class Restore : public Tool { public: - Restore() : Tool( "restore" , true , "" , "" ){ + + bool _drop; + bool _objcheck; + + Restore() : Tool( "restore" , true , "" , "" ) , _drop(false),_objcheck(false){ add_hidden_options() ("dir", po::value<string>()->default_value("dump"), "directory to restore from") + ("drop" , "drop each collection before import" ) + ("objcheck" , "validate object before inserting" ) ; addPositionArg("dir", 1); } @@ -45,6 +51,8 @@ public: int run(){ auth(); path root = getParam("dir"); + _drop = hasParam( "drop" ); + _objcheck = hasParam( "objcheck" ); /* If _db is not "" then the user specified a db name to restore as. * @@ -129,6 +137,11 @@ public: out() << "\t going into namespace [" << ns << "]" << endl; + if ( _drop ){ + out() << "\t dropping" << endl; + conn().dropCollection( ns ); + } + string fileString = root.string(); ifstream file( fileString.c_str() , ios_base::in | ios_base::binary); if ( ! file.is_open() ){ @@ -158,6 +171,22 @@ public: file.read( buf + 4 , size - 4 ); BSONObj o( buf ); + if ( _objcheck && ! o.valid() ){ + cerr << "INVALID OBJECT - going try and pring out " << endl; + cerr << "size: " << size << endl; + BSONObjIterator i(o); + while ( i.more() ){ + BSONElement e = i.next(); + try { + e.validate(); + } + catch ( ... ){ + cerr << "\t\t NEXT ONE IS INVALID" << endl; + } + cerr << "\t name : " << e.fieldName() << endl; + cerr << "\t " << e << endl; + } + } conn().insert( ns.c_str() , o ); read += o.objsize(); |