func main() { // initialize command-line opts opts := options.New("mongodump", mongodump.Usage, options.EnabledOptions{true, true, true}) inputOpts := &mongodump.InputOptions{} opts.AddOptions(inputOpts) outputOpts := &mongodump.OutputOptions{} opts.AddOptions(outputOpts) args, err := opts.Parse() if err != nil { log.Logf(log.Always, "error parsing command line options: %v", err) log.Logf(log.Always, "try 'mongodump --help' for more information") os.Exit(util.ExitBadOptions) } if len(args) > 0 { log.Logf(log.Always, "positional arguments not allowed: %v", args) log.Logf(log.Always, "try 'mongodump --help' for more information") os.Exit(util.ExitBadOptions) } // print help, if specified if opts.PrintHelp(false) { return } // print version, if specified if opts.PrintVersion() { return } // init logger log.SetVerbosity(opts.Verbosity) // connect directly, unless a replica set name is explicitly specified _, setName := util.ParseConnectionString(opts.Host) opts.Direct = (setName == "") opts.ReplicaSetName = setName dump := mongodump.MongoDump{ ToolOptions: opts, OutputOptions: outputOpts, InputOptions: inputOpts, } if err = dump.Init(); err != nil { log.Logf(log.Always, "Failed: %v", err) os.Exit(util.ExitError) } if err = dump.Dump(); err != nil { log.Logf(log.Always, "Failed: %v", err) if err == util.ErrTerminated { os.Exit(util.ExitKill) } os.Exit(util.ExitError) } }
func main() { // initialize command-line opts opts := commonopts.New("mongodump", "0.0.1", "<options>") inputOpts := &options.InputOptions{} opts.AddOptions(inputOpts) outputOpts := &options.OutputOptions{} opts.AddOptions(outputOpts) _, err := opts.Parse() if err != nil { fmt.Printf("error parsing command line options: %v\n\n", err) fmt.Printf("try 'mongodump --help' for more information\n") os.Exit(2) } // print help, if specified if opts.PrintHelp() { return } // print version, if specified if opts.PrintVersion() { return } // init logger log.InitToolLogger(opts.Verbosity) // create a session provider to connect to the db sessionProvider, err := db.InitSessionProvider(opts) if err != nil { fmt.Printf("error initializing database session: %v\n", err) os.Exit(1) //TODO copy legacy exit code } dump := mongodump.MongoDump{ ToolOptions: opts, OutputOptions: outputOpts, InputOptions: inputOpts, SessionProvider: sessionProvider, } err = dump.Dump() if err != nil { util.Exitf(1, "%v", err) } }
func main() { // initialize command-line opts opts := options.New("mongodump", mongodump.Usage, options.EnabledOptions{true, true, true}) inputOpts := &mongodump.InputOptions{} opts.AddOptions(inputOpts) outputOpts := &mongodump.OutputOptions{} opts.AddOptions(outputOpts) args, err := opts.Parse() if err != nil { log.Logvf(log.Always, "error parsing command line options: %v", err) log.Logvf(log.Always, "try 'mongodump --help' for more information") os.Exit(util.ExitBadOptions) } if len(args) > 0 { log.Logvf(log.Always, "positional arguments not allowed: %v", args) log.Logvf(log.Always, "try 'mongodump --help' for more information") os.Exit(util.ExitBadOptions) } // print help, if specified if opts.PrintHelp(false) { return } // print version, if specified if opts.PrintVersion() { return } // init logger log.SetVerbosity(opts.Verbosity) // connect directly, unless a replica set name is explicitly specified _, setName := util.ParseConnectionString(opts.Host) opts.Direct = (setName == "") opts.ReplicaSetName = setName // kick off the progress bar manager progressManager := progress.NewBarWriter(log.Writer(0), progressBarWaitTime, progressBarLength, false) progressManager.Start() defer progressManager.Stop() dump := mongodump.MongoDump{ ToolOptions: opts, OutputOptions: outputOpts, InputOptions: inputOpts, ProgressManager: progressManager, } finishedChan := signals.HandleWithInterrupt(dump.HandleInterrupt) defer close(finishedChan) if err = dump.Init(); err != nil { log.Logvf(log.Always, "Failed: %v", err) os.Exit(util.ExitError) } if err = dump.Dump(); err != nil { log.Logvf(log.Always, "Failed: %v", err) if err == util.ErrTerminated { os.Exit(util.ExitKill) } os.Exit(util.ExitError) } }