BackHub
is a simple yet powerful GitHub repository backup tool that creates and maintains complete local mirrors of your repositories. It supports concurrent backups, automated scheduling (every 3 days), and can be run either as a standalone binary or as a Docker container.
- Full repository mirroring including all branches, tags, and history
- Concurrent backup processing for multiple repositories defined in a YAML config file
- Automated backups with Docker deployment (every 3 days)
- GitHub token-based authentication (to be used in an environment variable)
- Easy restoration capability due to it being local mirror
- Multi-arch and multi-OS binary for simple one-time usage
go install github.com/tanq16/backhub@latest
mkdir $HOME/backhub # this is where you put your .backhub.yaml file
docker run -d \
--name backhub \
-e GH_TOKEN=your_github_token \
-v $HOME/backhub:/app \
tanq16/backhub:latest
git clone https://github.com/tanq16/backhub.git && cd backhub
go build
Run directly with default config path:
backhub
Specify custom config path:
backhub -c /path/to/config.yaml
For inline environment variable, use as:
GH_TOKEN=pat_jsdhksjdskhjdhkajshkdjh backhub
The Docker container automatically runs backups every 3 days.
version: "3.8"
services:
backhub:
image: tanq16/backhub:latest
restart: unless-stopped
environment:
- GH_TOKEN=your_github_token
volumes:
- /home/tanq/backhub:/app
BackHub uses a simple YAML configuration file. Default path is .backhub.yaml
:
repos:
- github.com/username/repo1
- github.com/username/repo2
- github.com/org/repo3
Lastly, use the GH_TOKEN
environment variable as your GitHub personal access token to use perform the backup.
To use a local mirror as a Git repository source (like when you need to restore from the backup), the following can be done:
-
Directly pull or clone from the mirror:
# Add the mirror as remote to an existing repo git remote add backup /path/to/your/mirror.git git pull backup main # or any other branch # clone from the mirror git clone /path/to/your/mirror.git new-repo
-
Serve the mirror as a local Git server:
# In the mirror directory git daemon --base-path=/path/to/parent --export-all # Clone from the new git server git clone git://localhost/mirror.git
-
Using file protocol in the Git URL:
git clone file:///path/to/mirror.git
Since it's a mirror, it contains all refs (branches, tags, etc.), so when you clone or pull from it, it can access everything like from the original. Use the following to see all branches and tags in the mirror:
git branch -a # shows all branches
git tag -l # shows all tags