Enable back-up

Kubegres allows to back-up the Primary PostgreSql database to a given volume in a scheduled way.

If back-up is enabled in Kubegres YAML, behind the scenes a Kubernetes Cronjob resource is created which regularly executes a backup bash script. It is possible to override that bash script to have a better control of the backup process, as explained in the doc: Override the default configurations.

To enable the backup option in a Postgres cluster, add the property "backup" to its Kubegres YAML, as in the example below:

backup:
    schedule: "* */1 * * *"
    pvcName: my-backup-pvc
    volumeMount: /var/lib/backup
                    

The above config has the following properties:

  • "backup.schedule: "* */1 * * *" : it schedules a back-up every hour. Its format follows the standard Cron spec.
  • "backup.pvcName: my-backup-pvc" : the Persistence-Volume-Claim (PVC) defining where the back-up data will be stored. A volume backed by a PVC is mounted into the path defined by "backup.volumeMount" (see below).
  • "backup.volumeMount: /var/lib/backup" : the location where the backup is stored in the docker image. A volume is mounted on that path using the PVC name defined by "database.pvcName".

Please see below an example of a full Kubegres YAML config with those back-up properties:

apiVersion: kubegres.reactive-tech.io/v1
kind: Kubegres
metadata:
  name: mypostgres
  namespace: default

spec:

   replicas: 3
   image: postgres:13.2
   port: 5432

   database:
      size: 200Mi

   backup:
       schedule: "* */1 * * *"
       pvcName: my-backup-pvc
       volumeMount: /var/lib/backup

   env:
      - name: POSTGRES_PASSWORD
        valueFrom:
           secretKeyRef:
              name: mySecretResource
              key: superUserPassword

      - name: POSTGRES_REPLICATION_PASSWORD
        valueFrom:
           secretKeyRef:
              name: mySecretResource
              key: replicationUserPassword