Skip to content

Commit

Permalink
feat(mongodb): pit_restore #7478
Browse files Browse the repository at this point in the history
  • Loading branch information
cycker authored and cycker committed Nov 27, 2024
1 parent 2700a73 commit 1ee68fe
Show file tree
Hide file tree
Showing 9 changed files with 578 additions and 129 deletions.
12 changes: 7 additions & 5 deletions dbm-ui/backend/db_services/mongodb/restore/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class MongoDBRestoreHandler(object):
"""mongodb定点构造函数封装"""

def __init__(self, cluster_id: int):
self.cluster = Cluster.objects.get(id=cluster_id)
self.cluster_id = cluster_id
# self.cluster = Cluster.objects.get(id=cluster_id)

@staticmethod
def _get_log_from_bklog(collector: str, start_time: datetime, end_time: datetime, query_string="*") -> List[Dict]:
Expand All @@ -52,15 +53,16 @@ def _query_latest_log_and_index(self, rollback_time: datetime, query_string: str
query_string=query_string,
)
if not backup_logs:
raise AppBaseException(_("距离回档时间点7天内没有备份日志 {} {}").format(query_string, rollback_time))
raise AppBaseException(_("距离回档时间点{}天内没有备份日志 query_string: {} from {} to {}").format(
BACKUP_LOG_RANGE_DAYS, query_string, start_time, end_time))

# 获取距离回档时间最近的全备日志
backup_logs.sort(key=lambda x: x[time_key])
time_keys = [log[time_key] for log in backup_logs]
try:
latest_backup_log_index = find_nearby_time(time_keys, rollback_time, flag)
except IndexError:
raise AppBaseException(_("无法找到时间点{}附近的全备日志记录 query_string:{} ").format(rollback_time, query_string))
raise AppBaseException(_("无法找到时间点{}附近的全备日志记录 query_string:{}").format(rollback_time, query_string))

return backup_logs, latest_backup_log_index

Expand All @@ -71,7 +73,7 @@ def query_latest_backup_log(self, rollback_time: datetime, set_name: str = None)
@param set_name: 指定SetName. cluster_type为ReplicaSet时,只有一个set_name, 可以为空.
"""
# 获取距离回档时间最近的全备日志
query_string = f"cluster_id: {self.cluster.id} AND pitr_file_type: {PitrFillType.FULL}"
query_string = f"cluster_id: {self.cluster_id} AND pitr_file_type: {PitrFillType.FULL}"
if set_name is not None:
query_string += f" AND set_name: {set_name}"
full_backup_logs, full_latest_index = self._query_latest_log_and_index(
Expand All @@ -82,7 +84,7 @@ def query_latest_backup_log(self, rollback_time: datetime, set_name: str = None)
# 找到与全备日志pitr_fullname相同的增量备份日志
pitr_fullname = latest_full_backup_log["pitr_fullname"]
query_string = (
f"cluster_id: {self.cluster.id} AND pitr_file_type: {PitrFillType.INCR} AND pitr_fullname: {pitr_fullname}"
f"cluster_id: {self.cluster_id} AND pitr_file_type: {PitrFillType.INCR} AND pitr_fullname: {pitr_fullname}"
)
if set_name is not None:
query_string += f" AND set_name: {set_name}"
Expand Down
2 changes: 2 additions & 0 deletions dbm-ui/backend/flow/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ class MongoDBActuatorActionEnum(str, StructuredEnum):
InstallDBMon = EnumField("install_dbmon", _("install_dbmon"))
MongoStart = EnumField("mongo_start", _("mongo_start"))
MongoHello = EnumField("mongodb_hello", _("mongodb_hello"))
MongoPitrRebuild = EnumField("mongodb_pitr_rebuild", _("mongodb_pitr_rebuild"))
MongoInstanceOp = EnumField("mongodb_instance_op", _("mongodb_instance_op"))


class EsActuatorActionEnum(str, StructuredEnum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def get_pkg_info():
# repo_version 如果REPO_VERSION_FOR_DEV有值,则使用REPO_VERSION_FOR_DEV,否则使用最新版本
# 正式环境中,REPO_VERSION_FOR_DEV为空
# 个人测试环境中,REPO_VERSION_FOR_DEV 按需配置
repo_version = env.REPO_VERSION_FOR_DEV if env.REPO_VERSION_FOR_DEV else MediumEnum.Latest

dev_env = str(env.REPO_VERSION_FOR_DEV)
repo_version = dev_env if dev_env != "" else MediumEnum.Latest
actuator_pkg = Package.get_latest_package(
version=repo_version, pkg_type=MediumEnum.DBActuator, db_type=DBType.MongoDB
)
Expand All @@ -47,7 +47,8 @@ def get_pkg_info():
toolkit_pkg = Package.get_latest_package(
version=MediumEnum.Latest, pkg_type="mongo-toolkit", db_type=DBType.MongoDB
)
dbmon_pkg = Package.get_latest_package(version=MediumEnum.Latest, pkg_type="dbmon", db_type=DBType.MongoDB)
dbmon_pkg = Package.get_latest_package(version=MediumEnum.Latest
, pkg_type="dbmon", db_type=DBType.MongoDB)
return {
"actuator_pkg": actuator_pkg,
"dbmon_pkg": dbmon_pkg,
Expand Down Expand Up @@ -103,7 +104,7 @@ def add_install_dbmon(root_id, flow_data, pipeline, iplist, bk_cloud_id, allow_e
bk_host_list.extend(sub_bk_host_list)
sub_pipelines.append(sub_pl.build_sub_process(_("dbmon-{}").format(ip)))

# 介质下发,包括actuator+dbmon+dbtools 如果文件没有变化,不会占用带宽
# 介质下发,包括actuator+dbmon+dbtools
pipeline.add_act(
**SendMedia.act(
act_name=_("CpFile: actuator+dbmon+dbtools+toolkit"),
Expand Down
Loading

0 comments on commit 1ee68fe

Please sign in to comment.