Easily back up your Github repositories and/or issues
It's been in the works at the lower-end of my priority list, but after having a bit of a bug-closing weekend, thought I'd tackle getting out an initial release of Github::Backup.
The cloud is a great thing, until the sun evaporates it one way or another. Github, although fantastically reliable, is prone to issues just like any other site on the Internet. I'd go as far to say that even they could be prone to data loss in very rare circumstances.
This distribution, which provides a command-line binary, allows you to quickly and easily back up your repositories and issues to your local machine. The repositories are cloned so all data is retrieved as-is as legitimate Git repos, and the issues are fetched and stored as JSON data. Useful if there was ever a catastrophic issue at Github, or simply for offline perusal of your information.
At a basic level, you need to send in your Github username, API token (see this), a directory to stash the data retrieved, and a flag to signify you want to back up either your repos, issues or both.
github_backup \
-u stevieb9 \
-t 003e12e0780025889f8da286d89d144323c20c1ff7 \
-d /home/steve/github_backup \
-r \
-i
That'll back up both repos and issues. The structure of the backup directory is as follows:
backup_dir/
- issues/
- repo1/
- issue_id_x
- issue_id_y
- repo2/
- issue_id_a
- repo1/
- repository data
- repo2/
- repository data
Now, most don't like supplying keys/tokens/passwords on the command-line or within a script, so you can stash your Github API token into the GITHUB_TOKEN
environment variable, and we'll fetch it from there instead:
github_backup -u stevieb9 -d /home/steve/github_backup -r -i
Full usage for the binary:
Usage: github_backup -u username -t github_api_token -d /backup/directory -r -i
Options:
-u | --user Your Github username
-t | --token Your Github API token
-d | --dir The backup directory
-p | --proxy Optional proxy (https://proxy.example.com:PORT)
-r | --repos Back up all of your repositories
-i | --issues Back up all of your issues
-h | --help Display this help page
The API is very straightforward as well:
use warnings;
use strict;
use Github::Backup;
# token stashed in GITHUB_TOKEN env var
my $gh = Github::Backup->new(
api_user => 'stevieb9',
dir => '/home/steve/github_backup'
);
# back up all repos
$gh->repos;
# back up all issues
$gh->issues;
This is one distribution that I've released prior to being happy with my unit test regimen, so that's on the imminent to-do list. There are tests, but as always, there can never be enough. In this case, I, myself am not even happy, so if you run into any issues, please open a ticket, or reply back here.
Going forward, I plan on adding functionality to independently back up all Github data for a user, not just repos and issues. I also plan to test restore operations, but that's not anything I'm considering short-term.
Have fun!
-stevieb
Note: Also posted at Perlmonks.
I liked the idea. Not sure, if I ever use it though. I appreciate the amount of work goes behind it. Well done and keep supporting the community. One small suggestion, a personal one, you can ignore if you don't like. Can you please rename the script to "github-backup"?