A simple script to backup an organization's GitHub repositories with issues and wikis
A simple script to backup an organization’s GitHub repositories with their issues and wikis.
This script is adapted from https://gist.github.com/darktim/5582423 (which was forked from https://gist.github.com/rodw/3073987) to support proxy and to retrieve more than 30 issues and authentication via TOKEN.
The following environment variables can be defined to make this script fit to your needs:
Script requires jq; install with apt install jq
on Ubuntu.
The script will generate per repository X from the target organization:
The git repositories are cloned with —mirror option so the result will be quite different from what we get after a classical git clone.
To get a working copy, in your current directory, of a repository which was saved by this backup script, one should extract the tar.gz containing the git repository backup and then execute the following command:
git clone /path/to/your/extracted/git/your_repository.git .
You can use a cron job to run this script. One way to use this script is to create a .github_backuprc file in the home directory of the user which will run the cron, with rwx——— permissions (rwx only for the user since the GitHub API token will be saved into this file).
This file will look like the following:
export GHBU_TOKEN=your_token_here
export GHBU_BACKUP_DIR=/where/you/want/your/backups
export GHBU_PROXY_SETTINGS="-x myproxy.mydomain.com:1234"
export GHBU_PRUNE_AFTER_N_DAYS=5
Here is an example of a crontab you can use to execute the backup script every day at 09:00 am and send an e-mail once the script has completed its work:
#
# Backup tango-controls GitHub organization
#
00 09 * * * . /home/my_username/.github_backuprc; /path/to/backup/script/backup-github.sh | mailx -s "[cron-github-backup] tango-controls" my_email_address@mydomain.com >/dev/null 2>&1