Skip to content

Instantly share code, notes, and snippets.

@sturman
Forked from nixjobin/bitbucket-backup-all-repos.sh
Last active October 26, 2018 13:45
Show Gist options
  • Save sturman/0f33561364d847c73dd3dbcbded0fd6f to your computer and use it in GitHub Desktop.
Save sturman/0f33561364d847c73dd3dbcbded0fd6f to your computer and use it in GitHub Desktop.
bitbucket-backup-all-repos.sh
#!/bin/bash
#Author Jobin Joseph
#Blog : JobNix.in
#Bio : JobinJoseph.com
#Bitbucket credentials
bbuser='Username_here'
bbpass='password_here'
fname=`date +%F_%H_%M`
check_dependencies() {
dpkg -s jq &> /dev/null
if [ $? -eq 0 ]; then
echo "jq is installed!"
else
echo "jq is NOT installed!"
echo "please install jq with `sudo apt install -y jq`"
exit 1
fi
}
bitbucket_get_urls () {
rm -f bitbucketurls
curl --user ${bitbucket_user}:${bitbucket_pass} https://api.bitbucket.org/2.0/repositories?pagelen=100 > bitbucket.1
jq '.values[].links.clone[] | select(.name=="ssh") | .href' bitbucket.1 > bitbucketurls
}
bb_backup () {
echo ${backup_folder_name} > VERSION
mkdir ${backup_folder_name}
cd ${backup_folder_name}
#bare clone
for repo in `cat ../bitbucketurls` ; do
echo "========== Cloning $repo =========="
git clone --bare $repo
done
}
#Backup Starts here
check_dependencies
bitbucket_get_urls
bb_backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment