summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/dump.cpp15
-rw-r--r--tools/export.cpp13
-rw-r--r--tools/restore.cpp5
-rw-r--r--tools/stat.cpp16
-rw-r--r--tools/tool.h6
5 files changed, 46 insertions, 9 deletions
diff --git a/tools/dump.cpp b/tools/dump.cpp
index a1690b2..971575d 100644
--- a/tools/dump.cpp
+++ b/tools/dump.cpp
@@ -37,7 +37,7 @@ class Dump : public Tool {
FILE* _f;
};
public:
- Dump() : Tool( "dump" , ALL , "*" , "*" , false ) {
+ Dump() : Tool( "dump" , ALL , "*" , "*" , true ) {
add_options()
("out,o", po::value<string>()->default_value("dump"), "output directory or \"-\" for stdout")
("query,q", po::value<string>() , "json query" )
@@ -47,6 +47,19 @@ public:
;
}
+ virtual void preSetup() {
+ string out = getParam("out");
+ if ( out == "-" ) {
+ // write output to standard error to avoid mangling output
+ // must happen early to avoid sending junk to stdout
+ useStandardOutput(false);
+ }
+ }
+
+ virtual void printExtraHelp(ostream& out) {
+ out << "Export MongoDB data to BSON files.\n" << endl;
+ }
+
// This is a functor that writes a BSONObj to a file
struct Writer {
Writer(FILE* out, ProgressMeter* m) :_out(out), _m(m) {}
diff --git a/tools/export.cpp b/tools/export.cpp
index c3a5420..0d9f022 100644
--- a/tools/export.cpp
+++ b/tools/export.cpp
@@ -45,6 +45,19 @@ public:
_usesstdout = false;
}
+ virtual void preSetup() {
+ string out = getParam("out");
+ if ( out == "-" ) {
+ // write output to standard error to avoid mangling output
+ // must happen early to avoid sending junk to stdout
+ useStandardOutput(false);
+ }
+ }
+
+ virtual void printExtraHelp( ostream & out ) {
+ out << "Export MongoDB data to CSV, TSV or JSON files.\n" << endl;
+ }
+
// Turn every double quote character into two double quote characters
// If hasSurroundingQuotes is true, doesn't escape the first and last
// characters of the string, if it's false, add a double quote character
diff --git a/tools/restore.cpp b/tools/restore.cpp
index c08c14f..ec0e1d3 100644
--- a/tools/restore.cpp
+++ b/tools/restore.cpp
@@ -73,6 +73,11 @@ public:
_drop = hasParam( "drop" );
_keepIndexVersion = hasParam("keepIndexVersion");
+ if (isMongos() && _db == "" && exists(root / "config")) {
+ cout << "Cannot do a full restore on a sharded system" << endl;
+ return -1;
+ }
+
bool doOplog = hasParam( "oplogReplay" );
if (doOplog) {
// fail early if errors
diff --git a/tools/stat.cpp b/tools/stat.cpp
index e1eda8d..8b1b5aa 100644
--- a/tools/stat.cpp
+++ b/tools/stat.cpp
@@ -365,11 +365,6 @@ namespace mongo {
}
int run() {
- if ( !(_username.empty() || _password.empty()) && isMongos()) {
- cout << "You cannot use mongostat on a mongos running with authentication enabled" << endl;
- return -1;
- }
-
_sleep = getParam( "sleep" , _sleep );
_all = hasParam( "all" );
if ( _many )
@@ -480,6 +475,9 @@ namespace mongo {
string error;
bool mongos;
+
+ string username;
+ string password;
};
static void serverThread( shared_ptr<ServerState> state ) {
@@ -489,8 +487,9 @@ namespace mongo {
string errmsg;
if ( ! conn.connect( state->host , errmsg ) )
state->error = errmsg;
-
long long cycleNumber = 0;
+
+ conn.auth("admin", state->username, state->password, errmsg);
while ( ++cycleNumber ) {
try {
@@ -549,6 +548,9 @@ namespace mongo {
state.reset( new ServerState() );
state->host = host;
state->thr.reset( new boost::thread( boost::bind( serverThread , state ) ) );
+ state->username = _username;
+ state->password = _password;
+
return true;
}
@@ -605,7 +607,7 @@ namespace mongo {
int runMany() {
StateMap threads;
-
+
{
string orig = getParam( "host" );
if ( orig == "" )
diff --git a/tools/tool.h b/tools/tool.h
index e6694f3..e401093 100644
--- a/tools/tool.h
+++ b/tools/tool.h
@@ -82,9 +82,13 @@ namespace mongo {
return _db + "." + _coll;
}
+ void useStandardOutput( bool mode ) {
+ _usesstdout = mode;
+ }
+
bool isMaster();
bool isMongos();
-
+
virtual void preSetup() {}
virtual int run() = 0;