Percona XtraBackup (PXB) version 8.0.28 supports taking backups for the encrypted tables in your MySQL database using the AWS Key Management Service. For setting up data-at-rest encryption using AWS key management service, please see Configuring Keyring for Encryption Using AWS Key Management Service in Percona Server for MySQL.

In this blog post, we will discuss how the backup and restore would work if you have an encrypted table using this keyring component.

Do we need to take any additional care with Percona XtraBackup?

It is mentioned in the Percona XtraBackup documentation that the backup does not need any additional configuration for backing up the encrypted data using the component_keyring_kms component, as PXB reads the necessary keys from MySQL.

I have enabled the component keyring KMS on my Percona Server for MySQL and also encrypted one of the tables (test.t1).

Let’s try to take a backup and see the logs. I am using a very basic command to PXB to keep it simple; however, you might have various other parameters as per the requirement,

The very important note in the logs is to make sure the PXB has initialized the component, and the backup was completed.

For preparing the backup

Here is the list of files in PXB that was taken along with the component keyring KMS installed in MySQL:

Notice that there is no information about the component keyring in the backup files.

Let’s try to prepare the backup as it is and with a simple command,

I see the below errors in the prepare logs,

When you start preparing a backup, it should load the keyring first. However, since the keyring did not load, it did not log whether the keying was loaded. That is what the error says while PXB reads table t1 to prepare and make sure the keyring is loaded.

The proper way to prepare the backup

You need two things:

  1. Local keyring file that is created when the component loads.
  2. Component keyring kms config file that you used for the encryption.

Copy the component_keyring_kms.cnf file in the backup directory. This file should be either in the local config or global config location as you configured. Take a look here at how the configuration is done for this component. 

Here is what the config file looks like. I have hidden my access keys to AWS.

My local keyring file, as per the configuration, is at this path /usr/local/mysql/keyring-mysql/aws-keyring-data

I will copy that file at the same path where I am preparing the backup, or if you are preparing it on the same host, you can use the same file as well and just copy the config file to the backup directory.

PXB tries to see if there is any component config file to initialize and then initializes it accordingly before preparing the backup. It needs both keys, the local keyring data file as well as the AWS key from KMS. Both of them are equally important. If you lose either, the backup is non-recoverable.

My backup directory has the config file now:

Also, the local keyring file at its defined location in the config file:

Let’s try to prepare the backup again and monitor the logs.

The important thing to note in the logs:

Once the component is loaded in the prepare stage, it should be able to decrypt any encrypted tables and prepare the backup successfully.

Then you can do a copy-back with PXB and start the MySQL service.

Suppose you are restoring this backup on the new instance. In that case, you need to make sure to initialize the component with the same keyring data file and the same component keyring KMS configuration to be able to read the encrypted tables.

Otherwise, the keyring will not load and you won’t be able to see the data on the new instance.

Even if you are restoring on the same instance, it is essential to configure the instance with the same keyring and config file.

Conclusion

Even though the backup does not need any extra parameters to take backup for encrypted data, the preparation stage needs a few additional steps.

The important thing to note is that the PXB won’t backup the local key and the config file for the component. You need to back it up and keep it safe.

Percona XtraBackup is a free, open source, complete online backup solution for all versions of Percona Server for MySQL and MySQL. It performs online non-blocking, tightly compressed, highly secure backups on transactional systems so that applications remain fully available during planned maintenance windows.

 

Download Percona XtraBackup

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments