Backup Visual Studio Team Services projects

​
import subprocess
import requests
import base64
import subprocess
import os

access_token = "xxx"

api_output = requests.get("https://username:"+access_token +"@org.visualstudio.com/DefaultCollection/_apis/projects?api-version=1.0")

for project in api_output.json()["value"]:
    print(project["name"])

    local_path = os.path.join("vsts", project["name"])

    if os.path.isdir(local_path):

        try:
            output = subprocess.check_output(
                ["git", "pull"], cwd=local_path)
            print(output)
        except:
            print("error")

    else:
        projectName = project["name"]
        output = subprocess.check_output(
            ["git", "clone", "ssh://org@vsssh.visualstudio.com:22/"+projectName+"/_ssh/"+projectName], cwd="vsts")
        print(output)