2020-09-08 08:09:24 +02:00
# GitHub-Backup
2010-07-13 14:20:48 -04:00
2020-09-08 08:09:24 +02:00
## Description
2013-07-14 21:43:10 -07:00
2014-06-26 00:28:35 +02:00
GitHub-Backup makes a local backup copy of all of a github user's (or github organization's) repositories.
2010-07-13 14:20:48 -04:00
2020-09-08 08:09:24 +02:00
## Dependencies
2013-08-02 00:18:43 +02:00
2019-05-05 03:22:47 +02:00
GitHub-Backup requires the `PyGitHub` Python package for the GitHub API v3.
2013-08-02 00:18:43 +02:00
Installation is simple with
2020-09-08 08:09:24 +02:00
```bash
2020-09-08 08:30:14 +02:00
pip install git+https://github.com/clockfort/GitHub-Backup
2020-09-08 08:09:24 +02:00
```
2013-08-02 00:18:43 +02:00
2020-09-08 08:09:24 +02:00
## Usage
2019-05-05 02:07:11 +02:00
2020-09-08 08:09:24 +02:00
```
2020-09-08 08:19:33 +02:00
usage: github-backup.py [-h] [-v {all,public,private}] [-a {owner,collaborator,organization_member}] [-d] [-q] [-m] [-f] [--skip-repos] [-g ARGS [ARGS ...]] [-t {git,http,ssh}] [-s SUFFIX] [-u USER] [-p [PASSWORD]]
[-P PREFIX] [-o ORG] [-A] [--all] [--starred] [--watched] [--followers] [--following] [--issues] [--issue-comments] [--issue-events] [--pulls] [--pull-comments] [--pull-commits] [--keys]
[--wikis] [--gists] [--starred-gists] [--releases] [--assets]
2019-05-05 03:22:58 +02:00
login_or_token backupdir
2013-08-01 17:03:16 -07:00
2020-09-08 08:19:33 +02:00
makes a backup of a github user's account
2013-08-01 17:03:16 -07:00
positional arguments:
2020-09-08 08:19:33 +02:00
login_or_token A Github username or token for authenticating
2013-08-01 17:03:16 -07:00
backupdir The folder where you want your backups to go
optional arguments:
2019-05-05 03:22:58 +02:00
-h, --help show this help message and exit
-v {all,public,private}, --visibility {all,public,private}
Filter repos by their visibility
-a {owner,collaborator,organization_member}, --affiliation {owner,collaborator,organization_member}
Filter repos by their affiliation
-d, --debug Show debug info
-q, --quiet Only show errors
2013-08-01 17:03:16 -07:00
-m, --mirror Create a bare mirror
2016-07-22 12:24:42 +02:00
-f, --skip-forks Skip forks
2020-09-08 08:19:33 +02:00
--skip-repos Skip backing up repositories
2019-05-05 03:22:58 +02:00
-g ARGS [ARGS ...], --git ARGS [ARGS ...]
Pass extra arguments to git
-t {git,http,ssh}, --type {git,http,ssh}
Select the protocol for cloning
2013-08-01 17:03:16 -07:00
-s SUFFIX, --suffix SUFFIX
Add suffix to repository directory names
2020-09-08 08:19:33 +02:00
-u USER, --username USER
Backup USER account
-p [PASSWORD], --password [PASSWORD]
Authenticate with Github API (give no argument to check ~/.github-backup.conf or prompt for a password)
2019-05-05 03:22:58 +02:00
-P PREFIX, --prefix PREFIX
Add prefix to repository directory names
2014-06-26 00:28:35 +02:00
-o ORG, --organization ORG
Backup Organizational repositories
2020-09-08 08:19:33 +02:00
-A, --account Backup account data
--all include everything in backup (not including [*])
--starred include JSON output of starred repositories in backup
--watched include JSON output of watched repositories in backup
--followers include JSON output of followers in backup
--following include JSON output of following users in backup
--issues include issues in backup
--issue-comments include issue comments in backup
--issue-events include issue events in backup
--pulls include pull requests in backup
--pull-comments include pull request review comments in backup
--pull-commits include pull request commits in backup
--keys include ssh keys in backup
--wikis include wiki clone in backup
--gists include gists in backup [*]
--starred-gists include starred gists in backup [*]
--releases include release information, not including assets or binaries
--assets include assets alongside release information; only applies if including releases
2020-09-08 08:09:24 +02:00
```
2010-07-13 14:33:45 -04:00
Then, put it in a cron job somewhere and forget about it for eternity.
2020-09-08 08:12:11 +02:00
## How To Back Up Entire GitHub Organisation Repos
2019-05-05 02:06:59 +02:00
2019-08-28 01:13:03 -04:00
1. Install Dependencies: `sudo pip install pygithub3`
2. Clone this repo using `$ git clone https://github.com/clockfort/GitHub-Backup.git`
2019-05-05 02:06:59 +02:00
3. Just open the cloned repo folder and run the terminal:
2020-09-08 08:09:24 +02:00
```bash
2019-05-05 02:06:59 +02:00
./github-backup.py [Your GitHub Username] [Path To Saving Directory] -o [For Organisation]
```
Example:
2020-09-08 08:09:24 +02:00
```bash
2020-09-08 08:30:14 +02:00
github-backup mohamed786 /home/mohamed786/githubbak -o LineageOS
2019-05-05 02:06:59 +02:00
```
2020-09-08 08:12:11 +02:00
## Use a a personal access token (PAT) instead of your password
You can generate a dedicated personal access token instead of using your GitHub password.
Follow the steps described [here in the GitHub documentation ](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token ) and use the token instead of your password.
Using a PAT can also work around issues when two factor authentication (TFA) is enabled on your account.
2020-09-08 08:09:24 +02:00
## Why This Software Exists
2010-07-13 14:33:45 -04:00
This software is useful in many cases:
2010-07-13 14:26:01 -04:00
- GitHub suddenly explodes.
- GitHub goes out of business.
- Your corporation's backup policies are more stringent than GitHub's.
- You have spotty/no internet access - perhaps you'd like to have all of your repositories available to code on while you ride the train?
- You are paranoid tinfoil-hat wearer who needs to back up everything in triplicate on a variety of outdated tape media.
2010-07-13 14:20:48 -04:00
2020-09-08 08:09:24 +02:00
## Questions, Improvements, Etc
2010-07-13 14:20:48 -04:00
2013-07-14 23:33:13 -04:00
If you have any improvements, I'm happy, (grateful, in fact) to entertain pull requests/patches, just drop me a line or message me on GitHub.
2014-06-26 00:28:35 +02:00
2020-09-08 08:09:24 +02:00
## Contributors
2014-06-26 00:28:35 +02:00
Idea/original implementation by
- Chris Lockfort (clockfort@csh .rit.edu) (Github: Clockfort)
(Original idea)
- Anthony Gargiulo (anthony@agargiulo .com) (Github: agargiulo)
(Python version)
- Steffen Vogel (post@steffenvogel .de) (Github: stv0g)
(A lot of patches and improvements)