Skip to content

Commit 78907e2

Browse files
mikliapkosoyacz
authored andcommitted
feature(manager): extend sctool restore task with dc-mapping flag
To run a restore task for multiDC cluster with EaR enabled (otherwise fails #1), the special flag has been introduced in Manager (#2) to map backed up DC with DC under restore, for example, sctool restore ... --dc-mapping dc1=dc1,dc2=dc2 The change introduces this new flag into `create_restore_task` method and makes sure that if Scylla cluster has more than 1 datacenter - the restore task will be triggered with this flag applied. refs: 1. scylladb/scylla-manager#3871 2. scylladb/scylla-manager#4213
1 parent 072a599 commit 78907e2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mgmt_cli_test.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,18 @@ def locations(self) -> list[str]:
646646
# FIXME: Make it works with multiple locations or file a bug for scylla-manager.
647647
return [f"{backend}:{location}" for location in buckets[:1]]
648648

649+
def get_dc_mapping(self) -> str | None:
650+
"""Get the datacenter mapping string for the restore task if there are > 1 DCs (multiDC) in the cluster.
651+
In case of singleDC, return None.
652+
653+
Example of return string:
654+
eu-west-2scylla_node_west=eu-west-2scylla_node_west,us-eastscylla_node_east=us-eastscylla_node_east
655+
"""
656+
if len(dcs := self.get_all_dcs_names()) > 1:
657+
return ",".join([f"{dc}={dc}" for dc in dcs])
658+
else:
659+
return None
660+
649661
# pylint: disable=too-many-arguments
650662
def verify_backup_success(self, mgr_cluster, backup_task, ks_names: list = None, tables_names: list = None,
651663
truncate=True, restore_data_with_task=False, timeout=None):
@@ -726,9 +738,10 @@ def restore_backup_without_manager(self, mgr_cluster, snapshot_tag, ks_tables_li
726738
def restore_backup_with_task(self, mgr_cluster, snapshot_tag, timeout, restore_schema=False, restore_data=False,
727739
location_list=None, extra_params=None):
728740
location_list = location_list if location_list else self.locations
741+
dc_mapping = self.get_dc_mapping()
729742
restore_task = mgr_cluster.create_restore_task(restore_schema=restore_schema, restore_data=restore_data,
730743
location_list=location_list, snapshot_tag=snapshot_tag,
731-
extra_params=extra_params)
744+
dc_mapping=dc_mapping, extra_params=extra_params)
732745
restore_task.wait_and_get_final_status(step=30, timeout=timeout)
733746
assert restore_task.status == TaskStatus.DONE, f"Restoration of {snapshot_tag} has failed!"
734747
InfoEvent(message=f'The restore task has ended successfully. '

sdcm/mgmt/cli.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ def set_cluster_id(self, value: str):
603603
self.id = value
604604

605605
def create_restore_task(self, restore_schema=False, restore_data=False, location_list=None, snapshot_tag=None,
606-
extra_params=None):
606+
dc_mapping=None, extra_params=None):
607607
cmd = f"restore -c {self.id}"
608608
if restore_schema:
609609
cmd += " --restore-schema"
@@ -614,6 +614,8 @@ def create_restore_task(self, restore_schema=False, restore_data=False, location
614614
cmd += " --location {} ".format(locations_names)
615615
if snapshot_tag:
616616
cmd += f" --snapshot-tag {snapshot_tag}"
617+
if dc_mapping:
618+
cmd += f" --dc-mapping {dc_mapping}"
617619
if extra_params:
618620
cmd += f" {extra_params}"
619621

0 commit comments

Comments
 (0)