diff options
Diffstat (limited to 'bin/bbackupquery/bbackupquery.cpp')
-rw-r--r-- | bin/bbackupquery/bbackupquery.cpp | 79 |
1 files changed, 63 insertions, 16 deletions
diff --git a/bin/bbackupquery/bbackupquery.cpp b/bin/bbackupquery/bbackupquery.cpp index c9d6b715..33860dcf 100644 --- a/bin/bbackupquery/bbackupquery.cpp +++ b/bin/bbackupquery/bbackupquery.cpp @@ -37,6 +37,8 @@ #endif #endif +#include <cstdlib> + #include "MainHelper.h" #include "BoxPortsAndFiles.h" #include "BackupDaemonConfigVerify.h" @@ -61,10 +63,13 @@ void PrintUsageAndExit() #ifdef WIN32 "[-u] " #endif - "\n\t[-c config_file] [-l log_file] [commands]\n" + "\n" + "\t[-c config_file] [-o log_file] [-O log_file_level]\n" + "\t[-l protocol_log_file] [commands]\n" + "\n" "As many commands as you require.\n" "If commands are multiple words, remember to enclose the command in quotes.\n" - "Remember to use quit command if you don't want to drop into interactive mode.\n"); + "Remember to use the quit command unless you want to end up in interactive mode.\n"); exit(1); } @@ -90,7 +95,7 @@ int main(int argc, const char *argv[]) #endif // Really don't want trace statements happening, even in debug mode - #ifndef NDEBUG + #ifndef BOX_RELEASE_BUILD BoxDebugTraceOn = false; #endif @@ -106,24 +111,26 @@ int main(int argc, const char *argv[]) #endif // Flags - bool quiet = false; bool readWrite = false; - Logging::SetProgramName("Box Backup (bbackupquery)"); + Logging::SetProgramName("bbackupquery"); - #ifdef NDEBUG + #ifdef BOX_RELEASE_BUILD int masterLevel = Log::NOTICE; // need an int to do math with #else int masterLevel = Log::INFO; // need an int to do math with #endif #ifdef WIN32 - const char* validOpts = "qvwuc:l:"; + const char* validOpts = "qvwuc:l:o:O:W:"; bool unicodeConsole = false; #else - const char* validOpts = "qvwc:l:"; + const char* validOpts = "qvwc:l:o:O:W:"; #endif + std::string fileLogFile; + Log::Level fileLogLevel = Log::INVALID; + // See if there's another entry on the command line int c; while((c = getopt(argc, (char * const *)argv, validOpts)) != -1) @@ -132,9 +139,6 @@ int main(int argc, const char *argv[]) { case 'q': { - // Quiet mode - quiet = true; - if(masterLevel == Log::NOTHING) { BOX_FATAL("Too many '-q': " @@ -159,6 +163,17 @@ int main(int argc, const char *argv[]) } break; + case 'W': + { + masterLevel = Logging::GetNamedLevel(optarg); + if (masterLevel == Log::INVALID) + { + BOX_FATAL("Invalid logging level"); + return 2; + } + } + break; + case 'w': // Read/write mode readWrite = true; @@ -174,8 +189,24 @@ int main(int argc, const char *argv[]) logFile = ::fopen(optarg, "w"); if(logFile == 0) { - BOX_ERROR("Failed to open log file '" << - optarg << "': " << strerror(errno)); + BOX_LOG_SYS_ERROR("Failed to open log file " + "'" << optarg << "'"); + } + break; + + case 'o': + fileLogFile = optarg; + fileLogLevel = Log::EVERYTHING; + break; + + case 'O': + { + fileLogLevel = Logging::GetNamedLevel(optarg); + if (fileLogLevel == Log::INVALID) + { + BOX_FATAL("Invalid logging level"); + return 2; + } } break; @@ -196,6 +227,19 @@ int main(int argc, const char *argv[]) Logging::SetGlobalLevel((Log::Level)masterLevel); + std::auto_ptr<FileLogger> fileLogger; + if (fileLogLevel != Log::INVALID) + { + fileLogger.reset(new FileLogger(fileLogFile, fileLogLevel)); + } + + bool quiet = false; + if (masterLevel < Log::NOTICE) + { + // Quiet mode + quiet = true; + } + // Print banner? if(!quiet) { @@ -260,7 +304,9 @@ int main(int argc, const char *argv[]) // 2. Connect to server if(!quiet) BOX_INFO("Connecting to store..."); SocketStreamTLS socket; - socket.Open(tlsContext, Socket::TypeINET, conf.GetKeyValue("StoreHostname").c_str(), BOX_PORT_BBSTORED); + socket.Open(tlsContext, Socket::TypeINET, + conf.GetKeyValue("StoreHostname").c_str(), + conf.GetKeyValueInt("StorePort")); // 3. Make a protocol, and handshake if(!quiet) BOX_INFO("Handshake with store..."); @@ -291,7 +337,7 @@ int main(int argc, const char *argv[]) if(!quiet) printf("Login complete.\n\nType \"help\" for a list of commands.\n\n"); // Set up a context for our work - BackupQueries context(connection, conf); + BackupQueries context(connection, conf, readWrite); // Start running commands... first from the command line { @@ -377,7 +423,8 @@ int main(int argc, const char *argv[]) #ifdef WIN32 // Clean up our sockets - WSACleanup(); + // FIXME we should do this, but I get an abort() when I try + // WSACleanup(); #endif MAINHELPER_END |