Scenarios
Note:
To save storage space, physical and logical backup files of TencentDB for MySQL are first compressed by qpress and then packaged by xbstream (xbstream is a packaging/unpackaging tool from Percona) for compression and packaging.
The open-source software Percona XtraBackup can be used for database backup and recovery. This document describes how to use the Percona XtraBackup tool to restore a MySQL physical backup file to a self-built database on another host.
Note:
If you use the Transparent Data Encryption or Instant DDL feature, you cannot restore data on a self-built system by using a physical backup.
Percona XtraBackup supports only the Linux platform and does not support the Windows platform.
Prerequisites
Download and install the Percona XtraBackup tool.
Note:
Ensure that the version of the tool you download matches the version of your database. For example, if your instance database version is MySQL 8.0.30, download the Percona XtraBackup tool version 8.0.30 accordingly. Click Download Address to navigate to the page for checking versions and downloading the tool. For installation instructions, see Percona XtraBackup Guide. Supported instance editions: MySQL Two-Node and Three-Node.
Note:
This document demonstrates the procedure using a CVM with the CentOS operating system and MySQL version 5.7 as examples.
You can download data backups and log backups for TencentDB for MySQL from the console.
Note:
By default, each IP address is limited to 10 connections, and the download speed per link can reach 20 Mbps - 30 Mbps.
1. Log in to the TencentDB for MySQL console. In the instance list, click the instance ID or click Manage in the Operation column to go to the instance management page. 2. On the instance management page, choose Backup and Restoration > Data Backup List, select the backup you need to download, and click Download in the Operation column.
3. In the pop-up dialog box, click Copy after the download address to obtain the download link.
4. Log in to the Linux CVM where your self-built MySQL resides, and use the wget command to download the physical backup at high speed over the private network.
Note:
Every download address is valid for 12 hours. If it expires, please refresh the page to obtain a new one.
The wget command format is: wget -c 'backup-file-download-address' -O custom-filename.xb.
Example:
wget -c 'https://mysql-database-backup-sh-1218.cos.ap-nanjing.myqcloud.com/12427%2Fmysql%2F0674-ffba-11e9-b592-70bd%2Fdata%2Fautomatic-delete%2F2019-12-03%2Fautomatic%2Fxtrabackup%2Fbk_61_156758150%2Fcdb-293fl9ya_backup_20191203000202.xb?sign=q-sign-algorithm%3Dsha1%26q-ak%3DAKzxfbLJ1%26q-sign-time%3D1575374119%3B1575417319%26q-key-time%3D1575374119%3B1575417319%26q-header-list%3D%26q-url-param-list%3D%26q-signature%3Dba959757&response-content-disposition=attachment%3Bfilename%3D%22yuan177685_backup_20191203000202.xb%22&response-content-type=application%2Foctet-stream' -O /data/test.xb
Step 2: Downloading the Backup Decryption Key (Required only if the backup encryption feature is enabled)
You can download the data backup decryption key for TencentDB for MySQL from the console.
Note:
A decryption key is independently generated for each database backup. If you have enabled the backup encryption feature, you must download and retain the decryption key along with the backup file.
1. Log in to the TencentDB for MySQL console. In the instance list, click the instance ID or click Manage in the Operation column to go to the instance management page. 2. On the instance management page, choose Backup and Restoration > Data Backup List, select the decryption key corresponding to the backup you need to download, and click Download Key in the Operation column.
Note:
3.1 Unpacking the Backup File
Use the xbstream command to unpack the data backup file to the target directory.
xbstream -x --decrypt=AES256 --encrypt-key-file=<backup-key-file> --parallel=2 -C /data/mysql < /data/test.xb
Note:
When backup encryption is not enabled, the command to unpack the backup file is: xbstream -x -C /data/mysql < /data/test.xb.
This document uses /data/mysql as the target directory for data file recovery storage. You can replace it with your actual path based on your specific requirements.
Replace /data/test.xb with your backup file.
The unpacking result is shown in the following figure:
If the backup file to be unpacked is a binlog backup, use the following command.
openssl enc -d -aes256 -k <encrypt_key> -in <download_binlog_name> -out <output_binlog_name>;
<encrypt_key>: Replace it with the actual backup key file content.
<download_binlog_name>: Replace it with the actual encrypted binlog file name.
<output_binlog_name>: Replace it with the actual decrypted binlog file name.
3.2 Extracting the Backup File
1. Download the qpress tool using the following command.
wget -d --user-agent="Mozilla/5.0 (Windows NT x.y; rv:10.0) Gecko/20100101 Firefox/10.0" https://docs-tencentdb-1256569818.cos.ap-guangzhou.myqcloud.com/qpress-11-linux-x64.tar
2. Extract the qpress binary file using the following command.
tar -xf qpress-11-linux-x64.tar -C /usr/local/bin
source /etc/profile
3. Use the following command to extract all files ending with .qp in the target directory.
xtrabackup --decompress --target-dir=/data/mysql
Note:
/data/mysql is the target directory where backup files were previously stored. You can replace it with your actual path based on your specific requirements.
Percona XtraBackup supports the --remove-original option only in version 2.4.6 and later.
xtrabackup does not delete the original compressed files by default during decompression. To delete the original compressed files after decompression, add the --remove-original parameter to the command above.
3.3 Preparing the Backup File
After the backup is decompressed, run the following command to apply the log.
xtrabackup --prepare --target-dir=/data/mysql
If the result contains the following output after execution, it indicates that the prepare operation was successful.
3.4 Modifying the Configuration File
1. Run the following command to open the backup-my.cnf file.
vi /data/mysql/backup-my.cnf
Note:
This document uses the target directory /data/mysql as an example. You can replace it with your actual path based on your specific requirements.
2. Due to version compatibility issues, comment out the following parameters in the extracted file backup-my.cnf.
innodb_checksum_algorithm
innodb_log_checksum_algorithm
innodb_fast_checksum
innodb_page_size
innodb_log_block_size
redo_log_version
server_uuid
master_key_id
3.5 Modifying File Attributes
Modify the file attributes and verify that the file is owned by the mysql user.
chown -R mysql:mysql /data/mysql
Step 4: Starting the mysqld Process and Logging In for Verification
1. Start the mysqld process.
mysqld_safe --defaults-file=/data/mysql/backup-my.cnf --user=mysql --datadir=/data/mysql &
2. Log in to mysql using a client to verify the connection.
Note:
After you run the command, you need to enter the password for the root account of the cloud database restored from the backup file.
Backup Related FAQs