Skip to content

Commit

Permalink
Database backup (#1)
Browse files Browse the repository at this point in the history
* add database backup cron job
  • Loading branch information
SapiensAnatis authored Jan 26, 2023
1 parent 05c222d commit d6f331e
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 16 deletions.
4 changes: 2 additions & 2 deletions charts/dragalia-api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: A Helm chart for the Dragalia Lost server emulator

type: application

version: 1.1.9
appVersion: "1.1.0-alpha"
version: 1.2.0
appVersion: "latest"

dependencies:
- name: postgresql
Expand Down
40 changes: 40 additions & 0 deletions charts/dragalia-api/templates/db-backup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if .Values.postgresqlBackup.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: postgres-backup
spec:
schedule: {{ .Values.postgresqlBackup.cron | quote }}
jobTemplate:
spec:
template:
spec:
containers:
- name: postgres
image: postgres:latest
imagePullPolicy: IfNotPresent
command:
- pg_dump
- --username=postgres
- --no-password
- --format=custom
- --file=/backups/dragalia-api-$(date +"%Y-%m-%d_%H-%M-%S").bak
- --host={{ include "dragalia-api.fullname" . }}-postgresql
- --verbose
volumeMounts:
- name: password
mountPath: ~/.pgpassword
readOnly: true
- name: data
mountPath: /backups
restartPolicy: Never
volumes:
- name: password
secret:
secretName: {{ include "dragalia-api.fullname" . }}-postgresql
key: postgres-password
optional: false
- name: data
persistentVolumeClaim:
claimName: {{ include "dragalia-api.fullname" . }}-postgresql-backup
{{- end }}
14 changes: 14 additions & 0 deletions charts/dragalia-api/templates/db-claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if .Values.postgresqlBackup.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "dragalia-api.fullname" . }}-postgresql-backup
spec:
volumeName: {{ include "dragalia-api.fullname" . }}-postgresql-backup
storageClassName: "standard"
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.postgresqlBackup.maxSize }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/dragalia-api/templates/db-volume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.postgresqlBackup.enabled }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ include "dragalia-api.fullname" . }}-postgresql-backup
labels:
type: local
spec:
storageClassName: "standard"
claimRef:
name: {{ include "dragalia-api.fullname" . }}-postgresql-backup
capacity:
storage: {{ .Values.postgresqlBackup.maxSize }}
accessModes:
- ReadWriteOnce
hostPath:
path: {{ .Values.postgresqlBackup.path | quote }}
{{- end }}
6 changes: 3 additions & 3 deletions charts/dragalia-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
protocol: TCP
volumeMounts:
- mountPath: "/app/logs"
name: log
name: logs
- mountPath: "/app/appsettings.{{ .Values.aspnet.environment }}.json"
name: config
subPath: "appsettings.json"
Expand Down Expand Up @@ -86,9 +86,9 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: log
- name: logs
persistentVolumeClaim:
claimName: {{ include "dragalia-api.fullname" . }}
claimName: {{ include "dragalia-api.fullname" . }}-logs
- name: config
configMap:
name: {{ include "dragalia-api.fullname" . }}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "dragalia-api.fullname" . }}
name: {{ include "dragalia-api.fullname" . }}-logs
spec:
volumeName: {{ include "dragalia-api.fullname" . }}
storageClassName: manual
volumeName: {{ include "dragalia-api.fullname" . }}-logs
storageClassName: "standard"
accessModes:
- ReadWriteOnce
resources:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ include "dragalia-api.fullname" . }}
name: {{ include "dragalia-api.fullname" . }}-logs
labels:
type: local
spec:
claimRef:
namespace: default
name: {{ include "dragalia-api.fullname" . }}
storageClassName: manual
name: {{ include "dragalia-api.fullname" . }}-logs
storageClassName: "standard"
capacity:
storage: {{ .Values.aspnet.logs.maxSize }}
accessModes:
- ReadWriteOnce
hostPath:
path: {{ .Values.aspnet.logs.folder }}
path: {{ .Values.aspnet.logs.folder | quote }}
14 changes: 11 additions & 3 deletions charts/dragalia-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ replicaCount: 1
image:
repository: sapiensanatis/dragalia-api
pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"

imagePullSecrets: []
nameOverride: ""
Expand All @@ -23,7 +21,7 @@ aspnet:
# The folder to save logs to
folder: /dragalia-api/logs
# The size of the log volume
maxSize: 5Gi
maxSize: 2Gi
# How many log files to retain.
retainedFileCount: 31
# When to roll over log files. Will also roll if >1GB.
Expand Down Expand Up @@ -90,6 +88,16 @@ postgresql:
postgresPassword: midgardsormr2
volumePermissions:
enabled: true

postgresqlBackup:
# Enable postgres backup
enabled: true
# Schedule for backup cron job
cron: "@daily"
# Backup volume size
maxSize: "10Gi"
# Backup volume host path
path: /dragalia-api/db-backup

service:
type: ClusterIP
Expand Down

0 comments on commit d6f331e

Please sign in to comment.