Commit 9a230a54 authored by szh's avatar szh

rename path to btyPath

parent 825852b0
......@@ -12,7 +12,7 @@ import (
)
var (
path string
btyPath string
)
func RaspberryChan() {
......@@ -22,7 +22,7 @@ func RaspberryChan() {
if value.Name == "" {
continue
}
path = GetAbsPath(setting.BityuanSetting.Name)
btyPath = GetAbsPath(setting.BityuanSetting.Name)
switch value.Name {
case "ROLLBACK":
err := rollback()
......@@ -88,12 +88,12 @@ func rollback() error {
time.Sleep(time.Second * 2)
tlog.Info("rollback start","height",pai.LocalLastHeight,"rollbackheight",rollheight)
var buf bytes.Buffer
if path == "" {
tlog.Error("GetAbsPath","err","path not exists")
if btyPath == "" {
tlog.Error("GetAbsPath","err","btyPath not exists")
BityuanFlag.Flag = false
return err
}
cmd := exec.Command(path+"/"+setting.BityuanSetting.Name, "-rollback",fmt.Sprintf("%d",rollheight))
cmd := exec.Command(btyPath+"/"+setting.BityuanSetting.Name, "-rollback",fmt.Sprintf("%d",rollheight))
cmd.Stdout = &buf
err = cmd.Run()
if err != nil {
......@@ -128,7 +128,7 @@ func backup() error {
func SafeBackup() error {
var buf bytes.Buffer
backup := exec.Command("cp","-r",path+"/datadir",path+"/datadir_backup")
backup := exec.Command("cp","-r",btyPath+"/datadir",btyPath+"/datadir_backup")
backup.Stderr = &buf
if err := backup.Run();err != nil {
tlog.Error("SafeBackup","err",buf.String())
......@@ -140,25 +140,25 @@ func SafeBackup() error {
func recoverNode() error {
BityuanFlag.Lock.Lock()
defer BityuanFlag.Lock.Unlock()
if path == "" {
tlog.Error("path empty","err","node not exists")
if btyPath == "" {
tlog.Error("btyPath empty","err","node not exists")
return errors.New("node not exists")
}
backupPath := path + "/datadir_backup"
backupPath := btyPath + "/datadir_backup"
if _,err := os.Stat(backupPath);err != nil {
if os.IsNotExist(err) {
tlog.Error("backup file not exists","err",backupPath)
return errors.New("backup file not exists")
}
}
remove := exec.Command("rm","-rf",path+"/datadir")
remove := exec.Command("rm","-rf",btyPath+"/datadir")
err := remove.Run()
if err != nil {
tlog.Error("rm -rf datadir","err",err)
return err
}
recover := exec.Command("cp","-r",backupPath,path+"/datadir")
recover := exec.Command("cp","-r",backupPath,btyPath+"/datadir")
err = recover.Run()
if err != nil {
tlog.Error("cp -r datadir_backup datadir","err",err)
......@@ -168,12 +168,12 @@ func recoverNode() error {
}
func deleteBackup() error {
path := GetAbsPath(setting.BityuanSetting.Name)
if path == "" {
tlog.Error("path empty","err","node not exists")
btyPath := GetAbsPath(setting.BityuanSetting.Name)
if btyPath == "" {
tlog.Error("btyPath empty","err","node not exists")
return errors.New("node not exists")
}
backupPath := path + "/datadir_backup"
backupPath := btyPath + "/datadir_backup"
if _,err := os.Stat(backupPath);err != nil {
if os.IsNotExist(err) {
tlog.Error("backup file not exists","err",backupPath)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment