Skip to content

Instantly share code, notes, and snippets.

@justinian
Last active September 3, 2020 20:14
Show Gist options
  • Save justinian/f96eeee5cfc225ec010a to your computer and use it in GitHub Desktop.
Save justinian/f96eeee5cfc225ec010a to your computer and use it in GitHub Desktop.
GitHub & Bitbucket backup scripts
#!/bin/bash
BACKUP_DIR="/home/justin/backups/git"
cd "$BACKUP_DIR"
for repo_url in `list_my_repos.sh`; do
repo_dir=`echo $repo_url | sed 's/^....//' | tr ':/@' '___'`
git clone --mirror "$repo_url" "/tmp/$repo_dir" > /dev/null 2>&1
git --git-dir "/tmp/$repo_dir" bundle create "$repo_dir.bundle.new" --all > /dev/null 2>&1
if [ -f "$repo_dir.bundle" ]; then rm "$repo_dir.bundle"; fi
mv "$repo_dir.bundle.new" "$repo_dir.bundle"
rm -rf "/tmp/$repo_dir"
done
#!/bin/bash
BB_USER="user:pass"
BB_API_URL="https://bitbucket.org/api/1.0/user/repositories"
GH_API_URL="https://api.github.com/user/repos"
GH_API_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
curl -H "Authorization: token ${GH_API_TOKEN}" -s "$GH_API_URL" | grep -Eo '"ssh_url": "[^"]+"' | awk '{print $2}' | sed 's/"//g'
curl -s --user "$BB_USER" "$BB_API_URL" | parse_bb_repos
#!/usr/bin/python
import json
import sys
repos = json.load(sys.stdin)
for r in [r for r in repos if r['scm'] == 'git']:
print "[email protected]:%(owner)s/%(name)s.git" % r
if "-v" in sys.argv:
print >> sys.stderr, json.dumps(repos, indent=4, separators=(',', ': '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment