This script creates git bundle files for all repositories in a GitHub organization. Git bundles are complete backups of git repositories that can be cloned or fetched from like any other git remote.
# install asdf: https://asdf-vm.com/guide/getting-started.html
# activate python version defined in .tool-versions
asdf install
# initialize and activate virtual env
python -m venv .venv
source .venv/bin/activate
# install python requirements
pip install -r requirements.txt
# set up environment variables
cp .env.example .env
# edit .env and add your GitHub token
# run the backup script (replace ORGNAME with target GitHub organization)
python backup.py ORGNAME
The script will create .bundle
files in the bundles/ORGNAME
directory. These bundles can be used to restore repositories:
# To clone a new repository from a bundle
git clone repo-name.bundle
# To fetch updates from a bundle into an existing repository
git fetch repo-name.bundle
The script requires two configurations:
- GitHub Token: Create a
.env
file based on.env.example
and add your GitHub personal access token - Organization Name: Provided as a command line argument when running the script
Example:
python backup.py usds