ledisdb/cmd/ledis-dump/main.go

53 lines
926 B
Go
Raw Normal View History

2014-07-11 06:43:39 +04:00
package main
import (
"flag"
"fmt"
2014-10-23 09:49:57 +04:00
"github.com/siddontang/ledisdb/client/go/ledis"
2014-07-11 06:43:39 +04:00
"os"
)
var host = flag.String("host", "127.0.0.1", "ledis server host")
var port = flag.Int("port", 6380, "ledis server port")
var sock = flag.String("sock", "", "ledis unix socket domain")
var dumpFile = flag.String("o", "./ledis.dump", "dump file to save")
func main() {
flag.Parse()
var err error
var f *os.File
2014-09-18 17:27:43 +04:00
if f, err = os.OpenFile(*dumpFile, os.O_CREATE|os.O_WRONLY, 0644); err != nil {
2014-07-11 06:43:39 +04:00
println(err.Error())
return
}
defer f.Close()
2014-10-23 09:49:57 +04:00
var addr string
2014-07-11 06:43:39 +04:00
if len(*sock) != 0 {
2014-10-23 09:49:57 +04:00
addr = *sock
2014-07-11 06:43:39 +04:00
} else {
2014-10-23 09:49:57 +04:00
addr = fmt.Sprintf("%s:%d", *host, *port)
2014-07-11 06:43:39 +04:00
}
2014-10-23 09:49:57 +04:00
c := ledis.NewConnSize(addr, 16*1024, 4096)
2014-07-11 06:43:39 +04:00
defer c.Close()
println("dump begin")
2014-10-23 09:49:57 +04:00
if err = c.Send("fullsync"); err != nil {
2014-07-11 06:43:39 +04:00
println(err.Error())
return
}
2014-10-23 09:49:57 +04:00
if err = c.ReceiveBulkTo(f); err != nil {
2014-07-11 06:43:39 +04:00
println(err.Error())
return
}
println("dump end")
}