Skip to content
/ backhub Public

Backhub helps maintain backups of multiple GitHub repos as full local mirrors.

License

Notifications You must be signed in to change notification settings

Tanq16/backhub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BackHub Logo

BackHub


Release Build Go Report Card
GitHub Release Docker Pulls

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.


Features

  • 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

Installation

Go Install

go install github.com/tanq16/backhub@latest

Docker Installation

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

Building from Source

git clone https://github.com/tanq16/backhub.git && cd backhub
go build

Usage

Binary Mode

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

Docker Mode

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

YAML Config File

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.

Using the Local Mirrors

To use a local mirror as a Git repository source (like when you need to restore from the backup), the following can be done:

  1. 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
  2. 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
  3. 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