Use Percona XtraBackup to restore a physical backup from ApsaraDB RDS for MySQL to a self-managed MySQL database.
Background
ApsaraDB RDS for MySQL supports restoring instance backups to a self-managed database. You can use various data restoration methods, such as restoring from a physical backup or a logical backup. For more information about selecting a data restoration method, see MySQL data restoration methods.
You can view the backup type of an instance in the ApsaraDB RDS console. In the left-side navigation pane, go to Backup and Restoration > Base Backups > Data Backup.
If no physical backups exist, you must first create a manual backup. For instructions, see Manual backup.
Scenarios
You can restore a physical backup from your RDS for MySQL instance to a self-managed database if you no longer need the instance for an extended period, or if it has been released but you still have its physical backup file.
Prerequisites
Your RDS MySQL instance must meet the following requirements:
Major version: 8.0, 5.7, 5.6, or 5.5
Edition: High-availability Edition
Storage type: Premium Local SSDs
NoteYou can view this information on the Basic Information page of your instance.
You can download physical backup files only for instances that meet the preceding requirements. If your instance is a Basic Edition instance, see the FAQ in this topic.
The tables in your RDS instance must not be encrypted with TDE.
ImportantEncrypted tables can cause restoration errors. Perform a decryption operation first.
You can check the TDE status on the Data Security > TDE page of the instance in the RDS console.
Your RAM user must have permission to download backup files. For instructions, see Authorize a RAM user with read-only permissions to download backup files.
Limitations
Restoring physical backup files is supported only for instances that use local disks. To restore a snapshot backup for an instance that uses a cloud disk, see Restore the data of an ApsaraDB RDS for MySQL instance to a self-managed MySQL instance by using snapshot backup files.
This process restores all data from the backup file. To restore only specific databases or tables, see Restore an RDS MySQL logical backup to a self-managed database.
Currently, physical backup files from RDS for MySQL can only be restored to a self-managed database on Linux.
Data restoration for MySQL Group Replication (MGR) clusters is not currently supported.
Impacts
If you restore an RDS MySQL physical backup to a self-managed database that also runs other services, those services will become unavailable.
This restoration method restores data to a new database's data directory, leaving the original data on your self-managed database unaffected.
How it works
Restoring a physical backup involves the following steps:
Perform a full physical backup of the database.
Download the physical backup file to a local device and decompress it with the
qpresstool.Use
Percona XtraBackupto restore the decompressed backup files to the data directory of your self-managed database.Restart the database. You can then view the original RDS MySQL data in your self-managed database.
Notes
A backup download URL is valid for one hour. If the URL expires, refresh the page to get a new one.
Do not modify or delete the contents of the backup file. Otherwise, the file may become corrupted and unrestorable. If you need to modify the data, first restore the backup to a self-managed database.
Billing
If you create manual backups, monitor your backup storage usage. Backup storage exceeding the free quota incurs backup fees.
If your self-managed database is on-premises, you will download backup data over the Internet. You will incur Internet traffic fees if your download traffic exceeds the free quota.
NoteIf your self-managed database is on an ECS instance in the same region and VPC as the RDS instance, downloading backup data via an internal address incurs no traffic fees.
Before you begin
Environment setup
Tools
Step 1: Download the backup file
Navigate to the RDS instance list, select a region, and then click the ID of the target instance.
In the left-side navigation pane, click Backup and Restoration.
On the Base Backups > Data backup tab, find the target physical backup and click Download instance backup in the Actions column.
If no physical backup file is available, you can create a manual backup. For more information, see Perform a manual backup.
If you are redirected to the Advanced Download page, your RDS instance is a cloud disk instance. To restore data, see Restore data from a snapshot backup file of an ApsaraDB RDS for MySQL instance to a self-managed database.
In the Download instance backup dialog box, copy the internal URL or public URL as needed.
ImportantIf you use an internal URL, you can download the backup file only from a server in the same region and VPC. You cannot download the file from a server in a different region or in the classic network.
If you use a public URL to download the backup file, you are charged for internet traffic that exceeds the free quota. For more information, see Billing details.
The backup download URL is valid for one hour. If it expires, refresh the page to obtain the latest URL.
Do not modify or delete the content of the backup file. Otherwise, the file may become damaged and unrestorable. If you need to make modifications, restore the data to your self-managed database first.
Log on to the Linux server that hosts your self-managed MySQL database and run the following command to download the physical backup.
wget -c 'https://****.bak.rds.aliyuncs.com/****_xb.qp?****' -O test_xb.qpNotePlease replace
https://****.bak.rds.aliyuncs.com/****_xb.qp?****in the command above with the actual backup download address. After you download the backup file, save it promptly to prevent data leaks.In this example,
test_xb.qpis used as the filename. You can specify a custom filename, but the file extension must match the extension in the download URL.Currently, download URLs for RDS for MySQL backups use one of two file extension formats:
_xb.qpor_qp.xb. You can check the download link to see which format your backup file uses.The physical backup format of RDS for MySQL 5.5 is
tar.gz.
Download FAQ
Step 2: Decompress the backup file
Choose a command to decompress the backup package based on its file name extension.
Refer to the Prerequisites section to install Percona XtraBackup and qpress, and then run the following commands.
Decompression FAQ
Step 3: Restore data
Before restoring the database, stop your self-managed database service.
You can use the ps -ef | grep '[m]ysql' command to check for mysql processes and use the sudo kill -9 <PID> command to terminate the process.
MySQL 8.0
Prepare for restoration.
/u01/xtrabackup80/bin/xtrabackup --defaults-file=/var/mysql_bkdata/backup-my.cnf --prepare --target-dir=/var/mysql_bkdata/Parameters:
Parameter
Description
--defaults-file
Sets default MySQL options from a configuration file.
An RDS MySQL backup file contains a configuration file named
backup-my.cnf. This file is located in the backup decompression directory at/var/mysql_bkdata/.--prepare
The prepare command for the XtraBackup tool.
--target-dir
Backup decompression directory
/var/mysql_bkdata/.Modify the data directory (datadir) of your self-managed database.
Edit the database configuration file.
sudo vim /etc/my.cnfTo find the path of the database configuration file, see Prerequisites.
Press the
ikey to enter edit mode, and set the datadir parameter to/var/mysql_newdata.datadir = /var/mysql_newdatamysql_newdatais the new data directory for the self-managed database, which you created in the Prerequisites section.Grant permissions on the new data directory.
chown -R mysql:mysql /var/mysql_newdataPress the
Esckey to exit edit mode, and enter:wq!to save and exit.
Restore the data.
sudo xtrabackup --defaults-file=/etc/my.cnf --copy-back --target-dir=/var/mysql_bkdata/Parameters:
Parameter
Description
--defaults-file
Obtain the target path for data restoration from the data directory (datadir) setting in the
my.cnffile of the self-managed database.--copy-back
The restore command for the XtraBackup tool.
--target-dir
The XtraBackup tool restores the data from the backup decompression directory,
/var/mysql_bkdata/, to the data directory of the self-managed database.
MySQL 5.7
Prepare for restoration.
innobackupex --defaults-file=/var/mysql_bkdata/backup-my.cnf --apply-log /var/mysql_bkdata/Parameters:
Parameter
Description
--defaults-file
Sets default MySQL options from a configuration file.
An RDS MySQL backup file contains a configuration file named
backup-my.cnflocated in the backup decompression directory:/var/mysql_bkdata/.--apply-log
The prepare command for the XtraBackup tool.
The command is followed by the directory for storing backup files, that is, the backup decompression directory
/var/mysql_bkdata/.Modify the self-managed database configuration file
my.cnf.Edit the database configuration file.
sudo vim /etc/my.cnfTo find the path of the database configuration file, see Prerequisites.
Press the
ikey to enter edit mode and change the datadir parameter to/var/mysql_newdata.datadir = /var/mysql_newdatamysql_newdatais the new data directory for the self-managed database, which was created in the Preparations section.Add the following content to
my.cnf.innodb_undo_tablespaces=2 innodb_undo_directory=/var/mysql_newdataImportantThe value of the innodb_undo_tablespaces parameter must match the value in
/var/mysql_bkdata/backup-my.cnf. You can run thecat /var/mysql_bkdata/backup-my.cnf | grep innodb_undo_tablespacescommand to query the value.Press the
Esckey to exit edit mode, and enter:wq!to save and exit.
Restore the data.
sudo innobackupex --defaults-file=/etc/my.cnf --copy-back /var/mysql_bkdata/Parameters:
Parameter
Description
--defaults-file
From the
my.cnffile of the self-managed database, obtain the target path for data restoration, which is the specified data directory (datadir).--copy-back
The restore command for the XtraBackup tool.
The directory specified after this command is the backup decompression directory, such as
/var/mysql_bkdata/, from which the XtraBackup tool restores data to the data directory of the self-managed database.
MySQL 5.6
Prepare for restoration.
innobackupex --defaults-file=/var/mysql_bkdata/backup-my.cnf --apply-log /var/mysql_bkdata/Parameters:
Parameter
Description
--defaults-file
Sets default MySQL options from a configuration file.
An RDS MySQL backup file includes a configuration file named
backup-my.cnf. This file is located in the backup decompression directory,/var/mysql_bkdata/.--apply-log
The prepare command for the XtraBackup tool.
After this command, specify the directory to store backup files: the backup decompression directory
/var/mysql_bkdata/.Modify the data directory (datadir) of your self-managed database.
Edit the database configuration file.
sudo vim /usr/my.cnfTo find the path of the database configuration file, see Prerequisites.
Press the
ikey to enter edit mode and add the datadir parameter.datadir = /var/mysql_newdatamysql_newdatais the new data directory for the self-managed database, which you created in Preparations.Press the
Esckey to exit edit mode, and then enter:wq!to save and exit.
Restore the data.
sudo innobackupex --defaults-file=/usr/my.cnf --copy-back /var/mysql_bkdata/Parameters:
Parameter
Description
--defaults-file
In the
my.cnffile of the self-managed database, obtain the target path for data restoration from the data directory (datadir) parameter.--copy-back
The restore command for the XtraBackup tool.
This command specifies the directory that contains the backup files, which is the backup decompression directory
/var/mysql_bkdata/. The XtraBackup tool restores the data from this directory to the data directory of the self-managed database.
MySQL 5.5
Prepare for restoration.
innobackupex --defaults-file=/var/mysql_bkdata/backup-my.cnf --apply-log /var/mysql_bkdata/Parameters:
Parameter
Description
--defaults-file
Sets default MySQL options from a configuration file.
An RDS MySQL backup file contains a configuration file named
backup-my.cnf. This file is located in the backup decompression directory, which is/var/mysql_bkdata/.--apply-log
The prepare command for the XtraBackup tool.
The command is followed by the directory for storing backup files, namely the backup decompression directory
/var/mysql_bkdata/.Modify the self-managed database configuration file
my.cnf.Edit the database configuration file.
sudo vim /etc/my.cnfTo find the path of the database configuration file, see Prerequisites.
Press the
ikey to enter edit mode, and add the datadir parameter.datadir = /var/mysql_newdatamysql_newdatais the new data directory for the self-managed database, which was created in the Preparations section.Add the following content to
my.cnf.innodb_log_file_size=1048576000ImportantThe value of the innodb_log_file_size parameter must be the same as the value in
/var/mysql_bkdata/backup-my.cnf. You can use thecat /var/mysql_bkdata/backup-my.cnf | grep innodb_log_file_sizecommand to query the value.Press the
Esckey to exit edit mode, and enter:wq!to save and exit.
Restore the data.
sudo innobackupex --defaults-file=/etc/my.cnf --copy-back /var/mysql_bkdata/Parameters:
Parameter
Description
--defaults-file
Obtain the target path for data restoration from the data directory (datadir) setting in the
my.cnffile of your self-managed database.--copy-back
The restore command for the XtraBackup tool.
After this command, specify the backup decompression directory, such as
/var/mysql_bkdata/, from which the XtraBackup tool restores data to the data directory of the self-managed database.
Restoration FAQ
Step 4: Start the database
MySQL 8.0 and 5.7
(Optional) In the RDS for MySQL console, view the instance parameters to check the value of lower_case_table_names. If the value is
1, you need to modify themy.cnfconfiguration file of the self-managed database.Edit the database configuration file.
sudo vim /etc/my.cnfTo find the path of the database configuration file, see Prerequisites.
Press
ito enter edit mode, and add the following content.lower_case_table_names=1Press the
Esckey to exit edit mode, and enter:wq!to save and exit.
Grant permissions on the data directory.
sudo chown -R mysql:mysql /var/mysql_newdataRun the following command to start the MySQL process.
sudo mysqld --defaults-file=/etc/my.cnf --user=mysql --datadir=/var/mysql_newdata &Parameters:
Parameter
Description
--defaults-file
The path of the configuration file for the self-managed database. This topic uses
/etc/my.cnfas an example. You can refer to Preparations to confirm the configuration file path of the database.--user
The user that starts the database. The value is fixed as mysql.
--datadir
The data directory that the database uses is
/var/mysql_newdatain this example. You can refer to Prerequisites to determine the data directory of your database.
MySQL 5.6
(Optional) In the ApsaraDB RDS for MySQL console, view the instance parameters to check the value of lower_case_table_names. If the value is
1, you need to modify themy.cnfconfiguration file of the self-managed database.Edit the database configuration file.
sudo vim /usr/my.cnfTo find the path of the database configuration file, see Prerequisites.
Press
ito enter edit mode and add the following content.lower_case_table_names=1Press the
Esckey to exit edit mode and enter:wq!to save and exit.
Grant permissions on the data directory.
sudo chown -R mysql:mysql /var/mysql_newdataRun the following command to start the MySQL process.
sudo mysqld --defaults-file=/usr/my.cnf --user=mysql --datadir=/var/mysql_newdata &Parameter
Description
--defaults-file
The configuration file path of the self-managed database. This topic uses
/usr/my.cnfas an example. See Prerequisites to confirm the path.--user
The user that starts the database. The value is fixed as mysql.
--datadir
The data directory used for database startup. This topic uses
/var/mysql_newdataas an example. You can refer to Prerequisites to determine the data directory of the database.
MySQL 5.5
Grant permissions on the data directory.
sudo chown -R mysql:mysql /var/mysql_newdataRun the following command to start the MySQL process.
sudo mysqld --defaults-file=/etc/my.cnf --user=mysql --datadir=/var/mysql_newdata &Parameter
Description
--defaults-file
The path to the configuration file of the self-managed database. This topic uses
/etc/my.cnfas an example. To confirm the path for your database, see Preparations.--user
The user that starts the database. The value is fixed as mysql.
--datadir
The data directory is used to start the database. This topic uses
/var/mysql_newdataas an example. You can refer to Prerequisites to confirm the data directory of your database.
Startup FAQ
Step 5: Connect and verify
Run the following command to log on to the MySQL database and verify that the process started successfully.
mysql -u -pNoteThis logon command is used to verify that the restoration is successful. If you only need to view table data, make sure that the account has query permissions.
If you forget your account or password, pass the
--skip-grant-tablesparameter when you run the command to start the MySQL process. After the process starts, it skips the permission check and allows you to log on to the database without an account or password. After you successfully log on, you can reset your account and password.
Run the following command to check whether the databases from the ApsaraDB RDS for MySQL instance exist.
SHOW DATABASES;
Connection and verification FAQ
References
To restore all data or specific databases and tables from an RDS for MySQL instance to another RDS instance, see Restore full data or Restore databases and tables.
For more data restoration methods, see Overview of data restoration methods.