Skip to content

Instantly share code, notes, and snippets.

@volkanpaksoy
Created October 31, 2019 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save volkanpaksoy/58b16aad9fce3c8612c95fdffab2e8cd to your computer and use it in GitHub Desktop.
Save volkanpaksoy/58b16aad9fce3c8612c95fdffab2e8cd to your computer and use it in GitHub Desktop.
Backing-Up-GitHub-Account-with-Bash
#! /bin/bash
backupDir='/repos'
token='{GITHUB USERNAME}:{PERSONAL ACCESS TOKEN}'
base64Token=$(echo -n $token | base64)
cd $backupDir
page=1
perPage=30
url="https://api.github.com/user/repos?page=$page&per_page=$perPage"
response=$(curl -H "Authorization: Basic $base64Token" $url)
#echo $response
for row in $(echo "${response}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 -d | jq -r ${1}
}
repoName=$(echo $(_jq '.name'))
repoUrl=$(echo $(_jq '.ssh_url'))
repoPath=$backupDir/$repoName
if [ ! -d "$repoPath" ]; then
echo "Repo doesn't exist, clone it"
git clone $repoUrl
else
echo "Repo exists, update"
cd $repoPath
git fetch --all
git reset --hard origin/master
cd $backupDir
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment