Skip to content

Commit 5dc4885

Browse files
committed
feat(gooddata-pipelines): Backup workspaces from list of workspace IDs
1 parent febbdeb commit 5dc4885

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

gooddata-pipelines/gooddata_pipelines/backup_and_restore/backup_input_processor.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,33 @@ def get_all_workspaces(self) -> list[str]:
158158
return all_workspaces
159159

160160
def get_ids_to_backup(
161-
self, input_type: InputType, path_to_csv: str | None = None
161+
self,
162+
input_type: InputType,
163+
path_to_csv: str | None = None,
164+
workspace_ids: list[str] | None = None,
162165
) -> list[str]:
163166
"""Returns the list of workspace IDs to back up based on the input type."""
164167

165168
if input_type in (InputType.LIST_OF_WORKSPACES, InputType.HIERARCHY):
166-
if path_to_csv is None:
169+
if (path_to_csv is None) == (workspace_ids is None):
167170
raise ValueError(
168-
f"Path to CSV is required for this input type: {input_type.value}"
171+
f"Path to CSV and list of workspace IDs must be specified exclusively for this input type: {input_type.value}"
169172
)
170173

171174
# If we're backing up based on the list, simply read it from the CSV
175+
list_of_parents = (
176+
self.csv_reader.read_backup_csv(path_to_csv)
177+
if path_to_csv is not None
178+
else workspace_ids
179+
)
180+
172181
if input_type == InputType.LIST_OF_WORKSPACES:
173-
return self.csv_reader.read_backup_csv(path_to_csv)
182+
return list_of_parents
174183
else:
175184
# For hierarchy backup, we read the CSV and treat it as a list of
176185
# parent workspace IDs. Then we retrieve the children of each parent,
177186
# including their children, and so on. The parent workspaces are
178187
# also included in the backup.
179-
list_of_parents = self.csv_reader.read_backup_csv(path_to_csv)
180188
list_of_children: list[str] = []
181189

182190
for parent in list_of_parents:

gooddata-pipelines/gooddata_pipelines/backup_and_restore/backup_manager.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,29 +373,37 @@ def process_batches_in_parallel(
373373

374374
raise
375375

376-
def backup_workspaces(self, path_to_csv: str) -> None:
376+
def backup_workspaces(
377+
self, path_to_csv: str | None, workspace_ids: list[str] | None
378+
) -> None:
377379
"""Runs the backup process for a list of workspace IDs.
378380
379-
Will read the list of workspace IDs from a CSV file and create backup for
380-
each workspace in storage specified in the configuration.
381+
Will take the list of workspace IDs or read the list of
382+
workspace IDs from a CSV file and create backup for each
383+
workspace in storage specified in the configuration.
381384
382385
Args:
383386
path_to_csv (str): Path to a CSV file containing a list of workspace IDs.
387+
workspace_ids (list[str]): List of workspace IDs
384388
"""
385-
self.backup(InputType.LIST_OF_WORKSPACES, path_to_csv)
389+
self.backup(InputType.LIST_OF_WORKSPACES, path_to_csv, workspace_ids)
386390

387-
def backup_hierarchies(self, path_to_csv: str) -> None:
391+
def backup_hierarchies(
392+
self, path_to_csv: str | None, workspace_ids: list[str] | None
393+
) -> None:
388394
"""Runs the backup process for a list of hierarchies.
389395
390-
Will read the list of workspace IDs from a CSV file and create backup for
391-
each those workspaces' hierarchies in storage specified in the configuration.
396+
Will take the list of workspace IDs or read the list of workspace IDs
397+
from a CSV file and create backup for each those workspaces' hierarchies
398+
in storage specified in the configuration.
392399
Workspace hierarchy means the workspace itself and all its direct and
393400
indirect children.
394401
395402
Args:
396403
path_to_csv (str): Path to a CSV file containing a list of workspace IDs.
404+
workspace_ids (list[str]): List of workspace IDs
397405
"""
398-
self.backup(InputType.HIERARCHY, path_to_csv)
406+
self.backup(InputType.HIERARCHY, path_to_csv, workspace_ids)
399407

400408
def backup_entire_organization(self) -> None:
401409
"""Runs the backup process for the entire organization.
@@ -406,12 +414,17 @@ def backup_entire_organization(self) -> None:
406414
self.backup(InputType.ORGANIZATION)
407415

408416
def backup(
409-
self, input_type: InputType, path_to_csv: str | None = None
417+
self,
418+
input_type: InputType,
419+
path_to_csv: str | None = None,
420+
workspace_ids: list[str] | None = None,
410421
) -> None:
411422
"""Runs the backup process with selected input type."""
412423
try:
413424
workspaces_to_export: list[str] = self.loader.get_ids_to_backup(
414-
input_type, path_to_csv
425+
input_type,
426+
path_to_csv,
427+
workspace_ids,
415428
)
416429
batches = self.split_to_batches(
417430
workspaces_to_export, self.config.batch_size

0 commit comments

Comments
 (0)