From 0f692514644c1f888854c0fa49353fb1fa38ba6d Mon Sep 17 00:00:00 2001 From: lukemakeit <2302063437@qq.com> Date: Mon, 14 Oct 2024 16:29:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(redis):=20dbmon=E5=AE=89=E8=A3=85=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E9=99=A4=E6=97=A0=E6=95=88=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=20#7328?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pkg/atomjobs/atomredis/bkdbmon_install.go | 15 ++------------- .../dbactuator/pkg/common/media_pkg.go | 4 ++++ .../db-tools/dbactuator/pkg/consts/consts.go | 2 +- .../dbactuator/pkg/report/reporter.go | 4 ++++ .../db-tools/dbactuator/pkg/util/util.go | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+), 14 deletions(-) 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..9b65fcfbf5 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) { 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 +}