ledisdb/cmd/ledis-repair/main.go

42 lines
722 B
Go
Raw Normal View History

2014-06-26 07:04:54 +04:00
package main
import (
"encoding/json"
"flag"
"github.com/siddontang/ledisdb/ledis"
"github.com/siddontang/ledisdb/leveldb"
"io/ioutil"
"path"
)
var fileName = flag.String("config", "/etc/ledis.config", "ledisdb config file")
func main() {
flag.Parse()
data, err := ioutil.ReadFile(fileName)
if err != nil {
println(err.Error())
return
}
var cfg ledis.Config
if err = json.Unmarshal(data, &cfg); err != nil {
println(err.Error())
return
}
if len(cfg.DataDir) == 0 {
println("must set data dir")
return
}
if len(cfg.DataDB.Path) == 0 {
cfg.DataDB.Path = path.Join(cfg.DataDir, "data")
}
if err = leveldb.Repair(&cfg.DataDB); err != nil {
println("repair error: ", err.Error())
}
}