diff --git a/dbm-services/sqlserver/db-tools/dbactuator/pkg/components/sqlserver/restore_dbs_full_backup.go b/dbm-services/sqlserver/db-tools/dbactuator/pkg/components/sqlserver/restore_dbs_full_backup.go index 31c52af860..6a9bb3eb6e 100644 --- a/dbm-services/sqlserver/db-tools/dbactuator/pkg/components/sqlserver/restore_dbs_full_backup.go +++ b/dbm-services/sqlserver/db-tools/dbactuator/pkg/components/sqlserver/restore_dbs_full_backup.go @@ -144,7 +144,7 @@ func (r *RestoreDBSForFullComp) PreCheck() error { } // GetRestorePath 获取这次恢复路径 -// 全量备份恢复的路径的优先级:app_setting表[RESTORE_PATH] > app_setting表[DATA_PATH] > 默认 +// 全量备份恢复的路径的优先级:app_setting表[RESTORE_PATH] > 默认 func (r *RestoreDBSForFullComp) GetRestorePath() error { var infos []AppSettingInfo checkSQL := fmt.Sprintf( @@ -154,17 +154,21 @@ func (r *RestoreDBSForFullComp) GetRestorePath() error { if err := r.LocalDB.Queryx(&infos, checkSQL); err != nil { return fmt.Errorf("select APP_SETTING failed: %v", err) } - if infos[0].RestorePath.Valid && infos[0].RestorePath.String != "" { - r.RestoreDataPath = infos[0].RestorePath.String - r.RestoreLogPath = infos[0].RestorePath.String - return nil - } - if infos[0].DataPath.Valid && infos[0].LogPath.Valid && - infos[0].DataPath.String != "" && infos[0].LogPath.String != "" { - r.RestoreDataPath = infos[0].DataPath.String - r.RestoreLogPath = infos[0].LogPath.String - return nil + // 如果aap_setting没有记录,则走默认 + if len(infos) > 0 { + if infos[0].RestorePath.Valid && infos[0].RestorePath.String != "" { + r.RestoreDataPath = infos[0].RestorePath.String + r.RestoreLogPath = infos[0].RestorePath.String + return nil + } + if infos[0].DataPath.Valid && infos[0].LogPath.Valid && + infos[0].DataPath.String != "" && infos[0].LogPath.String != "" { + r.RestoreDataPath = infos[0].DataPath.String + r.RestoreLogPath = infos[0].LogPath.String + return nil + } } + // 获取默认值 if defaultPath, err := r.LocalDB.GetDefaultPath(); err != nil { return fmt.Errorf("get default path failed: %v", err) } else { diff --git a/dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py b/dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py index 759eb3774d..20c1a34e75 100644 --- a/dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py +++ b/dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py @@ -309,6 +309,12 @@ def switch_slave( new_slave_obj.machine.save(update_fields=["db_module_id"]) cluster.storageinstance_set.add(new_slave_obj) + # 切换slave域名信息 + slave_entry_list = old_slave_obj.bind_entry.filter(cluster_entry_type=ClusterEntryType.DNS.value).all() + for slave_entry in slave_entry_list: + slave_entry.storageinstance_set.remove(old_slave_obj) + slave_entry.storageinstance_set.add(new_slave_obj) + # 添加对应cmdb服务实例信息 SqlserverCCTopoOperator(cluster).transfer_instances_to_cluster_module([new_slave_obj]) @@ -397,7 +403,7 @@ def reduce_slave( old_slave_obj = cluster.storageinstance_set.get(machine__ip=old_slave_host.ip) # 替换域名关联信息 - entry_list = old_slave_obj.bind_entry.all() + entry_list = old_slave_obj.bind_entry.filter(cluster_entry_type=ClusterEntryType.DNS.value).all() for entry in entry_list: entry.storageinstance_set.remove(old_slave_obj) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/common_sub_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/common_sub_flow.py index 0936544403..557eca10d9 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/common_sub_flow.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/common_sub_flow.py @@ -206,6 +206,7 @@ def switch_domain_sub_flow_for_cluster( cluster: Cluster, old_master: StorageInstance, new_master: StorageInstance, + is_force: bool = False, ): """ 主从切换后做域名切换处理 @@ -214,6 +215,7 @@ def switch_domain_sub_flow_for_cluster( @param old_master: 集群原主实例 @param new_master: 集群新主实例 @param cluster: 集群id + @param is_force: 是否属于强切行为,默认不是,强切行为认为主故障,从域名不切换到旧主上 """ # 构造只读上下文 global_data = {"uid": uid, "bk_biz_id": cluster.bk_biz_id} @@ -232,30 +234,31 @@ def switch_domain_sub_flow_for_cluster( "kwargs": asdict( UpdateDnsRecordKwargs( bk_cloud_id=cluster.bk_cloud_id, - old_instance=f"{new_master.machine.ip}#{new_master.port}", - new_instance=f"{old_master.machine.ip}#{old_master.port}", + old_instance=f"{old_master.machine.ip}#{old_master.port}", + new_instance=f"{new_master.machine.ip}#{new_master.port}", update_domain_name=old_master_dns.entry, ), ), } ) # 并发替换从域名映射 - slave_dns_list = new_master.bind_entry.filter(cluster_entry_type=ClusterEntryType.DNS.value).all() - for slave_dns in slave_dns_list: - acts_list.append( - { - "act_name": _("[{}]替换从域名映射".format(slave_dns.entry)), - "act_component_code": MySQLDnsManageComponent.code, - "kwargs": asdict( - UpdateDnsRecordKwargs( - bk_cloud_id=cluster.bk_cloud_id, - old_instance=f"{new_master.machine.ip}#{new_master.port}", - new_instance=f"{old_master.machine.ip}#{old_master.port}", - update_domain_name=slave_dns.entry, + if not is_force: + slave_dns_list = new_master.bind_entry.filter(cluster_entry_type=ClusterEntryType.DNS.value).all() + for slave_dns in slave_dns_list: + acts_list.append( + { + "act_name": _("[{}]替换从域名映射".format(slave_dns.entry)), + "act_component_code": MySQLDnsManageComponent.code, + "kwargs": asdict( + UpdateDnsRecordKwargs( + bk_cloud_id=cluster.bk_cloud_id, + old_instance=f"{new_master.machine.ip}#{new_master.port}", + new_instance=f"{old_master.machine.ip}#{old_master.port}", + update_domain_name=slave_dns.entry, + ), ), - ), - } - ) + } + ) sub_pipeline.add_parallel_acts(acts_list=acts_list) return sub_pipeline.build_sub_process(sub_name=_("变更集群[{}]域名映射".format(cluster.name))) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/sqlserver_add_slave.py b/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/sqlserver_add_slave.py index 8feb801ee1..6d88436dca 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/sqlserver_add_slave.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/sqlserver_add_slave.py @@ -20,6 +20,7 @@ from backend.flow.engine.bamboo.scene.sqlserver.base_flow import BaseFlow from backend.flow.engine.bamboo.scene.sqlserver.common_sub_flow import ( build_always_on_sub_flow, + clone_configs_sub_flow, install_sqlserver_sub_flow, install_surrounding_apps_sub_flow, sync_dbs_for_cluster_sub_flow, @@ -186,6 +187,18 @@ def run_flow(self): ) ) + # 先做克隆周边配置 + cluster_sub_pipeline.add_sub_pipeline( + sub_flow=clone_configs_sub_flow( + uid=self.data["uid"], + root_id=self.root_id, + source_host=Host(ip=master_instance.machine.ip, bk_cloud_id=cluster.bk_cloud_id), + source_port=master_instance.port, + target_host=Host(**info["new_slave_host"]), + target_port=master_instance.port, + ) + ) + # 删除随机账号 cluster_sub_pipeline.add_act( act_name=_("drop job user"), diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/sqlserver_master_slave_switch.py b/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/sqlserver_master_slave_switch.py index b9ae00cfa3..1c382a3678 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/sqlserver_master_slave_switch.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/sqlserver/sqlserver_master_slave_switch.py @@ -188,6 +188,7 @@ def run_flow(self): cluster=cluster, old_master=old_master, new_master=new_master, + is_force=self.data["force"], ) )