Skip to main content
Version: 3.0.0-alpha (Diátaxis)

How to configure automatic backups

This guide explains how to enable and configure automatic backups for your MySQL database on Hikube. Backups use Restic and are stored in an S3-compatible bucket, enabling reliable restoration in case of data loss.

Prerequisites

  • kubectl configured with your Hikube kubeconfig
  • A MySQL instance deployed on your tenant
  • An accessible S3-compatible bucket (Hikube Object Storage, AWS S3, etc.)
  • S3 access credentials (Access Key and Secret Key)

Steps

1. Prepare S3 storage and credentials

Before configuring backups, make sure you have the following information:

InformationExampleDescription
S3 Regioneu-central-1S3 bucket region
S3 Buckets3.hikube.cloud/mysql-backupsFull bucket path
Access KeyHIKUBE123ACCESSKEYS3 access key
Secret KeyHIKUBE456SECRETKEYS3 secret key
Restic passwordSuperStrongResticPassword!Password for backup encryption
warning

Keep the Restic password in a safe place. Without this password, it is impossible to restore encrypted backups.

2. Configure the backup section in the manifest

Create or modify your MySQL manifest to include the backup section:

mysql-with-backup.yaml
apiVersion: apps.cozystack.io/v1alpha1
kind: MariaDB
metadata:
name: example
spec:
replicas: 3
size: 10Gi
resourcesPreset: small

users:
appuser:
password: strongpassword
maxUserConnections: 100

databases:
myapp:
roles:
admin:
- appuser

backup:
enabled: true
schedule: "0 2 * * *" # Tous les jours à 2h du matin
cleanupStrategy: "--keep-last=3 --keep-daily=3 --keep-within-weekly=1m"
s3Region: eu-central-1
s3Bucket: s3.hikube.cloud/mysql-backups
s3AccessKey: "HIKUBE123ACCESSKEY"
s3SecretKey: "HIKUBE456SECRETKEY"
resticPassword: "SuperStrongResticPassword!"

Backup parameters

ParameterDescriptionDefault value
backup.enabledEnable backupsfalse
backup.scheduleCron schedule"0 2 * * *"
backup.s3RegionAWS S3 region"us-east-1"
backup.s3BucketS3 bucket-
backup.s3AccessKeyS3 access key-
backup.s3SecretKeyS3 secret key-
backup.resticPasswordRestic password-
backup.cleanupStrategyRetention strategy"--keep-last=3 --keep-daily=3 --keep-within-weekly=1m"
tip

Adapt the schedule to your needs. Some common examples:

  • "0 2 * * *": every day at 2 AM
  • "0 */6 * * *": every 6 hours
  • "0 3 * * 0": every Sunday at 3 AM

3. Apply the configuration

kubectl apply -f mysql-with-backup.yaml

4. Adapt the retention strategy

The cleanupStrategy uses Restic retention options. Here are some examples:

StrategyDescription
--keep-last=3Keep the last 3 snapshots
--keep-daily=7Keep 1 snapshot per day for 7 days
--keep-weekly=4Keep 1 snapshot per week for 4 weeks
--keep-within-weekly=1mKeep all weekly snapshots from the last month

Example for a production environment:

mysql-production-backup.yaml
apiVersion: apps.cozystack.io/v1alpha1
kind: MariaDB
metadata:
name: production
spec:
replicas: 3
resourcesPreset: medium
size: 50Gi

backup:
enabled: true
schedule: "0 */6 * * *"
cleanupStrategy: "--keep-last=7 --keep-daily=7 --keep-weekly=4"
s3Region: eu-central-1
s3Bucket: s3.hikube.cloud/mysql-backups
s3AccessKey: "PROD_ACCESS_KEY"
s3SecretKey: "PROD_SECRET_KEY"
resticPassword: "ProdResticPassword!"

Verification

Verify that the configuration has been applied correctly:

kubectl get mariadb example -o yaml | grep -A 10 backup

Expected output:

  backup:
enabled: true
schedule: "0 2 * * *"
s3Region: eu-central-1
s3Bucket: s3.hikube.cloud/mysql-backups
cleanupStrategy: "--keep-last=3 --keep-daily=3 --keep-within-weekly=1m"
note

The first backup will be executed according to the cron schedule defined in schedule. You can check available snapshots with the Restic command (see the guide How to restore a backup).

Going further