Skip to content

Instantly share code, notes, and snippets.

@tahnok
Created December 29, 2018 01:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tahnok/ecb21a09f1492daebdb1a0273d42f5bd to your computer and use it in GitHub Desktop.
Save tahnok/ecb21a09f1492daebdb1a0273d42f5bd to your computer and use it in GitHub Desktop.
backup your github repos periodically
import urllib2
import json
import os
user = "tahnok" #replace me
backup_path = "/home/wes/github_backups" #and replace me
repos = json.load(urllib2.urlopen("https://api.github.com/users/%s/repos?per_page=100" % user))
for repo in repos:
name = repo['name']
print("backing up %s" % name)
path = os.path.join(backup_path, name)
if os.path.isdir(path):
print("pulling...")
os.system("cd %s && git pull" % path)
else:
print("cloning...")
os.system("git clone %s %s" % (repo['clone_url'], path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment