paint-brush
How to backup personal GitHub repositoriesby@buklijas.sasa
108 reads

How to backup personal GitHub repositories

by Sasa BuklijasAugust 2nd, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

I will show how to do a <a href="https://hackernoon.com/tagged/backup" target="_blank">backup</a> of <a href="https://github.com/sasa-buklijas?tab=repositories" target="_blank">your GitHub repositories</a> with <a href="https://github.com/josegonzalez/python-github-backup" target="_blank">python-github-backup</a>

Company Mentioned

Mention Thumbnail
featured image - How to backup personal GitHub repositories
Sasa Buklijas HackerNoon profile picture

I will show how to do a backup of your GitHub repositories with python-github-backup

Why to bother with a backup of GitHub

I can already see that there will be comments regarding why to do the backup of GitHub.

  • “It is a waste of time.”
  • “GitHub internally already have backups.” (I hope so)
  • “They will not lose your code” (But maybe I will)
  • “They will not go overnight out of business.”


Response to all those comments is: You will not be worst off if you have your own backup.

If forever reason (GitHub go under, all repositories deleted by accident, alien attack) GitHub is not available anymore, I have my own backup of code that I have written.

Paid solution


If you are looking for a paid solution, BackHub looks like a good solution. I have no experience with BackHub, nor am I in any way associated with it.

Free solution

After researching all available options I have decided to go with python-github-backup because it had more stars and contributors on GitHub than other projects.

I have used the number of stars and contributors on GitHub as the assumption that python-github-backup is more in use than other solutions so there are more people who will continue to support it in future.

In order to access your GitHub personal data, you need to have a personal access token.


After that, you can install it with pip/pipenv: (I have installed it in separate virtualenv)

pipenv install github-backup or

pip install github-backup


Run it with: /full/path/github_backup/venv/bin/github-backup sasa-buklijas -t your_personal_access_token -o /full/path/github_backup --all

This command will backup all your GitHub information to /full/path/github_backup directory.

It would be tiresome to run this command every day, so I have automated it on my online hosting.

Crontab


My usecase: 15 00 * * * /full/path/github_backup/venv/bin/github-backup sasa-buklijas -t your_personal_access_token -o /full/path/github_backup --all > /full/path/github_backup/last_log.txt


> /full/path/github_backup/last_log.txt is used to have an output of the last backup command. >> can be used to have outputs of all backup commands, but I have found that having just last one is enough.

Conclusion

“You will not be worse off if you have your own backup.”

Do you have backups of your own personal GitHub repositories, if you have, what do you use for backup?

Originally published at buklijas.info on August 1, 2018.