Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mysql): 修复tendbcluster恢复问题 #959

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type InstallNewDbBackupParam struct {
ClusterId map[Port]int `json:"cluster_id"` // cluster id
ShardValue map[Port]int `json:"shard_value"` // shard value for spider
ExecUser string `json:"exec_user"` // 执行Job的用户
UntarOnly bool `json:"untar_only"` // 只解压,不校验不渲染配置
}

type runtimeContext struct {
Expand Down Expand Up @@ -112,6 +113,10 @@ func (i *InstallNewDbBackupComp) Init() (err error) {
i.dbConn = make(map[int]*native.DbWorker)
i.versionMap = make(map[int]string)
i.renderCnf = make(map[int]config.BackupConfig)
if i.Params.UntarOnly {
logger.Info("untar_only=true do not try to connect")
return nil
}
for _, port := range i.Params.Ports {
dbwork, err := native.InsObject{
Host: i.Params.Host,
Expand Down Expand Up @@ -207,6 +212,11 @@ func (i *InstallNewDbBackupComp) getInsShardValue(port int) int {

// InitRenderData 初始化待渲染的配置变量
func (i *InstallNewDbBackupComp) InitRenderData() (err error) {
if i.Params.UntarOnly {
logger.Info("untar_only=true do not need InitRenderData")
return nil
}

bkuser := i.GeneralParam.RuntimeAccountParam.DbBackupUser
bkpwd := i.GeneralParam.RuntimeAccountParam.DbBackupPwd
regexfunc, err := db_table_filter.NewDbTableFilter([]string{"*"}, []string{"*"}, i.ignoredbs, i.ignoretbls)
Expand Down Expand Up @@ -307,6 +317,10 @@ func (i *InstallNewDbBackupComp) DecompressPkg() (err error) {
// InitBackupUserPriv 创建备份用户
// TODO 用户初始化考虑在部署 mysqld 的时候进行
func (i *InstallNewDbBackupComp) InitBackupUserPriv() (err error) {
if i.Params.UntarOnly {
logger.Info("untar_only=true do not need InitBackupUserPriv")
return nil
}
for _, port := range i.Params.Ports {
err := i.initPriv(port, false)
if err != nil {
Expand Down Expand Up @@ -348,6 +362,10 @@ func (i *InstallNewDbBackupComp) initPriv(port int, isTdbCtl bool) (err error) {

// GenerateDbbackupConfig TODO
func (i *InstallNewDbBackupComp) GenerateDbbackupConfig() (err error) {
if i.Params.UntarOnly {
logger.Info("untar_only=true do not need GenerateDbbackupConfig")
return nil
}
// 先渲染模版配置文件
templatePath := path.Join(i.installPath, fmt.Sprintf("%s.tpl", cst.BackupFile))
if err := i.saveTplConfigfile(templatePath); err != nil {
Expand Down Expand Up @@ -458,6 +476,10 @@ func (i *InstallNewDbBackupComp) saveTplConfigfile(tmpl string) (err error) {

// AddCrontab TODO
func (i *InstallNewDbBackupComp) AddCrontab() error {
if i.Params.UntarOnly {
logger.Info("untar_only=true do not need AddCrontab")
return nil
}
if i.Params.ClusterType == cst.TendbCluster {
return i.addCrontabSpider()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (m *DBLoader) getChangeMasterPos(masterInst native.Instance) (*mysqlutil.Ch
return nil, errors.New("no master info found in metadata")
}
if masterInst.Host == "" || masterInst.Port == 0 { // 说明不关注备份位点信息
return nil, nil
return &mysqlutil.ChangeMaster{}, nil
}
// 如果备份文件的源实例,就是当前恢复要change master to 的实例,直接用 MasterStatus info
if masterInfo.MasterHost == masterInst.Host && masterInfo.MasterPort == masterInst.Port {
Expand Down
Loading