Skip to content

Commit

Permalink
fix(mysql): 修复mysql rotate备份客户端问题 close #1513
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlook committed Oct 24, 2023
1 parent cc2f5c2 commit 8f92870
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ CREATE TABLE IF NOT EXISTS `tb_config_name_def` (
`value_default` text,
`value_allowed` text,
`value_type_sub` varchar(100) NOT NULL DEFAULT '' COMMENT 'STRING,ENUM,RANGE,REGEX,JSON,COMPLEX',
`flag_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1: 显式的公共配置 0:不会显式出现在配置文件的全量配置项, 2: 显式的公共配置且只读',
`flag_status` tinyint(4) NOT NULL COMMENT '1: 显式的公共配置 -1:不会显式出现在配置文件的全量配置项, 2: 显式的公共配置且只读',
`flag_disable` tinyint(4) NOT NULL DEFAULT '0' COMMENT '2:readonly, 1:disable, 0:enable, -2: not_allowed_given, -3:must_given',
`flag_locked` tinyint(4) NOT NULL DEFAULT '0',
`flag_encrypt` tinyint(4) NOT NULL DEFAULT '0',
Expand Down
1 change: 1 addition & 0 deletions dbm-services/mysql/db-tools/mysql-rotatebinlog/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var rootCmd = &cobra.Command{
Short: "rotate binlog and backup them to remote",
Long: `rotate binlog files and backup them to remote
backup system`,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
comp := rotate.RotateBinlogComp{Config: viper.GetString("config")}
if removeConfigs, err := cmd.PersistentFlags().GetStringSlice("removeConfig"); err != nil {
Expand Down
23 changes: 15 additions & 8 deletions dbm-services/mysql/db-tools/mysql-rotatebinlog/pkg/rotate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ func (c *RotateBinlogComp) Start() (err error) {
}
var errRet error
for _, inst := range servers {
var backupClient backup.BackupClient
if backupClient, err = backup.InitBackupClient(); err != nil {
err = errs.WithMessagef(err, "init backup_client")
logger.Error("%+v", err.Error())
errRet = errors.Join(errRet, err)
continue
}
inst.backupClient = backupClient // if nil, ignore backup
inst.instance = &native.InsObject{
Host: inst.Host,
Port: inst.Port,
Expand All @@ -114,10 +106,22 @@ func (c *RotateBinlogComp) Start() (err error) {
return errors.Join(errRet, err)
}
for _, inst := range servers {
if inst.rotate == nil {
continue
}
if err = inst.FreeSpace(); err != nil {
logger.Error("FreeSpace %+v", err)
errRet = errors.Join(errRet, err)
}

var backupClient backup.BackupClient
if backupClient, err = backup.InitBackupClient(); err != nil {
err = errs.WithMessagef(err, "init backup_client")
logger.Error("%+v", err.Error())
errRet = errors.Join(errRet, err)
continue
}
inst.backupClient = backupClient // if nil, ignore backup
if err = inst.rotate.Backup(); err != nil {
logger.Error("Backup %+v", err)
errRet = errors.Join(errRet, err)
Expand Down Expand Up @@ -222,6 +226,9 @@ func (c *RotateBinlogComp) decideSizeToFree(servers []*ServerObj) error {
var diskPartInst = make(map[string][]*ServerObj) // 每个挂载目录上,放了哪些binlog实例以及对应的binlog空间
var diskParts = make(map[string]*cmutil.DiskPartInfo) // 目录对应的空间信息
for _, inst := range servers {
if inst.rotate == nil {
continue
}
diskPart, err := util.GetDiskPartitionWithDir(inst.binlogDir)
if err != nil {
logger.Warn("fail to get binlog_dir %s disk partition info", inst.binlogDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ func (i *ServerObj) Rotate() (err error) {
logger.Warn("max_keep_duration=%s is too small, set to %s", maxKeepDuration, cst.MaxKeepDurationMin)
maxKeepDuration = cst.MaxKeepDurationMin
}

if i.dbWorker, err = i.instance.Conn(); err != nil {
return err
}
if i.binlogDir, _, err = i.dbWorker.GetBinlogDir(i.Port); err != nil {
return err
}
rotate := &BinlogRotate{
// binlogDir: i.binlogDir,
backupClient: i.backupClient,
binlogInst: models.BinlogFileModel{
BkBizId: i.Tags.BkBizId,
Expand All @@ -75,17 +81,10 @@ func (i *ServerObj) Rotate() (err error) {
purgeInterval: timeutil.ViperGetDuration("public.purge_interval"),
rotateInterval: timeutil.ViperGetDuration("public.rotate_interval"),
maxKeepDuration: maxKeepDuration,
binlogDir: i.binlogDir,
}
i.rotate = rotate
logger.Info("rotate obj: %+v", rotate)
if i.dbWorker, err = i.instance.Conn(); err != nil {
return err
}
if i.binlogDir, _, err = i.dbWorker.GetBinlogDir(i.Port); err != nil {
return err
} else {
i.rotate.binlogDir = i.binlogDir
}
if err := os.Chmod(i.binlogDir, 0755); err != nil {
return errors.Wrap(err, "chmod 655")
}
Expand Down

0 comments on commit 8f92870

Please sign in to comment.