Skip to content

Commit

Permalink
fix(redis): dbmon安装时,删除无效文件链接 TencentBlueKing#7328
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemakeit authored and iSecloud committed Oct 14, 2024
1 parent c46de01 commit 0f69251
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions dbm-services/redis/db-tools/dbactuator/pkg/report/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions dbm-services/redis/db-tools/dbactuator/pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 0f69251

Please sign in to comment.