mirror of
https://github.com/morten-olsen/homelab-operator.git
synced 2026-02-08 01:36:28 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d091f3030b | ||
|
|
44ead050c7 | ||
|
|
c5a15ed5d4 |
3
charts/backup/Chart.yaml
Normal file
3
charts/backup/Chart.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
apiVersion: v2
|
||||||
|
version: 1.0.0
|
||||||
|
name: backup
|
||||||
45
charts/backup/templates/cron-job-backup.yaml
Normal file
45
charts/backup/templates/cron-job-backup.yaml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{{- $values := .Values -}}
|
||||||
|
{{- $release := .Release -}}
|
||||||
|
|
||||||
|
---
|
||||||
|
{{- range $key, $value := $values.jobs}}
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: CronJob
|
||||||
|
metadata:
|
||||||
|
name: "{{ $release.Name }}-{{ $key }}-backup"
|
||||||
|
spec:
|
||||||
|
schedule: "{{ $value.cron.backup }}"
|
||||||
|
concurrencyPolicy: Forbid
|
||||||
|
successfulJobsHistoryLimit: 3
|
||||||
|
failedJobsHistoryLimit: 1
|
||||||
|
jobTemplate:
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: "{{ $release.Name }}-{{ $key }}-backup"
|
||||||
|
image: ghcr.io/morten-olsen/homelab-operator-backup:main
|
||||||
|
imagePullPolicy: Always
|
||||||
|
command: ["/app/backup.sh"]
|
||||||
|
env:
|
||||||
|
- name: RESTIC_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: "{{ $values.password.name }}"
|
||||||
|
key: "{{ $values.password.key }}"
|
||||||
|
volumeMounts:
|
||||||
|
- name: source
|
||||||
|
mountPath: "/mnt/source"
|
||||||
|
- name: target
|
||||||
|
mountPath: "/mnt/backups"
|
||||||
|
subPath: "{{ $release.Name }}-{{ $key }}"
|
||||||
|
volumes:
|
||||||
|
- name: source
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: "{{ $value.source }}"
|
||||||
|
- name: target
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: "{{ $values.target }}"
|
||||||
|
restartPolicy: OnFailure
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
40
charts/backup/templates/cron-job-cleanup.yaml
Normal file
40
charts/backup/templates/cron-job-cleanup.yaml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{{- $values := .Values -}}
|
||||||
|
{{- $release := .Release -}}
|
||||||
|
|
||||||
|
---
|
||||||
|
{{- range $key, $value := $values.jobs}}
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: CronJob
|
||||||
|
metadata:
|
||||||
|
name: "{{ $release.Name }}-{{ $key }}-cleanup"
|
||||||
|
spec:
|
||||||
|
schedule: "{{ $value.cron.cleanup }}"
|
||||||
|
concurrencyPolicy: Forbid
|
||||||
|
successfulJobsHistoryLimit: 3
|
||||||
|
failedJobsHistoryLimit: 1
|
||||||
|
jobTemplate:
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: "{{ $release.Name }}-{{ $key }}-cleanup"
|
||||||
|
image: ghcr.io/morten-olsen/homelab-operator-backup:main
|
||||||
|
imagePullPolicy: Always
|
||||||
|
command: ["/app/cleanup.sh"]
|
||||||
|
env:
|
||||||
|
- name: RESTIC_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: "{{ $values.password.name }}"
|
||||||
|
key: "{{ $values.password.key }}"
|
||||||
|
volumeMounts:
|
||||||
|
- name: target
|
||||||
|
mountPath: "/mnt/backup"
|
||||||
|
subPath: "{{ $release.Name }}-{{ $key }}"
|
||||||
|
volumes:
|
||||||
|
- name: target
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: "{{ $values.target }}"
|
||||||
|
restartPolicy: OnFailure
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
10
charts/backup/values.yaml
Normal file
10
charts/backup/values.yaml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
password:
|
||||||
|
name: backup
|
||||||
|
key: password
|
||||||
|
jobs:
|
||||||
|
pictures:
|
||||||
|
cron:
|
||||||
|
backup: "0 2 * * *"
|
||||||
|
cleanup: "0 4 * * SUN"
|
||||||
|
source: pictures
|
||||||
|
target: backups
|
||||||
@@ -16,14 +16,14 @@ mkdir -p "/mnt/backup"
|
|||||||
echo "Starting Restic backup from $SOURCE_DIR to $RESTIC_REPOSITORY"
|
echo "Starting Restic backup from $SOURCE_DIR to $RESTIC_REPOSITORY"
|
||||||
|
|
||||||
echo "Checking/Initializing Restic repository..."
|
echo "Checking/Initializing Restic repository..."
|
||||||
restic init --repository "$RESTIC_REPOSITORY" || true
|
restic init --repo "$RESTIC_REPOSITORY" || true
|
||||||
|
|
||||||
echo "Running Restic backup..."
|
echo "Running Restic backup..."
|
||||||
restic backup \
|
restic backup \
|
||||||
|
-r "$RESTIC_REPOSITORY"
|
||||||
"$SOURCE_DIR" \
|
"$SOURCE_DIR" \
|
||||||
--verbose \
|
--verbose \
|
||||||
--tag "daily" \
|
--tag "daily" \
|
||||||
--exclude-cache \
|
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Restic backup completed successfully!"
|
echo "Restic backup completed successfully!"
|
||||||
|
|||||||
Reference in New Issue
Block a user