Thursday, August 2, 2018

Github Backup for Organization with Script

I'm not a github wizard, but I needed to backup the repos on our organization by cloning them all, where most of the repositories are private. After playing around I found a script that would work in the windows git console below. The text in read is what you change.

  1. Go to: https://github.com/settings/tokens and generate a personal access token. Make sure you write it down because it will disappear afterwards
  2. In the below code, orgname is the name of your organization, and your_access_token is the token you just generated, you will also need to run it for each page.

CNTX=orgs; NAME=orgname; ACCESS_TOKEN=your_access_token; PAGE=1
curl "https://api.github.com/$CNTX/$NAME/repos?page=$PAGE&per_page=100&access_token=$ACCESS_TOKEN" |
  grep -e 'clone_url*' |
  cut -d \" -f 4 |
  xargs -L1 git clone

No comments:

Post a Comment