Skip to content

Commit d982f25

Browse files
Merge pull request #158 from irfanhakim-as/borgmatic
Add Borgmatic Helm chart
2 parents bf1c19c + 5852a05 commit d982f25

12 files changed

Lines changed: 810 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Applications, developed or curated by [mika](https://github.com/irfanhakim-as),
1818

1919
| Chart Name | Description | Support | Access |
2020
| ---------- | ----------- | ------- | ------ |
21+
| [borgmatic](mika/borgmatic) | Simple, configuration-driven backup software for servers and workstations. |||
2122
| [clog](mika/clog) | Creative blog, Career blog, Coin blog, you name it. || 🔒 |
2223
| [cloudflared](mika/cloudflared) | Cloudflare Tunnel is a tunneling software that lets you quickly secure and encrypt application traffic to any type of infrastructure. |||
2324
| [cloudflareddns](mika/cloudflareddns) | Access your home network remotely via a custom domain name without a static IP! |||

mika/borgmatic/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

mika/borgmatic/Chart.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v2
2+
name: borgmatic
3+
description: Simple, configuration-driven backup software for servers and workstations.
4+
type: application
5+
version: 0.1.0
6+
appVersion: "1.9.6"
7+
keywords:
8+
- "borgmatic"
9+
- "backup"
10+
- "borg"
11+
home: "https://torsion.org/borgmatic/"
12+
icon: "https://torsion.org/borgmatic/static/borgmatic.png"
13+
sources:
14+
- "https://github.com/borgmatic-collective/borgmatic"
15+
- "https://github.com/borgmatic-collective/docker-borgmatic"
16+
- "https://github.com/irfanhakim-as/charts"
17+
maintainers:
18+
- name: "Irfan Hakim"
19+
email: "irfanhakim.as@yahoo.com"
20+
url: "https://github.com/irfanhakim-as"

mika/borgmatic/README.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# [borgmatic](https://github.com/borgmatic-collective/borgmatic)
2+
3+
Simple, configuration-driven backup software for servers and workstations.
4+
5+
## Prerequisites
6+
7+
> [!NOTE]
8+
> You may refer to [Orked](https://github.com/irfanhakim-as/orked) for help with setting up a Kubernetes cluster that meets all the following prerequisites.
9+
10+
- Kubernetes 1.19+
11+
- Helm 3.2.0+
12+
- Longhorn 1.4.1+
13+
14+
---
15+
16+
## Preflight checklist
17+
18+
> [!IMPORTANT]
19+
> The following items are required to be set up prior to installing this chart.
20+
21+
### Set up SSH key
22+
23+
An SSH key pair is required for authenticating with the remote Borg server. The public key must be authorised on the remote server, and the private key content should be provided as the value of `borgmatic.global.sshPrivateKey` (shared across all jobs) or `borgmatic.configs.<name>.sshPrivateKey` (per job) in your values file.
24+
25+
1. Generate an SSH key pair:
26+
27+
```sh
28+
ssh-keygen -t ed25519 -C "borgmatic" -f ./borgmatic_ed25519
29+
```
30+
31+
2. Authorise the public key on the remote Borg server:
32+
33+
```sh
34+
ssh-copy-id -i ./borgmatic_ed25519.pub <user>@<backuphost>
35+
```
36+
37+
Replace `<user>` and `<backuphost>` accordingly.
38+
39+
3. Copy the private key content for use as the value of `borgmatic.global.sshPrivateKey` or `borgmatic.configs.<name>.sshPrivateKey` in your values file:
40+
41+
```sh
42+
cat ./borgmatic_ed25519
43+
```
44+
45+
---
46+
47+
## Recommended configurations
48+
49+
> [!NOTE]
50+
> The following configuration recommendations might not be the default settings for this chart but are **highly recommended**. Please carefully consider them before configuring your installation.
51+
52+
**This section does not apply to this chart.**
53+
54+
---
55+
56+
## Application configurations
57+
58+
> [!NOTE]
59+
> The following configurations are expected or recommended to be set up from within the application after completing the installation.
60+
61+
### Initialise the Borg repository
62+
63+
Each Borg repository must be initialised once before borgmatic can perform backups.
64+
65+
1. Create a one-off shell job for the borgmatic config:
66+
67+
```sh
68+
kubectl create job --namespace ${namespace} borgmatic-shell --from=cronjob/${releaseName}-borgmatic-<name>-shell
69+
```
70+
71+
Replace `${namespace}`, `${releaseName}`, and `<name>` with the config name (e.g. `databases`, `files`) accordingly.
72+
73+
2. Once the pod is running, get the pod name and exec into it to initialise the repository:
74+
75+
```sh
76+
kubectl get pod --namespace ${namespace} -l job-name=borgmatic-shell
77+
kubectl exec --namespace ${namespace} -it <pod-name> -- \
78+
borgmatic init --encryption repokey-blake2 --config /etc/borgmatic.d/<name>.yaml
79+
```
80+
81+
Replace `${namespace}`, `<pod-name>`, and `<name>` accordingly.
82+
83+
3. Delete the job once initialisation is complete:
84+
85+
```sh
86+
kubectl delete job --namespace ${namespace} borgmatic-shell
87+
```
88+
89+
Replace `${namespace}` accordingly.
90+
91+
---
92+
93+
## How to add the chart repo
94+
95+
1. Add the repo to your local helm client:
96+
97+
```sh
98+
helm repo add mika https://irfanhakim-as.github.io/charts
99+
```
100+
101+
2. Update the repo to retrieve the latest versions of the packages:
102+
103+
```sh
104+
helm repo update
105+
```
106+
107+
---
108+
109+
## How to install or upgrade a chart release
110+
111+
1. Get the values file of the borgmatic chart or an existing installation (release).
112+
113+
Get the latest borgmatic chart values file for a new installation:
114+
115+
```sh
116+
helm show values mika/borgmatic > values.yaml
117+
```
118+
119+
**Alternatively**, get the values file of an existing borgmatic release:
120+
121+
```sh
122+
helm get values ${releaseName} --namespace ${namespace} > values.yaml
123+
```
124+
125+
Replace `${releaseName}` and `${namespace}` accordingly.
126+
127+
2. Edit your borgmatic values file with the intended configurations:
128+
129+
```sh
130+
nano values.yaml
131+
```
132+
133+
Pay extra attention to the descriptions and sample values provided in the chart values file.
134+
135+
3. Install a new release for borgmatic or upgrade an existing borgmatic release:
136+
137+
```sh
138+
helm upgrade --install ${releaseName} mika/borgmatic --namespace ${namespace} --create-namespace --values values.yaml --wait
139+
```
140+
141+
Replace `${releaseName}` and `${namespace}` accordingly.
142+
143+
4. Verify that your borgmatic release has been installed:
144+
145+
```sh
146+
helm ls --namespace ${namespace} | grep "${releaseName}"
147+
```
148+
149+
Replace `${namespace}` and `${releaseName}` accordingly. This should return the release information if the release has been installed.
150+
151+
---
152+
153+
## How to uninstall a chart release
154+
155+
> [!CAUTION]
156+
> Uninstalling a release will irreversibly delete all the resources associated with the release, including any persistent data.
157+
158+
1. Uninstall the desired release:
159+
160+
```sh
161+
helm uninstall ${releaseName} --namespace ${namespace} --wait
162+
```
163+
164+
Replace `${releaseName}` and `${namespace}` accordingly.
165+
166+
2. Verify that the release has been uninstalled:
167+
168+
```sh
169+
helm ls --namespace ${namespace} | grep "${releaseName}"
170+
```
171+
172+
Replace `${namespace}` and `${releaseName}` accordingly. This should return nothing if the release has been uninstalled.
173+
174+
---
175+
176+
## Chart configurations
177+
178+
| Key | Type | Default | Description |
179+
|-----|------|---------|-------------|
180+
| borgmatic.configs | object | `{}` | A map of borgmatic configuration jobs, each generating a dedicated CronJob with its own schedule. Items: `.schedule`, `.passphrase`, `.sshPrivateKey`, `.secrets`, `.volumes`, `.content`. |
181+
| borgmatic.global.passphrase | string | `""` | The passphrase used to encrypt and decrypt the Borg repository, shared across all borgmatic jobs. |
182+
| borgmatic.global.secrets | object | `{}` | Secret environment variables shared across all borgmatic jobs. |
183+
| borgmatic.global.sshPrivateKey | string | `""` | SSH private key content shared across all borgmatic jobs. |
184+
| borgmatic.timezone | string | `""` | The timezone used for the borgmatic CronJob schedule and log timestamps. Default: `"UTC"`. |
185+
| image.borgmatic.pullPolicy | string | `""` | The policy that determines when Kubernetes should pull the borgmatic container image. Default: `"IfNotPresent"`. |
186+
| image.borgmatic.registry | string | `""` | The registry where the borgmatic container image is hosted. Default: `"ghcr.io"`. |
187+
| image.borgmatic.repository | string | `""` | The name of the repository that contains the borgmatic container image used. Default: `"borgmatic-collective/borgmatic"`. |
188+
| image.borgmatic.tag | string | `""` | The tag that specifies the version of the borgmatic container image used. Default: `Chart appVersion`. |
189+
| imagePullSecrets | list | `[]` | Credentials used to securely authenticate and authorise the pulling of container images from private registries. |
190+
| resources.borgmatic | object | `{}` | borgmatic container resources. |
191+
| storage.data.accessMode | string | `""` | The access mode defining how the data storage can be mounted. Default: `"ReadWriteMany"`. |
192+
| storage.data.enabled | bool | `false` | Specifies whether persistent storage should be provisioned for data storage. |
193+
| storage.data.storage | string | `""` | The default amount of persistent storage allocated for the data storage. Default: `"1Gi"`. |
194+
| storage.data.storageClassName | string | `""` | The storage class name used for dynamically provisioning a persistent volume for the data storage. Default: `"longhorn"`. |

mika/borgmatic/templates/NOTES.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{{- $borgmaticConfigs := .Values.borgmatic.configs }}
2+
{{- $dataPersistence := .Values.storage.data.enabled }}
3+
{{- $globalPassphrase := .Values.borgmatic.global.passphrase | toString }}
4+
{{- $globalSSHKey := .Values.borgmatic.global.sshPrivateKey | toString }}
5+
borgmatic has been installed and configured for {{ .Release.Name | toString }} 🎉
6+
7+
The following are a list of backup job(s) you have configured:
8+
9+
{{- if not $borgmaticConfigs }}
10+
11+
⚠️ No backup jobs were configured for borgmatic to run
12+
13+
{{- else }}
14+
15+
{{- $i := 0 }}
16+
{{- range $name, $job := $borgmaticConfigs }}
17+
{{- $i = add1 $i }}
18+
{{- $schedule := $job.schedule | default "0 3 * * *" | toString }}
19+
{{- $passphrase := "no" }}
20+
{{- if or ($job.passphrase | toString) $globalPassphrase }}{{- $passphrase = "yes" }}{{- end }}
21+
{{- $sshKey := "no" }}
22+
{{- if or ($job.sshPrivateKey | toString) $globalSSHKey }}{{- $sshKey = "yes" }}{{- end }}
23+
{{- $volumeCount := len ($job.volumes | default (list)) }}
24+
25+
{{ printf "%s. name=%s | schedule=%s | passphrase=%s | ssh_key=%s | volumes=%s" ($i | toString) $name $schedule $passphrase $sshKey ($volumeCount | toString) }}
26+
27+
{{- end }}
28+
29+
{{- end }}
30+
31+
Persistent state storage: {{ ternary "enabled" "disabled" $dataPersistence }}
32+
33+
If this is a new installation, initialise each Borg repository before backups can run:
34+
35+
kubectl create job --namespace {{ .Release.Namespace }} borgmatic-shell --from=cronjob/{{ .Release.Name }}-borgmatic-<name>-shell
36+
37+
kubectl get pod --namespace {{ .Release.Namespace }} -l job-name=borgmatic-shell
38+
39+
kubectl exec --namespace {{ .Release.Namespace }} -it <pod-name> -- borgmatic init --encryption repokey-blake2 --config /etc/borgmatic.d/<name>.yaml
40+
41+
kubectl delete job --namespace {{ .Release.Namespace }} borgmatic-shell
42+
43+
Replace <name> with the config name (e.g. main, databases).
44+
45+
To open an interactive shell for borgmatic inspection (e.g. listing archives), run:
46+
47+
kubectl create job --namespace {{ .Release.Namespace }} borgmatic-shell --from=cronjob/{{ .Release.Name }}-borgmatic-<name>-shell
48+
49+
kubectl get pod --namespace {{ .Release.Namespace }} -l job-name=borgmatic-shell
50+
51+
kubectl exec --namespace {{ .Release.Namespace }} -it <pod-name> -- /bin/sh
52+
53+
kubectl delete job --namespace {{ .Release.Namespace }} borgmatic-shell
54+
55+
Replace <name> with the config name (e.g. main, databases).
56+
57+
To manually trigger a backup job, run:
58+
59+
kubectl create job --namespace {{ .Release.Namespace }} --from=cronjob/{{ .Release.Name }}-borgmatic-<name> {{ .Release.Name }}-borgmatic-<name>-manual
60+
61+
Replace <name> with the config name (e.g. main, databases).
62+
63+
To view borgmatic logs from the most recent backup run, run:
64+
65+
kubectl logs --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "borgmatic.name" . }},app.kubernetes.io/instance={{ .Release.Name }}"
66+
67+
For more information on how to use and configure borgmatic, please refer to the official documentation.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "borgmatic.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "borgmatic.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "borgmatic.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "borgmatic.labels" -}}
37+
helm.sh/chart: {{ include "borgmatic.chart" . }}
38+
{{ include "borgmatic.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "borgmatic.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "borgmatic.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "borgmatic.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "borgmatic.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

0 commit comments

Comments
 (0)