ledisdb/cmd/ledis-load/main.go

75 lines
1.3 KiB
Go
Raw Normal View History

2014-07-11 12:57:25 +04:00
package main
import (
"flag"
"fmt"
"github.com/siddontang/ledisdb/config"
2014-07-11 12:57:25 +04:00
"github.com/siddontang/ledisdb/ledis"
)
var configPath = flag.String("config", "", "ledisdb config file")
2014-07-11 12:57:25 +04:00
var dumpPath = flag.String("dump_file", "", "ledisdb dump file")
func main() {
flag.Parse()
if len(*configPath) == 0 {
println("need ledis config file")
return
}
cfg, err := config.NewConfigWithFile(*configPath)
2014-07-11 12:57:25 +04:00
if err != nil {
println(err.Error())
return
}
if len(*dumpPath) == 0 {
println("need dump file")
return
}
if len(cfg.DataDir) == 0 {
println("must set data dir")
return
}
ldb, err := ledis.Open(cfg)
2014-07-11 12:57:25 +04:00
if err != nil {
println("ledis open error ", err.Error())
return
}
err = loadDump(cfg, ldb)
2014-07-11 12:57:25 +04:00
ldb.Close()
if err != nil {
println(err.Error())
return
}
println("Load OK")
}
func loadDump(cfg *config.Config, ldb *ledis.Ledis) error {
2014-07-11 12:57:25 +04:00
var err error
if err = ldb.FlushAll(); err != nil {
return err
}
2014-09-04 18:43:56 +04:00
var head *ledis.BinLogAnchor
2014-07-11 12:57:25 +04:00
head, err = ldb.LoadDumpFile(*dumpPath)
if err != nil {
return err
}
//master enable binlog, here output this like mysql
if head.LogFileIndex != 0 && head.LogPos != 0 {
2014-07-20 12:16:12 +04:00
format := "MASTER_LOG_FILE='binlog.%07d', MASTER_LOG_POS=%d;\n"
fmt.Printf(format, head.LogFileIndex, head.LogPos)
}
2014-07-11 12:57:25 +04:00
return nil
2014-07-11 12:57:25 +04:00
}