diff --git a/dbm-ui/backend/db_services/mysql/fixpoint_rollback/handlers.py b/dbm-ui/backend/db_services/mysql/fixpoint_rollback/handlers.py index 23f1f8e7fc..6031b8695c 100644 --- a/dbm-ui/backend/db_services/mysql/fixpoint_rollback/handlers.py +++ b/dbm-ui/backend/db_services/mysql/fixpoint_rollback/handlers.py @@ -385,7 +385,8 @@ def query_binlog_from_bklog( ) if not binlogs: - raise AppBaseException(_("无法查找在时间范围内{}-{},主机{}的binlog日志").format(start_time, end_time, host_ip)) + return {} + # raise AppBaseException(_("无法查找在时间范围内{}-{},主机{}的binlog日志").format(start_time, end_time, host_ip)) # 根据stop_time和host进行过滤(字典外层参数cluster_domain,cluster_id,host,port都一样) binlog_record: Dict[str, Union[str, List]] = { diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/common/get_binlog_backup.py b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/common/get_binlog_backup.py index e93867c99c..748ccbc9c5 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mysql/common/get_binlog_backup.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mysql/common/get_binlog_backup.py @@ -27,21 +27,8 @@ def get_backup_binlog( return result # 先从别分文件的主节点查询,查询不到改为从节点查询。 rollback_handler = FixPointRollbackHandler(cluster_id) - backup_binlog = rollback_handler.query_binlog_from_bklog( - start_time=start_time, - end_time=end_time, - host_ip=binlog_info["show_master_status"]["master_host"], - port=binlog_info["show_master_status"]["master_port"], - minute_range=minute_range, - ) - result["binlog_start_file"] = binlog_info["show_master_status"]["binlog_file"] - result["binlog_start_pos"] = binlog_info["show_master_status"]["binlog_pos"] - if backup_binlog is None: - if "show_slave_status" not in binlog_info.keys(): - result["query_binlog_error"] = _( - "获取原主节点 {} binlog失败".format(binlog_info["show_master_status"]["master_host"]) - ) - return result + backup_binlog = None + if "show_slave_status" in binlog_info.keys(): backup_binlog = rollback_handler.query_binlog_from_bklog( start_time=start_time, end_time=end_time, @@ -51,9 +38,21 @@ def get_backup_binlog( ) result["binlog_start_file"] = binlog_info["show_slave_status"]["binlog_file"] result["binlog_start_pos"] = binlog_info["show_slave_status"]["binlog_pos"] + logger.info("master binlog is:", backup_binlog) + + if backup_binlog is None or len(backup_binlog) == 0: + backup_binlog = rollback_handler.query_binlog_from_bklog( + start_time=start_time, + end_time=end_time, + host_ip=binlog_info["show_master_status"]["master_host"], + port=binlog_info["show_master_status"]["master_port"], + minute_range=minute_range, + ) + result["binlog_start_file"] = binlog_info["show_master_status"]["binlog_file"] + result["binlog_start_pos"] = binlog_info["show_master_status"]["binlog_pos"] if backup_binlog is None: - result["query_binlog_error"] = _("获取原主节点{} 和 原从节点{} 的binlog失败").format( - binlog_info["show_master_status"]["master_host"], binlog_info["show_slave_status"]["master_host"] + result["query_binlog_error"] = _("原备份节点节点{} 的binlog失败").format( + binlog_info["show_master_status"]["master_host"] ) return result result["binlog_task_ids"] = [i["task_id"] for i in backup_binlog["file_list_details"]]