Restoring Database from Physical Backup

Last updated: 2021-07-06 19:51:03



    To save storage capacity, physical and logical backups in TencentDB for MySQL will be compressed with qpress and then packed with xbstream offered by Percona.

    The open-source Percona XtraBackup can be used to back up and restore databases. This document describes how to use XtraBackup to restore a physical backup file of TencentDB for MySQL instance to a self-built database on CVM.


    • Download and install XtraBackup.
      XtraBackup can be downloaded at Percona's official website. Please select Percona XtraBackup v2.4.6 or later. For more information on installation, please see Percona XtraBackup 2.4.
    • Supported instance architectures: two-node or three-node MySQL
    • Instances with data encryption enabled cannot be restored from a physical backup.



    This document takes a CVM instance running CentOS and a MySQL v5.7 instance as an example.

    Step 1. Download the backup file

    You can download data backups and log backups of TencentDB for MySQL instances in the console.


    Each IP can have up to 10 download links by default, with a download speed limit of 20–30 Mbps each.

    1. Log in to the TencentDB for MySQL console. In the instance list, click the instance ID or Manage in the Operation column to access the instance management page.
    2. On the Backup and Restore > Data Backup List tab, locate the backup file to be downloaded and click Download in the Operation column.
    3. We recommend you copy the download link in the pop-up dialog box, log in to a (Linux) CVM instance in the same VPC as the TencentDB instance, and run the wget command for download over the private network at a higher speed.

      • You can also click Download to download it directly, which may take longer.
      • wget command format: wget -c 'backup file download address' -O custom filename.xb
      wget -c '' -O ~/test.xb

    Step 2. Restore data

    2.1 Unpack the backup file

    Run the xbstream command to unpack the backup file to the target directory.

    xbstream -x -C /data < ~/test.xb

    • /data is used as an example in this document. You can replace it with a real path according to the actual situation.
    • Replace ~/test.xb with your backup file.

    The unpacking result is as shown below:

    2.2 Decompress the backup file

    1. Download qpress by running the following command:

      If an error is displayed during the wget download, you can go to QuickLZ's official website to download qpress locally and upload it to the Linux CVM instance. For more information, please see Uploading Files via SCP to a Linux CVM from Linux.

    2. Extract the qpress binary files by running the following command.
      tar -xf qpress-11-linux-x64.tar -C /usr/local/bin
      source /etc/profile
    3. Decompress all .qp files in the destination directory by running the following qpress command:
      xtrabackup --decompress --target-dir=/data

      • /data is the target directory where the backup file was previously stored. You can replace it with a real path according to the actual situation.
      • The --remove-original option is supported only in Percona Xtrabackup v2.4.6 and later.
      • xtrabackup won't delete the original files during decompression by default. If you want to delete them upon the completion of decompression, add the --remove-original parameter to the above command.

    2.3 Prepare the backup file

    After a backup file is decompressed, you need to execute the "apply log" operation by running the following command.

    xtrabackup --prepare  --target-dir=/data

    If the execution result contains the following output, it means that the preparation succeeded.

    2.4 Modify the configuration file

    1. Run the following command to open the backup-my.cnf file.
      vi /data/backup-my.cnf

      The target directory /data is used as an example in this document. You can replace it with a real path according to the actual situation.

    2. Given the existing version issues, the following parameters need to be commented out from 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

    2.5 Modify file attributes

    Modify file attributes and check whether files are owned by the mysql user.

    chown -R mysql:mysql /data

    Step 3. Start the mysqld process and log in for verification

    1. Start the mysqld process.
      mysqld_safe --defaults-file=/data/backup-my.cnf --user=mysql --datadir=/data &
    2. Log in to the client for verification.
      mysql  -uroot

    Backup FAQs

    See Common Issues and Failure Reasons.