Back up and restore
This guide describes how to use the DBBackup Custom Resource to:
Perform a backup of a database
This section describes how you can prepare backups of your database deployed using the Cennso Database Instance.
Important
The backup job runs against a read replica instead of the primary, so the target DBInstance must run at least one read replica, with spec.mysql.size set to 2 or more. If the cluster runs only a single instance, the backup job cannot find a pod to back up and fails with the error: ERROR: No read replica found. Backup can be performed only on a read replica.. For more information, see the Configuration restrictions section.
To deploy a Cennso Database Backup, execute the following steps:
Prepare the Kubernetes secret in the Kubernetes namespace where your MySQL cluster is up and running. This secret should contain the list of environment variables with the data needed for the authorisation at a ResticOpens in a new tab backend. To prepare a secret, create a file, for example
secret.data, with the list of environment variables which you need to authorise at a restic backend. For example:bashNote
To find information about all supported environment variables, see the official documentationOpens in a new tab.
At the next step, encode the contents of the file to
base64:bashCreate a Kubernetes secret file
secret.yamland put the output of the previous command to the data.secret field. For example:yamlApply this secret to the Core Cluster where you want to perform backups using the following command:
bashPrepare the
DBBackupCustom Resource (CR) to deploy the Cennso Database Backup in your Management Cluster. This CR defines the connection to the Core Cluster and the backup job configuration. For example:yamlImportant
The DBBackup resource has restrictions on some configurable values. For more information, see the Configuration restrictions section.
Apply the prepared CR to your Management Cluster:
bashCheck your Core Cluster for the created Kubernetes CronJob to check if backups are configured to run at the specified time:
bash
The example above shows the Custom Resource that creates a Kubernetes CronJob. This CronJob performs a backup of the database deployed in the Core Cluster specified by the {CORE-CLUSTER-NAME} and located in the namespace specified by the {NAMESPACE-WITH-MYSQL-CLUSTER}. It performs a backup each day at 00:00. The {SECRET-NAME} must specify the name of the Kubernetes secret which you created in the previous step.
For more information about available configuration options, see the Cennso Database Backup document.
Restore a database from a backup
If your database or the data was corrupted in a way that you can not continue to run MySQL instances on existing data files, you have to restore the database from a backup.
To restore the database from a backup, you must deploy a new MySQL cluster using the instructions given in the Deploy Cennso Database document or scale the existing cluster to zero instances. To learn how to deploy a new MySQL cluster, read the Installation and Deploy Cennso Database documents. To scale down your existing cluster, you can use the command line or Cennso Management Console:
Important
Be sure you know the node names where the MySQL instances are deployed before you scale down your database cluster. If you are using the Cennso Management Console, you can find the nodes where your MySQL instances are deployed at the Cennso Management → Configurations. Choose the DBInstance related to your MySQL cluster and check the nodes at the specification tab. If you are using the CLI, you can use the following command to get the nodes on the Core Cluster where your MySQL cluster is deployed:
To scale down the MySQL cluster using CMC:
- Go to Cennso Management → Configurations.
- Use filters at the top menu to select the
DBInstancekind. Then, choose theDBInstancerelated to your MySQL cluster. - Press the
Editbutton and switch to the Specification tab. - Set the value of the MySQL cluster size to
0.
To scale down the MySQL cluster using CLI, set the spec.mysql.size value to 0 in the PerconaServerMySQL related to your database cluster and wait until all MySQL instances are terminated. To find the needed PerconaServerMySQL resource, use the following command:
After this, follow the next steps to restore your database from a backup:
Go to nodes where the MySQL cluster is deployed and remove the broken MySQL datadirOpens in a new tab:
bashGo to the node where the primary MySQL instance is intended to run after restoring the backup. Find the snapshot ID in Restic from which you want to restore and fetch it to the node:
bashRestore the backup using the
xtrabackupOpens in a new tab command:bashNote
If you set the
--compressoption in the spec.xtradbExtraArgs of theDBBackupCustom Resource, you should decompress the backup before restoring from it. To do that, use the following commands:bashDelete the directory with the backup:
bashFrom now on, you can scale your MySQL cluster to the desired number of instances again. To do this, you can use the Cennso Management Console or the CLI. Repeat step 1 above to set the number of MySQL instances as expected.
Important
In addition, it is highly recommended to enable MySQL CLONEOpens in a new tab and disable binary-donor after you restore the backup.
To enable
CLONEoperations, you can set the CLONE_REQUIRED_ON_ASYNC_CLUSTER environment variable totruein thePerconaServerMySQLresource related to your MySQL cluster. To disablebinary-donor, scale its deployments to0.After the database cluster is up and running and the
CLONEoperation finishes, you can set the value of the CLONE_REQUIRED_ON_ASYNC_CLUSTER back tofalseand enablebinary-donoragain. After restarting the MySQL instances, you should have a ready MySQL cluster with restored data.For more information on how to validate your MySQL cluster, see the Validate the MySQL cluster document.