Skip to content

Instantly share code, notes, and snippets.

@W4RH4WK
Last active February 27, 2016 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save W4RH4WK/ca4b5f233afa77802757 to your computer and use it in GitHub Desktop.
Save W4RH4WK/ca4b5f233afa77802757 to your computer and use it in GitHub Desktop.
Github Backup
#!/usr/bin/env python
import requests
token = 'INSERT TOKEN HERE'
def list_repos():
repos = requests.get(
'https://api.github.com/user/repos?per_page=1000',
headers={'Authorization': 'token ' + token}
).json()
for r in repos:
print r['clone_url']
def list_gists():
gists = requests.get(
'https://api.github.com/gists?per_page=1000',
headers={'Authorization': 'token ' + token}
).json()
for g in gists:
print g['git_pull_url']
if __name__ == '__main__':
list_repos()
list_gists()
#!/bin/bash
GITHUB_REPOS="$HOME/bin/github_repos"
BACKUP_DIR="$HOME/archive/github"
for repo_url in $($GITHUB_REPOS); do
repo_dir="${repo_url##*/}"
if [[ -d "$BACKUP_DIR/$repo_dir" ]]; then
git --git-dir "$BACKUP_DIR/$repo_dir" remote update
else
git clone --mirror "$repo_url" "$BACKUP_DIR/$repo_dir"
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment