Skip to content
Snippets Groups Projects
Commit 93eabeb3 authored by Andrii Sosiuk's avatar Andrii Sosiuk
Browse files

YT-157 Adjust GitLab Backup Script to avoid shared projects

 Ensure backups are only processed for direct member projects of a group.
 If a project is shared with a group, backing it up without the appropriate
 permissions can cause the backup to fail.
parent 77a91f92
No related branches found
No related tags found
1 merge request!411YT-157 Adjust GitLab Backup Script to avoid shared projects
Pipeline #144186 passed with stages
in 23 seconds
......@@ -193,8 +193,18 @@ def get_projects_from_group(gitlab, base_group):
return p_list
def main(args):
def check_project_is_shared(project, base_group):
"""Check if project is shared with base_group"""
shared = False
if project.shared_with_groups:
for shared_with_group in project.shared_with_groups:
if base_group in shared_with_group["group_full_path"]:
shared = True
return shared
def main(args):
parser = argparse.ArgumentParser(description=__doc__, usage="%(prog)s [OPTIONS]")
parser.add_argument(
......@@ -212,11 +222,11 @@ def main(args):
)
parser.add_argument(
"-g",
"--group-id",
"--group",
action="store",
dest="groupid",
dest="group_path",
default=GITLAB_GROUP_ID,
help=("Specify the group by id to query projects in."),
help=("Specify the group to query projects in."),
)
parser.add_argument(
"-e",
......@@ -242,13 +252,18 @@ def main(args):
logging.debug(options)
gitlab = gl.Gitlab(options.gitlab_url, private_token=options.token)
group = gitlab.groups.get(options.groupid)
group = gitlab.groups.get(options.group_path)
print(f"Getting projects in group {group.name}")
projects = get_projects_from_group(gitlab, group)
p = {}
for project in projects:
print(f"Processing project: {project.name} {project.path_with_namespace}")
if check_project_is_shared(project, options.group_path):
print("This is a shared project. Skipping.")
continue
exportpath = (
f"{os.path.join(options.exportpath, project.path_with_namespace)}.tar.gz"
)
......@@ -285,6 +300,7 @@ def main(args):
with open(exportpath, "w+b") as f:
f.write(export.download())
p[project]["downloaded"] = True
print("Done.")
if in_started_state == 0:
break
print(f"Waiting for exports to be finished ({in_started_state})")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment