Skip to content
Snippets Groups Projects

GitLab Repo Backup

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Ethan Nelson

    This script polls GitLab for repositories you are a part of, then clones them to the working directory. If the script has already run once and/or there are repositories already present in the working directory, it will instead fetch and pull the origin remote.

    Make sure create a private token in settings and add it in the script (https://gitlab.ssec.wisc.edu/profile/personal_access_tokens).

    Edited
    snippetfile1.txt 774 B
    import json
    import os
    import time
    
    os.system('curl --header "Private-Token: ENTER_YOUR_TOKEN_HERE" "https://gitlab.ssec.wisc.edu/api/v4/projects?simple=yes&owned=yes&per_page=100" > owned-projects.json')
    f = json.loads(open('owned-projects.json').read())
    
    os.system('curl --header "Private-Token: ENTER_YOUR_TOKEN_HERE" "https://gitlab.ssec.wisc.edu/api/v4/projects?simple=yes&starred=yes&per_page=100" > starred-projects.json')
    f += json.loads(open('starred-projects.json').read())
    
    for repo in f:
        dir = repo['ssh_url_to_repo'].split('/')[-1][:-4]
        if os.path.isdir(dir):
            os.chdir(dir)
            os.system('git fetch origin && git pull origin')
            os.chdir('../')
            time.sleep(1)
        else:
            os.system('git clone %s' % repo['ssh_url_to_repo'])
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment