diff --git a/Readme.md b/Readme.md index c3b7b65..e21d7fa 100644 --- a/Readme.md +++ b/Readme.md @@ -33,6 +33,8 @@ Usage of ./bin/redis-dump-go: Parallel workers (default 10) -noscan Use KEYS * instead of SCAN - for Redis <=2.8 + -noselect + Do not print select statement in result dump (default: false) -output string Output type - can be resp or commands (default "resp") -port int diff --git a/main.go b/main.go index 59b67ee..4984a05 100644 --- a/main.go +++ b/main.go @@ -53,6 +53,7 @@ func realMain() int { db := flag.Uint("db", 0, "only dump this database (default: all databases)") filter := flag.String("filter", "*", "Key filter to use") noscan := flag.Bool("noscan", false, "Use KEYS * instead of SCAN - for Redis <=2.8") + noselect := flag.Bool("noselect", false, "Do not print select statement in result dump (default: false)") nWorkers := flag.Int("n", 10, "Parallel workers") withTTL := flag.Bool("ttl", true, "Preserve Keys TTL") output := flag.String("output", "resp", "Output type - can be resp or commands") @@ -101,12 +102,12 @@ func realMain() int { logger := log.New(os.Stdout, "", 0) if db == nil { - if err = redisdump.DumpServer(*host, *port, redisPassword, *filter, *nWorkers, *withTTL, *noscan, logger, serializer, progressNotifs); err != nil { + if err = redisdump.DumpServer(*host, *port, redisPassword, *filter, *nWorkers, *withTTL, *noscan, *noselect, logger, serializer, progressNotifs); err != nil { fmt.Fprintf(os.Stderr, "%s", err) return 1 } } else { - if err = redisdump.DumpDB(*host, *port, redisPassword, uint8(*db), *filter, *nWorkers, *withTTL, *noscan, logger, serializer, progressNotifs); err != nil { + if err = redisdump.DumpDB(*host, *port, redisPassword, uint8(*db), *filter, *nWorkers, *withTTL, *noscan, *noselect, logger, serializer, progressNotifs); err != nil { fmt.Fprintf(os.Stderr, "%s", err) return 1 } diff --git a/redisdump/redisdump.go b/redisdump/redisdump.go index afdc7e4..50b0cf1 100644 --- a/redisdump/redisdump.go +++ b/redisdump/redisdump.go @@ -262,7 +262,7 @@ func RedisURL(redisHost string, redisPort string, redisDB string, redisPassword } // DumpDB dumps all keys from a single Redis DB -func DumpDB(redisHost string, redisPort int, redisPassword string, db uint8, filter string, nWorkers int, withTTL bool, noscan bool, logger *log.Logger, serializer func([]string) string, progress chan<- ProgressNotification) error { +func DumpDB(redisHost string, redisPort int, redisPassword string, db uint8, filter string, nWorkers int, withTTL bool, noscan bool, noselect bool, logger *log.Logger, serializer func([]string) string, progress chan<- ProgressNotification) error { var err error keyGenerator := scanKeys @@ -289,7 +289,10 @@ func DumpDB(redisHost string, redisPort int, redisPassword string, db uint8, fil if err = client.Do(radix.Cmd(nil, "SELECT", fmt.Sprint(db))); err != nil { return err } - logger.Printf(serializer([]string{"SELECT", fmt.Sprint(db)})) + + if !noselect { + logger.Printf(serializer([]string{"SELECT", fmt.Sprint(db)})) + } done := make(chan bool) keyBatches := make(chan []string) @@ -310,7 +313,7 @@ func DumpDB(redisHost string, redisPort int, redisPassword string, db uint8, fil // DumpServer dumps all Keys from the redis server given by redisURL, // to the Logger logger. Progress notification informations // are regularly sent to the channel progressNotifications -func DumpServer(redisHost string, redisPort int, redisPassword string, filter string, nWorkers int, withTTL bool, noscan bool, logger *log.Logger, serializer func([]string) string, progress chan<- ProgressNotification) error { +func DumpServer(redisHost string, redisPort int, redisPassword string, filter string, nWorkers int, withTTL bool, noscan bool, noselect bool, logger *log.Logger, serializer func([]string) string, progress chan<- ProgressNotification) error { url := RedisURL(redisHost, fmt.Sprint(redisPort), "", redisPassword) dbs, err := getDBIndexes(url) if err != nil { @@ -318,7 +321,7 @@ func DumpServer(redisHost string, redisPort int, redisPassword string, filter st } for _, db := range dbs { - if err = DumpDB(redisHost, redisPort, redisPassword, db, filter, nWorkers, withTTL, noscan, logger, serializer, progress); err != nil { + if err = DumpDB(redisHost, redisPort, redisPassword, db, filter, nWorkers, withTTL, noscan, noselect, logger, serializer, progress); err != nil { return err } }