Skip to content

add option to skip "select" statement in resulting dump #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 7 additions & 4 deletions redisdump/redisdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -310,15 +313,15 @@ 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 {
return err
}

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
}
}
Expand Down