Skip to content

Instantly share code, notes, and snippets.

@CodeBrauer
Created April 16, 2019 06:48
Show Gist options
  • Save CodeBrauer/1f53d90f7e202d34989dd583f20ee552 to your computer and use it in GitHub Desktop.
Save CodeBrauer/1f53d90f7e202d34989dd583f20ee552 to your computer and use it in GitHub Desktop.
Python3 script to backup all repos from gitlab. Just pipe the command output to a textfile (to run it later/somewhere else) or directly in your shell.
from urllib.request import urlopen
import json
import subprocess, shlex
import sys
allProjects = urlopen("http://gitlab.example.org/api/v3/projects/all?private_token=[PERSONAL_TOKEN]&per_page=100")
allProjectsDict = json.loads(allProjects.read().decode())
for index,thisProject in enumerate(allProjectsDict):
try:
thisProjectURL = thisProject['ssh_url_to_repo'] + ' ' + thisProject['path_with_namespace'].replace('/', '_');
sys.stdout.write('git clone ' + thisProjectURL)
if index != (len(allProjectsDict) - 1):
sys.stdout.write(' && ')
except Exception as e:
print("Error on %s: %s" % (thisProjectURL, e.strerror))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment