Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languageyml
titlevalues.yaml
# Default values for mariadb-backup.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
image:
  repositorytag: "ktimoney/mysqldump_backup"
backoffLimit: 34
schedule: "\"*/155 * * * *\""
volumes:
  name: backup-pv
  storageClassName:
    path: /run/desktop/mnt/host/c/mariadb/backup
    accessModes: ReadWriteOnce
  capacity:
    storage: 50Mi
  persistentVolumeReclaimPolicy: Retain
  nodeAffinity:
    nodeSelectorTerms: docker-desktop
data:
  backup_retention_interval: mmin # mmin for minutes, mtime for days
  backup_retention_period: "\"120\""
  db_host: host.docker.internal
  db_port: "\3306"3355\""
  db_user: YmFja3Vw
  db_pwd: YmFja3Vw

...

Code Block
languageyml
titlebackupConfigMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: backup-config
  namespace: default
data:
  backup_retention_interval: {{ .Values.data.backup_retention_interval }}
  backup_retention_period: {{ .Values.data.backup_retention_period | quote }}
  db_host: {{ .Values.data.db_host }}
  db_port: {{ .Values.data.db_port | quote }}


Code Block
languageyml
titlebackupSecret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: backup-secret
type: Opaque
data:
  db_user: {{ .Values.data.db_user }}
  db_pwd: {{ .Values.data.db_pwd }}

...

Code Block
languageyml
titlebackupCronjob.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: backup-cron
spec:
  schedule: {{ .Values.schedule | quote }}
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          volumes:
            - name: backup-volume
              persistentVolumeClaim:
                claimName: backup-claim
          containers:
          - name: mysqldump-backup
            image: {{ .Values.image.repositorytag }}
            volumeMounts:
            - mountPath: /tmp
              name: backup-volume
            env:
            - name: DB_HOST
              valueFrom:
                configMapKeyRef:
                  name: backup-config
                  key: db_host
            - name: DB_PORT
              valueFrom:
                configMapKeyRef:
                  name: backup-config
                  key: db_port
            - name: BACKUP_RETENTION_INTERVAL
              valueFrom:
                configMapKeyRef:
                  name: backup-config
                  key: backup_retention_interval
            - name: BACKUP_RETENTION_PERIOD
              valueFrom:
                configMapKeyRef:
                  name: backup-config
                  key: backup_retention_period
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: backup-secret
                  key: db_user
            - name: DB_PWD
              valueFrom:
                secretKeyRef:
                  name: backup-secret
                  key: db_pwd
          restartPolicy: Never
      backoffLimit: {{ .Values.backoffLimit }}

...

 * backoffLimit sets the number of times (+1) the cron will retry the job before it stops

...

Replication as a Backup Solution

Testing

Backup Testing

Notes

We may need to create a user specifically for doing backups:

...