How to backup Github repositories
It’s cool to trust sites to keep our data, but it can happen at a time that they disappear. If there was a way to know how to backup Github repositories. It might sound awkward to backup Github sometimes you are no longer complying with the GTU of the site, or the site has suffered a major failure and their backup process has been destroyed or even you yourself have deleted your data by mistake.
In the case of Github, it can be interesting to make a regular backup of everything you store there and rest to which you have access. You will probably never need it, but it is the very principle of the safeguard: To foresee the “in case …”.
To back up your Github data regularly, there is the github-backup python script that requires the creation of a token and then installs like this:
pip install github-backup
Then to start the backup, here is the command (you can also put it in a crontab to trigger a scheduled backup)
github-backup USERNAME -t VOTRE_TOKEN -o /chemin/stockage/backup --all
This is the basic command, but there are lots of parameters to add or include in your backup like starred deposits, those watched, pull requests, the issues … etc.
In short, you can pretty much do whatever you want, if you like to back up everything just -all parameter.
Backup all repositories:
export ACCESS_TOKEN=SOME-GITHUB-TOKEN github-backup WhiteHouse --token $ACCESS_TOKEN --organization --output-directory /tmp/white-house --repositories
That is probably one the easiest way to backup your Github repositories.
Last but not least, it is regarding the authentication. You won’t be able to run any of these commands unless you set up the authentication first.
According to the tool documentation:
Password-based authentication will fail if you have two-factor authentication enabled.
You can read more about this tool here.