Configure periodic backups of MariaDB¶
Note
For bare metal and vSphere providers, the MariaDB backup functionality is enabled since Container Cloud 2.27.0 (Cluster release 16.2.0).
After the management cluster deployment, the cluster configuration includes the MariaDB backup functionality. The Kubernetes cron job responsible for the MariaDB backup is enabled by default. For the MariaDB backup workflow, see Mirantis OpenStack for Kubernetes Operations Guide: MariaDB backup workflow.
Warning
For bare metal and vSphere providers, a local volume of only one node of a management cluster is selected when the backup is created for the first time. This volume is used for all subsequent backups.
If the node containing backup data must be redeployed, first move the MySQL backup to another node and update the PVC binding along with the MariaDB backup job to use another node as described in Change the storage node for MariaDB on bare metal and vSphere clusters.
For the OpenStack provider, a backup job is configured to work with
the default csi-sc-cinderplugin
storage class. With this class, a PV
is created as a Cinder volume. This way, it is independent from any of the
management cluster nodes.
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:
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.
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
.
Enable the MariaDB backup in the
Cluster
object:spec: providerSpec: value: kaas: management: helmReleases: ... - name: iam values: keycloak: mariadb: conf: phy_backup: enabled: true
Modify the configuration as required. By default, the backup is set up as follows:
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
PVCThe backup timeout is
21600
secondsThe 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.Modify the following backup parameters that you can pass to the cron job and override from the
Cluster
object:¶ 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
Modify the following environment variables that you can pass to the cron job and override from the
Cluster
object:¶ 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 toincremental
. Otherwise, it is ignored. For example, withfull_backup_cycle
set to604800
seconds, a full backup is performed weekly and, if cron is set to0 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 excludinggalera.cache
andib_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 thanDB_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