Backing Up MySQL Database using Openshift/Kubernetes Cron Job
Periodic Backups When running an application in production, the data and app should be backed up periodically. One way to do that is by using git repository for the source code and periodically dumping the database. This article shows how to do such periodic jobs using CronJob functionality of Openshift/Kubernetes. Technique When running a cronjob, the filesystem that being used to run the pod will be ephemeral, that is, non-persistent. To work around this limit we should mount from external volume, which can be in the form of persistent volume claim or directly provided volume specification. The Job specs apiVersion: batch/v1 kind: Job metadata: name: job04-test spec: template: spec: containers: - name: job04c-test image: centos/mysql-57-centos7 command: ["/bin/sh","-c", "/opt/rh/rh-mysql57/root/usr/bin/mysqldump --single-transaction -u $MYSQL_USER $MYSQL_DB -h $MYSQL_HOST | gzip > /tmp/dump`d