diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomredis/bkdbmon_install.go b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomredis/bkdbmon_install.go index d34c4d1d9f..5b92db1091 100644 --- a/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomredis/bkdbmon_install.go +++ b/dbm-services/redis/db-tools/dbactuator/pkg/atomjobs/atomredis/bkdbmon_install.go @@ -243,19 +243,8 @@ func (job *BkDbmonInstall) UntarMedia() (err error) { return } // 如果 /home/mysql/bk-dbmon 是一个无效的软链接,则删除 - if util.FileExists(consts.BkDbmonPath) { - var stat fs.FileInfo - var link string - stat, err = os.Stat(consts.BkDbmonPath) - if err == nil && stat.Mode()&os.ModeSymlink != 0 { - link, err = os.Readlink(consts.BkDbmonPath) - if err == nil && !util.FileExists(link) { - rmCmd := fmt.Sprintf("rm -rf %s", consts.BkDbmonPath) - job.runtime.Logger.Info(rmCmd) - util.RunBashCmd(rmCmd, "", nil, 1*time.Minute) - } - } - } + util.RemoveInvalidSoftLink(consts.BkDbmonPath) + remoteVersion = l01[1] if util.FileExists(consts.BkDbmonBin) { cmd := fmt.Sprintf("%s -v |awk '{print $2}'", consts.BkDbmonBin) diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/common/media_pkg.go b/dbm-services/redis/db-tools/dbactuator/pkg/common/media_pkg.go index dd294e91aa..4919c1af34 100644 --- a/dbm-services/redis/db-tools/dbactuator/pkg/common/media_pkg.go +++ b/dbm-services/redis/db-tools/dbactuator/pkg/common/media_pkg.go @@ -70,6 +70,10 @@ func (pkg *DbToolsMediaPkg) Install() (err error) { // if err != nil { // return // } + + // 如果 /home/mysql/dbtools 是个无效的软链接,则删除 + util.RemoveInvalidSoftLink(consts.DbToolsPath) + toolsName := filepath.Base(consts.DbToolsPath) backupDir := filepath.Join(consts.GetRedisBackupDir(), "dbbak") // 如 /data/dbbak bakdirToolsTar := filepath.Join(backupDir, toolsName+".tar.gz") // 如 /data/dbbak/dbtools.tar.gz diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/consts/consts.go b/dbm-services/redis/db-tools/dbactuator/pkg/consts/consts.go index b599387f25..38b5e1ba09 100644 --- a/dbm-services/redis/db-tools/dbactuator/pkg/consts/consts.go +++ b/dbm-services/redis/db-tools/dbactuator/pkg/consts/consts.go @@ -116,7 +116,7 @@ const ( PackageSavePath = "/data/install" Data1Path = "/data1" DataPath = "/data" - DbaReportSaveDir = "/home/mysql/dbareport/" + DbaReportSaveDir = "/home/mysql/dbareport" RedisReportSaveDir = "/home/mysql/dbareport/redis/" ExporterConfDir = "/home/mysql/.exporter" RedisReportLeftDay = 15 diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/report/reporter.go b/dbm-services/redis/db-tools/dbactuator/pkg/report/reporter.go index 04a963c19b..8dc2c360a3 100644 --- a/dbm-services/redis/db-tools/dbactuator/pkg/report/reporter.go +++ b/dbm-services/redis/db-tools/dbactuator/pkg/report/reporter.go @@ -20,6 +20,10 @@ type Reporter interface { // CreateReportDir 创建上报目录 /home/mysql/dbareport -> {REDIS_BACKUP_DIR}/dbbak/dbareport func CreateReportDir() (err error) { mylog.Logger.Info("begin to create reportDir(%s)", consts.DbaReportSaveDir) + + // 如果 /home/mysql/dbareport 是个无效的软链接,则删除 + util.RemoveInvalidSoftLink(consts.DbaReportSaveDir) + var realLink string realReportDir := filepath.Join(consts.GetRedisBackupDir(), "dbbak", "dbareport") // 如 /data/dbbak/dbareport if !util.FileExists(realReportDir) { @@ -45,7 +49,7 @@ func CreateReportDir() (err error) { rmCmd := "rm -rf " + consts.DbaReportSaveDir util.RunBashCmd(rmCmd, "", nil, 1*time.Minute) } - err = os.Symlink(realReportDir, filepath.Dir(consts.DbaReportSaveDir)) + err = os.Symlink(realReportDir, consts.DbaReportSaveDir) if err != nil { err = fmt.Errorf("os.Symlink %s -> %s fail,err:%s", consts.DbaReportSaveDir, realReportDir, err) mylog.Logger.Error(err.Error()) diff --git a/dbm-services/redis/db-tools/dbactuator/pkg/util/util.go b/dbm-services/redis/db-tools/dbactuator/pkg/util/util.go index 6bd1accee0..09eb7bd777 100644 --- a/dbm-services/redis/db-tools/dbactuator/pkg/util/util.go +++ b/dbm-services/redis/db-tools/dbactuator/pkg/util/util.go @@ -15,6 +15,7 @@ import ( "syscall" "time" + "dbm-services/redis/db-tools/dbactuator/mylog" "dbm-services/redis/db-tools/dbactuator/pkg/consts" "github.com/dustin/go-humanize" @@ -314,3 +315,21 @@ func SizeToHumanStr(ssize int64) string { } return "-" + humanize.BigIBytes((&big.Int{}).SetInt64(-ssize)) } + +// RemoveInvalidSoftLink 删除无效的软链接 +func RemoveInvalidSoftLink(softLink string) (err error) { + softLink = strings.TrimSpace(softLink) + if softLink == "" { + mylog.Logger.Info(fmt.Sprintf("softLink %s is empty,skip RemoveInvalidSoftLink", softLink)) + return nil + } + execCmd := fmt.Sprintf(` + if [[ -L %q && ! -e %q ]] + then + rm -rf %s + fi + `, softLink, softLink, softLink) + mylog.Logger.Info(execCmd) + _, err = RunBashCmd(execCmd, "", nil, 2*time.Minute) + return +}