2014-07-11 12:57:25 +04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2015-05-04 17:42:28 +03:00
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
"github.com/siddontang/ledisdb/config"
|
2014-07-11 12:57:25 +04:00
|
|
|
"github.com/siddontang/ledisdb/ledis"
|
|
|
|
)
|
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
ldb, err := ledis.Open(cfg)
|
2014-07-11 12:57:25 +04:00
|
|
|
if err != nil {
|
|
|
|
println("ledis open error ", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
err = loadDump(cfg, ldb)
|
2014-07-11 12:57:25 +04:00
|
|
|
ldb.Close()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
println(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
println("Load OK")
|
|
|
|
}
|
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
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-22 13:50:51 +04:00
|
|
|
_, err = ldb.LoadDumpFile(*dumpPath)
|
|
|
|
return err
|
2014-07-11 12:57:25 +04:00
|
|
|
}
|