Configure periodic backups of MariaDB for AWS and OpenStack providers

After the management cluster deployment, the cluster configuration includes the MariaDB backup functionality for the AWS and OpenStack cloud providers. The Kubernetes cron job responsible for the MariaDB backup is enabled by default. For the MariaDB backup workflow, see MOS Operations Guide: MariaDB backup workflow.

Note

For other supported Container Cloud providers, the MariaDB backup functionality is disabled and will be enabled in one of the following releases.

To manually create a MariaDB database backup, run:

kubectl -n kaas create job --from=cronjob/mariadb-phy-backup mariadb-phy-backup-manual-001

To modify the default backup configuration for MariaDB:

  1. Select from the following options:

    • If the management cluster is not bootstrapped yet, proceed to the next step.

    • If the management cluster is already deployed, verify that the mariadb-phy-backup CronJob object is present:

      kubectl -n kaas get cronjob mariadb-phy-backup
      

      Example of a positive system response:

      NAME                 SCHEDULE    SUSPEND   ACTIVE   LAST SCHEDULE   AGE
      mariadb-phy-backup   0 0 * * *   False     0        6h3m            10d
      

      If the object is missing, make sure that your management cluster is successfully upgraded to the latest version.

  2. Select from the following options:

    • If the management cluster is not bootstrapped yet, modify cluster.yaml.template using the steps below.

    • If the management cluster is already deployed, modify the configuration kubectl edit <mgmtClusterName> using the steps below. By default, the management cluster name is kaas-mgmt.

  3. Enable the MariaDB backup in the Cluster object:

    spec:
      providerSpec:
        value:
          kaas:
            management:
              helmReleases:
              ...
              - name: iam
                values:
                  keycloak:
                    mariadb:
                      conf:
                        phy_backup:
                          enabled: true
    
  4. Modify the configuration as required. By default, the backup is set up as follows for the OpenStack and AWS providers:

    • Runs on a daily basis at 00:00 AM

    • Creates full backups daily

    • Keeps 5 latest full backups

    • Saves backups to the mariadb-phy-backup-data PVC

    • The backup timeout is 21600 seconds

    • The backup type is full

    The mariadb-phy-backup cron job launches backups of the MariaDB Galera cluster. The job accepts settings through parameters and environment variables.

  5. Modify the following backup parameters that you can pass to the cron job and override from the Cluster object:

    MariaDB backup: Configuration parameters

    Parameter

    Default

    Description

    --backup-type (string)

    full

    Backup type. The list of possible values include:

    • incremental

      If the newest full backup is older than the value of the full_backup_cycle parameter, the system performs a full backup. Otherwise, the system performs an incremental backup of the newest full backup.

    • full

      Always performs only a full backup.

    Usage example:

    spec:
      providerSpec:
        value:
          kaas:
            management:
              helmReleases:
              - name: iam
                values:
                  keycloak:
                    mariadb:
                      conf:
                        phy_backup:
                          backup_type: incremental
    

    --backup-timeout (integer)

    21600

    Timeout in seconds for the system to wait for the backup operation to succeed.

    Usage example:

    spec:
      providerSpec:
        value:
          kaas:
            management:
              helmReleases:
              - name: iam
                values:
                  keycloak:
                    mariadb:
                      conf:
                        phy_backup:
                          backup_timeout: 30000
    

    --allow-unsafe-backup (boolean)

    false

    If set to true, enables the MariaDB cluster backup on a not fully operational cluster where:

    • The current number of ready pods is not equal to MARIADB_REPLICAS

    • Some replicas do not have healthy wsrep statuses

    Usage example:

    spec:
      providerSpec:
        value:
          kaas:
            management:
              helmReleases:
              - name: iam
                values:
                  keycloak:
                    mariadb:
                      conf:
                        phy_backup:
                          allow_unsafe_backup: true
    
  6. Modify the following environment variables that you can pass to the cron job and override from the Cluster object:

    MariaDB backup: Environment variables

    Variable

    Default

    Description

    MARIADB_BACKUPS_TO_KEEP (integer)

    10

    Number of full backups to keep.

    Usage example:

    spec:
      providerSpec:
        value:
          kaas:
            management:
              helmReleases:
              - name: iam
                values:
                  keycloak:
                    mariadb:
                      conf:
                        phy_backup:
                          backups_to_keep: 3
    

    MARIADB_BACKUP_PVC_NAME (string)

    mariadb-phy-backup-data

    Persistent volume claim used to store backups.

    Usage example:

    spec:
      providerSpec:
        value:
          kaas:
            management:
              helmReleases:
              - name: iam
                values:
                  keycloak:
                    mariadb:
                      conf:
                        phy_backup:
                          backup_pvc_name: mariadb-phy-backup-data
    

    MARIADB_FULL_BACKUP_CYCLE (integer)

    604800

    Number of seconds that defines a period between 2 full backups. During this period, incremental backups are performed. The parameter is taken into account only if backup_type is set to incremental. Otherwise, it is ignored. For example, with full_backup_cycle set to 604800 seconds, a full backup is performed weekly and, if cron is set to 0 0 * * *, an incremental backup is performed daily.

    Usage example:

    spec:
      providerSpec:
        value:
          kaas:
            management:
              helmReleases:
              - name: iam
                values:
                  keycloak:
                    mariadb:
                      conf:
                        phy_backup:
                          full_backup_cycle: 70000
    

    MARIADB_BACKUP_REQUIRED_SPACE_RATIO (floating)

    1.2

    Multiplier for the database size to predict the space required to create a backup, either full or incremental, and perform a restoration keeping the uncompressed backup files on the same file system as the compressed ones.

    To estimate the size of MARIADB_BACKUP_REQUIRED_SPACE_RATIO, use the following formula: size of (1 uncompressed full backup + all related incremental uncompressed backups + 1 full compressed backup) in KB =< (DB_SIZE * MARIADB_BACKUP_REQUIRED_SPACE_RATIO) in KB.

    The DB_SIZE is the disk space allocated in the MySQL data directory, which is /var/lib/mysql, for databases data excluding galera.cache and ib_logfile* files. This parameter prevents the backup PVC from being full in the middle of the restoration and backup procedures. If the current available space is lower than DB_SIZE * MARIADB_BACKUP_REQUIRED_SPACE_RATIO, the backup script fails before the system starts the actual backup and the overall status of the backup job is failed.

    Usage example:

    spec:
      providerSpec:
        value:
          kaas:
            management:
              helmReleases:
              - name: iam
                values:
                  keycloak:
                    mariadb:
                      conf:
                        phy_backup:
                          backup_required_space_ratio: 1.4
    

Configuration example:

To perform full backups monthly and incremental backups daily at 02:30 AM and keep the backups for the last six months, configure the database backup in your Cluster object as follows:

spec:
  providerSpec:
    value:
      kaas:
        management:
          helmReleases:
          - name: iam
            values:
              keycloak:
                mariadb:
                  conf:
                    phy_backup:
                      enabled: true
                      backups_to_keep: 6
                      schedule_time: '30 2 * * *'
                      full_backup_cycle: 2628000