https://github.com/ebiiim/gitbackup
A Kubernetes Operator for scheduled backup of Git repositories.
https://github.com/ebiiim/gitbackup
backup git kubernetes operator
Last synced: 5 months ago
JSON representation
A Kubernetes Operator for scheduled backup of Git repositories.
- Host: GitHub
- URL: https://github.com/ebiiim/gitbackup
- Owner: ebiiim
- License: mit
- Created: 2022-11-15T08:33:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-22T11:05:30.000Z (over 1 year ago)
- Last Synced: 2025-01-22T12:21:46.683Z (over 1 year ago)
- Topics: backup, git, kubernetes, operator
- Language: Go
- Homepage:
- Size: 160 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Git Backup Operator
[](https://github.com/ebiiim/gitbackup/blob/main/LICENSE)
[](https://github.com/ebiiim/gitbackup/releases/latest)
[](https://github.com/ebiiim/gitbackup/actions/workflows/ci.yaml)

[](https://goreportcard.com/report/github.com/ebiiim/gitbackup)
[](https://codecov.io/gh/ebiiim/gitbackup)
A [Kubernetes Operator](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/) for scheduled backup of Git repositories.
- [Overview](#overview)
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Backup a Git repository with a `Repository` resource](#backup-a-git-repository-with-a-repository-resource)
- [Backup many Git repositories with a `Collection` resource](#backup-many-git-repositories-with-a-collection-resource)
- [Uninstallation](#uninstallation)
- [Developing](#developing)
- [Prerequisites](#prerequisites)
- [Run a development cluster with kind](#run-a-development-cluster-with-kind)
## Overview
1. You create a `Repository` resource.
2. The Operator creates a `CronJob` resource from it.
3. The `CronJob` does the actual work.
```yaml
apiVersion: gitbackup.ebiiim.com/v1beta1
kind: Repository
metadata:
name: repo1
spec:
src: https://github.com/ebiiim/gitbackup
dst: https://gitlab.com/ebiiim/gitbackup
schedule: "0 6 * * *"
gitCredentials:
name: repo1-secret # specify a Secret resource in the same namespace
```
## Getting Started
Supported Kubernetes versions: __1.21 or higher__
### Installation
Make sure you have [cert-manager](https://cert-manager.io/) deployed, as it is used to generate webhook certificates.
```sh
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.10.0/cert-manager.yaml
```
> ⚠️ You may have to wait a second for cert-manager to be ready.
Deploy the Operator with the following command. It creates `gitbackup-system` namespace and deploys CRDs, controllers and other resources.
```sh
kubectl apply -f https://github.com/ebiiim/gitbackup/releases/download/v0.2.1/gitbackup.yaml
```
### Backup a Git repository with a `Repository` resource
First, create a `Secret` resource that contains `.git-credentials`.
```sh
kubectl create secret generic repo1-secret --from-file=$HOME/.git-credentials
```
Next, create a `Repository` resource.
```yaml
apiVersion: gitbackup.ebiiim.com/v1beta1
kind: Repository
metadata:
name: repo1
spec:
src: https://github.com/ebiiim/gitbackup
dst: https://gitlab.com/ebiiim/gitbackup
schedule: "0 6 * * *"
gitCredentials:
name: repo1-secret
```
Finally, confirm that resources has been created.
```
$ kubectl get repos
NAME AGE
repo1 5s
$ kubectl get cronjobs
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
gitbackup-repo1 0 6 * * * False 0 5s
```
> 💡 You can test the `CronJob` by manually triggering it.
>
> ```sh
> kubectl create job --from=cronjob/
> ```
### Backup many Git repositories with a `Collection` resource
First, create a `Secret` resource that contains `.git-credentials`.
```sh
kubectl create secret generic coll1-secret --from-file=$HOME/.git-credentials
```
Next, create a `Collection` resource.
```yaml
apiVersion: gitbackup.ebiiim.com/v1beta1
kind: Collection
metadata:
name: coll1
spec:
schedule: "0 6 * * *"
gitCredentials:
name: coll1-secret
repos:
- name: gitbackup
src: https://github.com/ebiiim/gitbackup
dst: https://gitlab.com/ebiiim/gitbackup
- name: foo
src: https://example.com/src/foo
dst: https://example.com/dst/foo
- name: bar
src: https://example.com/src/bar
dst: https://example.com/dst/bar
```
Finally, confirm that resources has been created.
```
$ kubectl get colls
NAME AGE
coll1 5s
$ kubectl get repos
NAME AGE
coll1-bar 5s
coll1-foo 5s
coll1-gitbackup 5s
$ kubectl get cronjobs
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
gitbackup-coll1-bar 2 6 * * * False 0 5s
gitbackup-coll1-foo 1 6 * * * False 0 5s
gitbackup-coll1-gitbackup 0 6 * * * False 0 5s
```
> 💡 Each job runs one minute apart.
### Uninstallation
Delete the Operator and resources with the following command.
```sh
kubectl delete -f https://github.com/ebiiim/gitbackup/releases/download/v0.2.1/gitbackup.yaml
```
## Developing
This Operator uses [Kubebuilder](https://github.com/kubernetes-sigs/kubebuilder) (v3.8.0), so we basically follow the Kubebuilder way. See the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html) for details.
### Prerequisites
Make sure you have the following tools installed:
- Git
- Make
- Go
- Docker
### Run a development cluster with [kind](https://kind.sigs.k8s.io/)
```sh
./hack/dev-kind-reset-cluster.sh # create a K8s cluster `kind-gitbackup`
./hack/dev-kind-deploy.sh # build and deploy the Operator
```