mirror of
https://github.com/morten-olsen/homelab-operator.git
synced 2026-02-08 01:36:28 +01:00
improvements
This commit is contained in:
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
|
||||
44
charts/backup/templates/cron-job-backup.yaml
Normal file
44
charts/backup/templates/cron-job-backup.yaml
Normal file
@@ -0,0 +1,44 @@
|
||||
{{- $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
|
||||
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 }}
|
||||
39
charts/backup/templates/cron-job-cleanup.yaml
Normal file
39
charts/backup/templates/cron-job-cleanup.yaml
Normal file
@@ -0,0 +1,39 @@
|
||||
{{- $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
|
||||
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,13 @@ mkdir -p "/mnt/backup"
|
||||
echo "Starting Restic backup from $SOURCE_DIR to $RESTIC_REPOSITORY"
|
||||
|
||||
echo "Checking/Initializing Restic repository..."
|
||||
restic init --repository "$RESTIC_REPOSITORY" || true
|
||||
restic init --repo "$RESTIC_REPOSITORY" || true
|
||||
|
||||
echo "Running Restic backup..."
|
||||
restic backup \
|
||||
"$SOURCE_DIR" \
|
||||
--verbose \
|
||||
--tag "daily" \
|
||||
--exclude-cache \
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Restic backup completed successfully!"
|
||||
|
||||
Reference in New Issue
Block a user