Skip to content

Commit 037ba44

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

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

gooddata-pipelines/gooddata_pipelines/backup_and_restore/backup_input_processor.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# (C) 2025 GoodData Corporation
22

33
from dataclasses import dataclass
4+
from typing import cast
45

56
import requests
67

@@ -158,25 +159,33 @@ def get_all_workspaces(self) -> list[str]:
158159
return all_workspaces
159160

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

165169
if input_type in (InputType.LIST_OF_WORKSPACES, InputType.HIERARCHY):
166-
if path_to_csv is None:
170+
if (path_to_csv is None) == (workspace_ids is None):
167171
raise ValueError(
168-
f"Path to CSV is required for this input type: {input_type.value}"
172+
f"Path to CSV and list of workspace IDs must be specified exclusively for this input type: {input_type.value}"
169173
)
170174

171175
# If we're backing up based on the list, simply read it from the CSV
176+
list_of_parents = (
177+
self.csv_reader.read_backup_csv(path_to_csv)
178+
if path_to_csv is not None
179+
else cast(list[str], workspace_ids)
180+
)
181+
172182
if input_type == InputType.LIST_OF_WORKSPACES:
173-
return self.csv_reader.read_backup_csv(path_to_csv)
183+
return list_of_parents
174184
else:
175185
# For hierarchy backup, we read the CSV and treat it as a list of
176186
# parent workspace IDs. Then we retrieve the children of each parent,
177187
# including their children, and so on. The parent workspaces are
178188
# also included in the backup.
179-
list_of_parents = self.csv_reader.read_backup_csv(path_to_csv)
180189
list_of_children: list[str] = []
181190

182191
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)