djlactose/github_backup
A Docker container that performs daily backups of your GitHub repositories locally.
1.3K
This project provides a Docker container that performs daily backups of your GitHub repositories locally. Instead of using cron, the container runs an infinite loop that checks the current time every hour. When the current hour matches the scheduled backup time (configurable via an environment variable), the backup script is executed once per day.
Note:
For private repositories or higher API rate limits, supply a GitHub token via theGITHUB_TOKEN
environment variable. If you only need to backup public repositories, this variable can be omitted.
Automated Daily Backups:
The container’s entrypoint script runs an infinite loop that checks every hour. When the current hour matches the configured backup hour, it runs the backup script (only once per day).
Mirror Cloning:
Uses git clone --mirror
to perform complete backups of your repositories, preserving all refs (branches, tags, etc.).
GitHub API Integration with Pagination:
The backup script fetches all repositories using the GitHub API (handling pagination if you have more than 100 repositories).
Volume Persistence:
Backups are stored on a host-mounted volume so that they persist even if the container restarts.
Configurable Backup Time:
Specify the desired backup hour (in 24-hour format) using the BACKUP_HOUR
environment variable (default is 2
for 2 AM).
Dockerfile:
Builds the image using Alpine Linux, installs required packages (git
, curl
, jq
), and copies the backup and entrypoint scripts.
backup.sh:
The script that fetches all GitHub repositories (with pagination) and either mirror-clones or updates the backup for each repository.
entrypoint.sh:
The script that runs in an infinite loop, checking the current hour every 3600 seconds. If the current hour matches the configured backup hour (and the backup hasn’t already been run that day), it triggers backup.sh
.
The container supports the following environment variables:
GITHUB_USER (required):
Your GitHub username. This is used to fetch your public repositories (or private ones if a token is provided).
GITHUB_TOKEN (optional):
A GitHub token with the necessary permissions. If provided, this allows the container to access private repositories and increases the API rate limit.
BACKUP_HOUR (optional):
The hour (in 24-hour format) when the backup should run each day. If not provided, the default value is 2
(i.e., 2 AM).
Clone the project repository to your local machine:
git clone https://github.com/yourusername/github-backup.git
cd github-backup
docker pull djlactose/github_backup