Created
December 29, 2018 01:58
-
-
Save tahnok/ecb21a09f1492daebdb1a0273d42f5bd to your computer and use it in GitHub Desktop.
backup your github repos periodically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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