Percona XtraBackup has implemented support for encrypted backups. It can be used to encrypt/decrypt local or streaming backup with xbstream option (streaming tar backups are not supported) in order to add another layer of protection to the backups. Encryption is done with the libgcrypt library.
Encryption related options are currently ignored by innobackupex when specified in my.cnf.
Creating Encrypted Backups¶
- --encryption=ALGORITHM - currently supported algorithms are: AES128, AES192 and AES256
- --encrypt-key=ENCRYPTION_KEY - proper length encryption key to use. It is not recommended to use this option where there is uncontrolled access to the machine as the command line and thus the key can be viewed as part of the process info.
- --encrypt-key-file=KEYFILE - the name of a file where the raw key of the appropriate length can be read from. The file must be a simple binary (or text) file that contains exactly the key to be used.
$ openssl rand -base64 24
Example output of that command should look like this:
This value then can be used as the encryption key
Using the --encrypt-key option¶
Example of the innobackupex command using the --encrypt-key should look like this
$ innobackupex --encrypt=AES256 --encrypt-key="GCHFLrDFVx6UAsRb88uLVbAVWbK+Yzfs" /data/backups
Using the --encrypt-key-file option¶
Example of the innobackupex command using the --encrypt-key-file should look like this
$ innobackupex --encrypt=AES256 --encrypt-key-file=/data/backups/keyfile /data/backups
Depending on the text editor used for making the KEYFILE, text file in some cases can contain the CRLF and this will cause the key size to grow and thus making it invalid. Suggested way to do this would be to create the file with: echo -n "GCHFLrDFVx6UAsRb88uLVbAVWbK+Yzfs" > /data/backups/keyfile
Both of these examples will create a timestamped directory in /data/backups containing the encrypted backup.
You can use the innobackupex --no-timestamp option to override this behavior and the backup will be created in the given directory.
Optimizing the encryption process¶
Two new options have been introduced with the encrypted backups that can be used to speed up the encryption process. These are --encrypt-threads and --encrypt-chunk-size. By using the --encrypt-threads option multiple threads can be specified to be used for encryption in parallel. Option --encrypt-chunk-size can be used to specify the size (in bytes) of the working encryption buffer for each encryption thread (default is 64K).
Decrypting Encrypted Backups¶
Backups can be decrypted with The xbcrypt binary. Following one-liner can be used to encrypt the whole folder:
$ for i in `find . -iname "*\.xbcrypt"`; do xbcrypt -d --encrypt-key-file=/root/secret_key --encrypt-algo=AES256 < $i > $(dirname $i)/$(basename $i .xbcrypt) && rm $i; done
Percona XtraBackup innobackupex --decrypt option has been implemented that can be used to decrypt the backups:
$ innobackupex --decrypt=AES256 --encrypt-key="GCHFLrDFVx6UAsRb88uLVbAVWbK+Yzfs" /data/backups/2015-03-18_08-31-35/
Prior to Percona XtraBackup 2.2.10 innobackupex --decrypt would remove the original encrypted files and leave the results in the same location. After version 2.2.10 Percona XtraBackup doesn’t automatically remove the encrypted files. In order to clean up the backup directory users should remove the *.xbcrypt files.
When the files have been decrypted backup can be prepared.
Preparing Encrypted Backups¶
After the backups have been decrypted, they can be prepared the same way as the standard full backups with the --apply-logs option:
$ innobackupex --apply-log /data/backups/2015-03-18_08-31-35/
After version 2.2.10 Percona XtraBackup doesn’t automatically remove the encrypted files. In order to clean up the backup directory users should remove the *.xbcrypt files.
Restoring Encrypted Backups¶
innobackupex has a --copy-back option, which performs the restoration of a backup to the server’s datadir
$ innobackupex --copy-back /path/to/BACKUP-DIR
It will copy all the data-related files back to the server’s datadir, determined by the server’s my.cnf configuration file. You should check the last line of the output for a success message:
innobackupex: Finished copying back files. 150318 11:08:13 innobackupex: completed OK!