How to create automatic arangodb cluster backups in a Kubernetes Cluster?
This is how I solved it (credits to the offical arangodb github for the first part of the script).
What is the script doing?
We are creating a cronjob which will run every 14 days. Then we spin up a pod which will use the arangodump
tool to dump (in this case) the whole database.
By passing it data like the database url,password, user name and save it on a volume under temp/dump
.
Afterwards we create another pod which uses the minio cli tool, which allows to interact with any of the major object storage providers.
We first set an mc alias for gcloud with the access key and secret, you can replace this with any other s3 compatible provider url. Aftwerwards we will mirror the /temp/dump
to the cloud bucket (in this case qute, replace this with your own bucket name!) in a folder with the most date of the backup. $()
can be used to execute shell commands and use the return value, just for anybody not knowing that.
apiVersion: batch/v1beta1kind: CronJobmetadata: name: backup-jobspec: schedule: "0 0 */14 * *" #Runs the job at every 14 days jobTemplate: spec: template: metadata: name: backup-job spec: initContainers: - name: dump-create image: "arangodb:3.7.3" args: - "arangodump" - "--server.endpoint=$(ENDPOINT)" - "--server.username=$(USERNAME)" - "--server.password=$(PASSWORD)" - "--server.database=MY-DATABASE" - "--output-directory=/tmp/dump" - "--overwrite" volumeMounts: - name: dump mountPath: /tmp/dump env: - name: "PASSWORD" valueFrom: secretKeyRef: name: signing-secret key: root-password - name: "USERNAME" valueFrom: configMapKeyRef: name: signing-config key: "admin-user" - name: "ENDPOINT" valueFrom: configMapKeyRef: name: signing-config key: db-url restartPolicy: OnFailure containers: - name: db-dump-upload image: "minio/mc" imagePullPolicy: IfNotPresent command: ["/bin/sh","-c"] args: ["mc alias set gcs https://storage.googleapis.com $ACCESSKEY $SECRETKEY; mc mirror /tmp/dump gcs/qute/$(date -I)"] #no () for env variables!!!! volumeMounts: - name: dump mountPath: /tmp/dump env: - name: SECRETKEY valueFrom: secretKeyRef: name: backup-secret key: secret - name: ACCESSKEY valueFrom: secretKeyRef: name: backup-secret key: access-key volumes: - name: dump emptyDir: {}