PK!sRdd README.md# Git backup. Backups all of your GitHub remote git repositories locally. ## What do I need? - Python 3+ ## How to run it? 1. Set `GITHUB_TOKEN` env variable with your github token 2. Execute script with path to where repositories should be saved ``` git-backup --path=~/Documents/backup ``` ## Install with pypi ``` $ pip install git-repo-backup ``` PK!git_repo_backup/__init__.pyPK!;git_repo_backup/backup.pyimport os import sys import click from git import Repo, InvalidGitRepositoryError, NoSuchPathError from github import Github from tqdm import tqdm @click.command() @click.option("--path", required=True, help="Path to where repositories will be saved.") def cli(path): repos = github_integration(path) for repo in tqdm(repos, bar_format="Processing github repositories: {n}"): local_repository_path = os.path.join(path, "github", repo["name"]) try: repo = Repo(local_repository_path) except (InvalidGitRepositoryError, NoSuchPathError): if not os.path.isdir(local_repository_path): os.makedirs(local_repository_path) repo = Repo.clone_from( f"https://github.com/{repo['name']}.git", local_repository_path ) for remote in repo.remotes: remote.fetch() remote.pull() repo.submodule_update() def github_integration(path): _validate({"GITHUB_TOKEN"}) github = Github(os.environ["GITHUB_TOKEN"]) github_repos = github.get_user().get_repos() for r in github_repos: yield {"name": r.full_name} def _validate(required_envs): missing_env = required_envs - os.environ.keys() if missing_env: click.secho(f'Missing env variables: "{",".join(missing_env)}".', fg="red") sys.exit() if __name__ == "__main__": cli() PK!H$190git_repo_backup-2.0.0.dist-info/entry_points.txtN+I/N.,()J,MJL.-2R !|=ePK!Hu)GTU%git_repo_backup-2.0.0.dist-info/WHEEL HM K-*ϳR03rOK-J,/R(O-)$qzd&Y)r$UV&UrPK!HjB(git_repo_backup-2.0.0.dist-info/METADATASn0+H-űY8Z"KCn_̛+t<㎇?Xdh] *t^i ҉:*Kn^Vr ),V8eZ(TJ:bCUbJi1̫i2^KDKe2ۨ Z:;\LK.3>U  okBRh7ϓ[+R3F$y}GpQ o(F /K!gp嬢x|+kmoʢޔn{.>E`-|ymBі(]KAQ SVzD?uGߘ2Fy65B;IxǵeubUi=d0=ЋI`BMhAbPK!H݉c`1&git_repo_backup-2.0.0.dist-info/RECORDˎ0*b]KPFQ܅*db2Y8Y|rشϡ=0ΙEZgqfZM~qcw,&8x`T2+|M7 +j(kUq=8U*E'^u"szpQ"\$)۽>իʌiFo3x/ŒP.;[/#Rz9cѼ$i]F2On$L  w&h%G*fdS!VJ_?R5F˵%IoPK!sRdd README.mdPK!git_repo_backup/__init__.pyPK!;git_repo_backup/backup.pyPK!H$190git_repo_backup-2.0.0.dist-info/entry_points.txtPK!Hu)GTU%git_repo_backup-2.0.0.dist-info/WHEELPK!HjB(git_repo_backup-2.0.0.dist-info/METADATAPK!H݉c`1&# git_repo_backup-2.0.0.dist-info/RECORDPK"