2014-07-11 06:43:39 +04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2015-05-04 17:42:28 +03:00
|
|
|
|
|
|
|
"github.com/siddontang/goredis"
|
2014-07-11 06:43:39 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-03-11 06:54:02 +03:00
|
|
|
c, err := goredis.ConnectWithSize(addr, 16*1024, 4096)
|
2015-03-02 12:12:55 +03:00
|
|
|
if err != nil {
|
|
|
|
println(err.Error())
|
|
|
|
return
|
|
|
|
}
|
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")
|
|
|
|
}
|