Skip to content

Commit 0f055f1

Browse files
committed
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 80eb803 commit 0f055f1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: mgmt_cli_test.py

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

520+
def get_dc_mapping(self) -> str | None:
521+
"""Get the datacenter mapping string for the restore task if there are > 1 DCs (multiDC) in the cluster.
522+
In case of singleDC, return None.
523+
524+
Example of return string:
525+
eu-west-2scylla_node_west=eu-west-2scylla_node_west,us-eastscylla_node_east=us-eastscylla_node_east
526+
"""
527+
if len(dcs := self.get_all_dcs_names()) > 1:
528+
return ",".join([f"{dc}={dc}" for dc in dcs])
529+
else:
530+
return None
531+
520532
# pylint: disable=too-many-arguments
521533
def verify_backup_success(self, mgr_cluster, backup_task, ks_names: list = None, tables_names: list = None,
522534
truncate=True, restore_data_with_task=False, timeout=None):
@@ -597,9 +609,10 @@ def restore_backup_without_manager(self, mgr_cluster, snapshot_tag, ks_tables_li
597609
def restore_backup_with_task(self, mgr_cluster, snapshot_tag, timeout, restore_schema=False, restore_data=False,
598610
location_list=None, extra_params=None):
599611
location_list = location_list if location_list else self.locations
612+
dc_mapping = self.get_dc_mapping()
600613
restore_task = mgr_cluster.create_restore_task(restore_schema=restore_schema, restore_data=restore_data,
601614
location_list=location_list, snapshot_tag=snapshot_tag,
602-
extra_params=extra_params)
615+
dc_mapping=dc_mapping, extra_params=extra_params)
603616
restore_task.wait_and_get_final_status(step=30, timeout=timeout)
604617
assert restore_task.status == TaskStatus.DONE, f"Restoration of {snapshot_tag} has failed!"
605618
InfoEvent(message=f'The restore task has ended successfully. '

Diff for: 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)