A git backup script wrapped in Alpine Linux.
10K+
This dockerizes a simple script I wrote years ago to create git bundle backups of a private git server.
The example helm / docker-compose service definition will cause a dump of all accessible projects to happen at the default hour (0:45am in $TZ) from a GitLab server named git.instantlinux.net onto a subdirectory git in volume "backup".
Retention is set by a variable KEEP_DAYS which defaults to 31. Within the DEST_DIR you will then find a separate directory for each day of the month. If you set KEEP_DAYS to 7, it will keep a directory for each day of the week. Backups older than KEEP_DAYS will be automatically removed.
Provide a read-only private ssh key to access your git repo(s) in the Docker secret git-dump_sshkey. Github has an apparently-permanent and seemingly-arbitrary restriction against using the same read-only deploy key for more than one repo, so unless you specify the https access method, you will need to set up multiple instances of this container to backup more than one Github repo.
For GitLab, Bitbucket or other private repos, you can use this to back up an arbitrary number of git repos which share the same deploy key. This script supports the GitLab v3 API to read the list of projects at runtime, so you don't have to specify the REPOS parameter.
This repo has complete instructions for building a kubernetes cluster where you can deploy with helm or kubernetes.yaml using make and customizing Makefile.vars after cloning this repo:
git clone https://github.com/instantlinux/docker-tools.git
cd docker-tools/k8s
make git-dump
These variables can be passed to the image from kubernetes.yaml or docker-compose.yml as needed:
| Variable | Default | Description |
|---|---|---|
| API_TOKEN_SECRETNAME | docker secret name of API token as below | |
| DEST_DIR | /var/backup/git | destination path |
| HOUR | 0 | cron-syntax backup hour |
| KEEP_DAYS | 31 | days of snapshots to keep |
| MINUTE | 45 | cron-syntax minutes past hour |
| ORG | org in SCM | |
| REPO_PREFIX | [email protected]:instantlinux/ | prefix for each repository URI |
| REPOS | repository URIs to back up | |
| SCM_TYPE | github | type - github, gitlab, or gitea |
| SSHKEY_SECRETNAME | git-dump_sshkey | docker secret name as below |
| SSH_PORT | 22 | TCP port of git service |
| TZ | UTC | time zone |
| Secret | Description |
|---|---|
| git-dump_sshkey | read-only key for git repos (override name above) |
| xxx-api-token | API token for fetching project list from gitlab |
If you want to make improvements to this image, see CONTRIBUTING.
Content type
Image
Digest
sha256:5d0a55621…
Size
17.2 MB
Last updated
17 days ago
docker pull instantlinux/git-dump