Last active
July 25, 2019 19:10
-
-
Save m-esm/4ef79891356f6154a397f0cf1a49917e to your computer and use it in GitHub Desktop.
backup github repositories ( users & orgs )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main_dir=~/Desktop/github-backups | |
github_users=(orgs/serendip-agency users/m-esm) | |
echo -e "\tBackup directory:$main_dir \n\n\tAccounts to backup:" | |
for a in ${github_users[@]}; do echo -e "\t\t${a}"; done | |
echo -e "\n\t$(mkdir $main_dir 2>&1)" | |
cd $main_dir | |
for user in ${github_users[@]}; do | |
repos=$(curl https://api.github.com/$user/repos --silent) | |
for row in $(echo "${repos}" | jq -r '.[] | @base64'); do | |
_jq() { echo ${row} | base64 --decode | jq -r ${1}; } | |
name=$(_jq '.name') | |
ssh_url=$(_jq '.ssh_url') | |
echo -e "\n\n\tNAME:$name \n\tURL:$ssh_url\n\tDIR:$main_dir/$user/$name" | |
echo -e "\tcloning git ..." | |
echo -e "\tCloning result $(git clone $ssh_url ./$user/$name 2>&1)" | |
cd $main_dir/$user/$name | |
if [ $? -eq 0 ]; then | |
echo -e "\tpulling ..." | |
git pull | |
else | |
echo Failed to clone $user/$name | |
fi | |
cd $main_dir | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment