Cloudup improvements

Finally can backup repositories to be private (still not able to copy private github repos). Now the all option will attempt to look for up to 10,000 repositories versus 100.
This commit is contained in:
Alex Epstein 2017-07-18 12:56:09 -04:00
parent c3fab13e79
commit 2da9569dfe
1 changed files with 27 additions and 34 deletions

View File

@ -98,15 +98,15 @@ backupRepo()
timestamp=$(date | tr " " _ | tr : _ ) ## we do this because it takes care of changes bitbucket would have made
cd ~/temp/github/$repoName || { echo "Fatal error"; return 1; }
if [[ $private == "1" ]];then
httpGet --user $bbUsername:$password https://api.bitbucket.org/1.0/repositories/ --data name=$repoName$timestamp is_private=true > /dev/null
httpGet --user $bbUsername:$password https://api.bitbucket.org/1.0/repositories/ --data name=$repoName$timestamp --data is_private=true > /dev/null || { echo "Error: creating the bitbucket repo failed, most likely due to an incorrect username or password."; return 1; }
echo "private"
else
httpGet --user $bbUsername:$password https://api.bitbucket.org/1.0/repositories/ --data name=$repoName$timestamp > /dev/null
httpGet --user $bbUsername:$password https://api.bitbucket.org/1.0/repositories/ --data name=$repoName$timestamp > /dev/null || { echo "Error: creating the bitbucket repo failed, most likely due to an incorrect username or password."; return 1; }
fi
originalRepoName=$repoName
repoName=$(echo $repoName | tr '[:upper:]' '[:lower:]')
timestamp=$(echo $timestamp | tr '[:upper:]' '[:lower:]')
git remote set-url origin https://$bbUsername:$password@bitbucket.org/$bbUsername/$repoName$timestamp.git > /dev/null || return 1 ## switch the remote over to bitbucket rather than github
git remote set-url origin "https://$bbUsername:$password@bitbucket.org/$bbUsername/$repoName$timestamp.git" > /dev/null || return 1 ## switch the remote over to bitbucket rather than github
echo "Uploading $originalRepoName to bitbucket"
git push -q --progress origin --all > /dev/null || return 1 ## pushes al files to github and most of the repo history
echo "Uploading the tags for $originalRepoName"
@ -145,10 +145,14 @@ cloneGitHubRepo()
## Grabs the last 100 updated repos and greps to grab the repository names and puts them in an array called repoNames
getGithubRepoNames()
{
response=$(httpGet "https://api.github.com/users/$ghUsername/repos?sort=updated&per_page=100" | grep -Eo '"name": "[ a-Z . \/ \\ 0-9 -- _ ]*' | sed s/'"name": "'/""/g)
for repo in $response
for pageNumber in {1..100}
do
repoNames+=("$repo")
response=$(httpGet "https://api.github.com/users/$ghUsername/repos?sort=updated&per_page=100&page=$pageNumber" | grep -Eo '"name": "[ a-Z . \/ \\ 0-9 -- _ ]*' | sed s/'"name": "'/""/g)
if [[ $response == "" ]];then break;fi ## will only break if the page is empty
for repo in $response
do
repoNames+=("$repo")
done
done
}
@ -166,8 +170,9 @@ usage()
echo "Examples:"
echo " cloudup"
echo " cloudup -p -a"
echo " cloudup -p nameOfRepo1 nameOf Repo2"
echo " cloudup -p nameOfRepo1 nameOfRepo2"
echo " cloudup nameOfRepo"
echo " cloudup -a"
}
getConfiguredClient || exit 1
@ -181,8 +186,6 @@ while getopts "pauvh" opt; do
;;
p)
private="1"
echo "Feature not added yet, for now all backups must be public (can be manually set to private through bitbucket after backup)" >&2
exit 0
;;
h)
usage
@ -216,11 +219,13 @@ if [[ $# == "1" ]]; then
usage
exit 0
fi
elif [ $# -ge 1 ];then
getGitHubUserInfo || exit 1
getBitbucketInfo || exit 1
echo
if [[ $private != "1" ]];then
fi
if [[ $all == "0" ]];then
if [[ $private == "0" && $2 != "" ]];then
getGitHubUserInfo || exit 1
getBitbucketInfo || exit 1
for i in "$@"; do ## if private is not on as a flag start rpping through them
repoName=$i
echo "Starting to backup $repoName"
@ -229,21 +234,7 @@ elif [ $# -ge 1 ];then
echo
done
exit 0
else
for i in "${@:2}"; do
repoName=$i
echo "Starting to backup $repoName"
cloneGitHubRepo || exit 1
backupRepo || { echo "Error: couldnt backup $originalRepoName to bitbucket"; exit 1; }
echo
done
exit 0
fi
fi
if [[ $all == "0" ]];then
if [[ $1 == "" ]];then
elif [[ ( $private == "0" && $1 == "" ) || ( $private == "1" && $2 == "" ) ]];then
getGitHubUserInfo || exit 1
getGitHubRepoInfo || exit 1
getBitbucketInfo || exit 1
@ -253,11 +244,14 @@ if [[ $all == "0" ]];then
exit 0
else
getGitHubUserInfo || exit 1
repoName=$1 || exit 1
getBitbucketInfo || exit 1
echo
cloneGitHubRepo || exit 1
backupRepo || { echo "Error: couldnt backup $originalRepoName to bitbucket"; exit 1; }
for i in "${@:2}"; do
repoName=$i
echo "Starting to backup $repoName"
cloneGitHubRepo || exit 1
backupRepo || { echo "Error: couldnt backup $originalRepoName to bitbucket"; exit 1; }
echo
done
exit 0
fi
else
@ -275,5 +269,4 @@ else
done
echo "Successfully backed up all repositories"
exit 0
fi