db-backup-retention

by wjentner

Helm chartv1.1.0App v1.1.0Verified publisher

A Helm chart to set up a database backup (including timed retention) using a CronJob.

About this chart

db-backup-retention

A Helm chart to set up a database backup (including timed retention) using a CronJob.

Script

The Dockerfile and script to create the backup can be found here: https://github.com/wjentner/k8s-db-backup-retention

This has been tested with bitnami/mariadb and bitnami/postgresql images. Other images might require adjustments.

Minimal examples

MariaDB/MySQL (mysqldump/mariadb-dump)

The following example creates an hourly backup of a MariaDB/MySQL database system and keeps those backups for 30 days before deleting them. The backups are created by executing mysqldump inside the database pod. This will create files in your mounted folder similar to:

my-db-backup-2025-02-04T20:00:01+00:00.sql.gz
my-db-backup-2025-02-04T21:00:01+00:00.sql.gz
config:
  dbPod: my-mariadb-0
  dbUser:
    value: root
    #secret:
    #  name: my-db-secret
    #  key: my-secret-user-key
  dbPassword:
    # value: keepMeSecret! (not recommended)
    secret:
      name: my-db-secret
      key: MARIADB_ROOT_PASSWORD
  # if you use MariaDB, consider using mariadb-dump
  backupExec: mysqldump
  # backup all databases or name them explicitly
  backupDatabases: --all-databases
  # 30 days
  retentionMinutes: 43200
  backupFilePrefix: my-db-backup

persistence:
  enabled: true
  size: 10Gi
  storageClass: my-storage

# cronjob:
#   schedule: 0 * * * *
#   concurrencyPolicy: Forbid
#   failedJobsHistoryLimit: 2
#   successfulJobsHistoryLimit: 1
#   backoffLimit: 2
#   restartPolicy: Never

PostgreSQL (pg_dump/pg_dumpall)

The following example creates an hourly backup of a PostgreSQL database system and keeps those backups for 30 days before deleting them. The backups are created by executing pg_dumpall inside the database pod. This will create files in your mounted folder similar to:

my-db-backup-2025-02-04T20:00:01+00:00.sql.gz
my-db-backup-2025-02-04T21:00:01+00:00.sql.gz
config:
  dbPod: my-postgresql-0
  dbUser:
    value: root
    #secret:
    #  name: my-db-secret
    #  key: my-secret-user-key
  dbPassword:
    # value: keepMeSecret! (not recommended)
    secret:
      name: my-db-secret
      key: DB_ROOT_PASSWORD
  backupExec: pg_dumpall
  # ignored for pg_dumpall
  # backupDatabases: mydatabase
  # 30 days
  retentionMinutes: 43200
  backupFilePrefix: my-db-backup

persistence:
  enabled: true
  size: 10Gi
  storageClass: my-storage

# cronjob:
#   schedule: 0 * * * *
#   concurrencyPolicy: Forbid
#   failedJobsHistoryLimit: 2
#   successfulJobsHistoryLimit: 1
#   backoffLimit: 2
#   restartPolicy: Never

Maintainers

NameEmailUrl
Wolfgang Jentner[email protected]https://wjentner.io

Requirements

RepositoryNameVersion
oci://registry-1.docker.io/bitnamichartscommon2.x.x

Values

KeyTypeDefaultDescription
affinityobject{}
commonAnnotationsobject{}common annotations to add to all resources
commonLabelsobject{}common labels to add to all resources
config.backupDatabasesstring"--all-databases"the database name to backup or --all-databases if mysqldump is used. Will be ignored for pg_dumpall.
config.backupExecstring"mysqldump"the executable to run for backup. Allowed values are: mysqldump, mariadb-dump, pg_dump, & pg_dumpall.
config.backupFilePrefixstring"db-backup"the prefix for the backup file (will produce: db-backup-2025-02-04T20:00:01+00:00.sql.gz)
config.backupMountPathstring"/backups"the path to store the backup file
config.dbPasswordobject{"secret":{"key":"my-secret-password-key","name":"my-db-secret"}}the database password to use for backup (either direct value or through secret)
config.dbPodstring"my-mariadb-0"the name of the pod running the database (will be used to run backup command)
config.dbUserobject{"value":"root"}the name of the database user to use for backup (either direct value or through secret)
config.dbUser.valuestring"root"the name of the database user to use for backup
config.retentionMinutesint43200the retention time in minutes for backups (default 43200 minutes = 30 days)
cronjob.backoffLimitint2
cronjob.concurrencyPolicystring"Forbid"cronjob concurrency policy
cronjob.failedJobsHistoryLimitint2
cronjob.restartPolicystring"Never"
cronjob.schedulestring"0 * * * *"cronjob schedule in cron format (visit https://crontab.guru/ for help with the syntax). Default is every hour.
cronjob.successfulJobsHistoryLimitint1
fullnameOverridestring""string to fully override db-backup-rentention.fullname
fullnameOverridestring""
image.pullPolicystring"IfNotPresent"
image.repositorystring"ghcr.io/wjentner/k8s-db-backup-retention"
image.tagstring""Overrides the image tag whose default is the chart appVersion.
imagePullSecretslist[]
nameOverridestring""
nameOverridestring""string to partially override db-backup-rentention.fullname
nodeSelectorobject{}
persistence.accessModeslist["ReadWriteOnce"]primary.persistence.accessModes MariaDB primary persistent volume access Modes
persistence.annotationsobject{}primary.persistence.annotations MariaDB primary persistent volume claim annotations
persistence.enabledbooltruepersistence.enabled Enable persistence to store backups using a PersistentVolumeClaim. If false, use emptyDir - for testing only.
persistence.existingClaimstring""persistence.existingClaim Name of an existing PersistentVolumeClaim for NOTE: When it's set the rest of persistence parameters are ignored
persistence.labelsobject{}primary.persistence.labels Labels for the PVC
persistence.selectorobject{}primary.persistence.selector Selector to match an existing Persistent Volume selector: matchLabels: app: my-app
persistence.sizestring"8Gi"primary.persistence.size MariaDB primary persistent volume size
persistence.storageClassstring""persistence.storageClass backups persistent volume storage class If defined, storageClassName: If set to "-", storageClassName: "", which disables dynamic provisioning If undefined (the default) or set to null, no storageClassName spec is set, choosing the default provisioner. (gp2 on AWS, standard on GKE, AWS & OpenStack)
podAnnotationsobject{}
podSecurityContextobject{}
rbac.createbooltrue
rbac.role.annotationsobject{}
rbac.role.namestring""
rbac.roleBinding.annotationsobject{}
rbac.roleBinding.namestring""
resourcesobject{}
securityContextobject{}
serviceAccount.annotationsobject{}Annotations to add to the service account
serviceAccount.createbooltrueSpecifies whether a service account should be created
serviceAccount.namestring""The name of the service account to use. If not set and create is true, a name is generated using the fullname template
tolerationslist[]

Autogenerated from chart metadata using helm-docs v1.14.2

Deploy db-backup-retention with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has db-backup-retention on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartdb-backup-retention is pinned at v1.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply