Reference https://help.aliyun.com/knowledge_detail/41817.html
Restore the backup files of the cloud database MySQL to the self-built database
Update Time: 2017-07-27 14:52:13
The cloud database MySQL version uses the open source software Percona Xtrabackup to back up the database, so you can use the software to restore the backup files of the cloud database MySQL to the built-in database, this article describes the detailed procedures.
For information on how to back up the MySQL version of cloud database, see Backing up RDS data.
Pre-conditions
The local MySQL database is installed on a 64-bit Linux system and is the same version as the MySQL version of the cloud database.
description : Due to software limitations, it is currently only supported to restore the backup files of the cloud database MySQL to the self-built MySQL database installed in the Linux system. However, the recovered data files under Linux can be used normally in Windows and Linux operating systems.
The Data Recovery Tool Percona Xtrabackup 2.2.9 or later is installed in the operating system. If not installed, please download it from Percona Xtrabackup website, please refer to the official documentation for installation instructions.
The operating system has the data backup file installed to unzip the tool rds_backup_extract.sh. If it is not installed, please click Download.
Operation Steps
-
To get a data backup file, follow these steps.
-
To log on to the RDS management console.
-
Selects the region of the destination instance.
-
Click the ID of the target instance to go to the basic information page.
-
In the left navigation bar, select Backup Recovery and go to the Backup Recovery page.
-
Select the Data Backup tab.
-
Select a time range for the query, and then click Query .
-
In the Data backup list, locate the data backup that you want to download, and click its corresponding download , as shown in.
-
In the instance backup file Download window, click Copy Extranet address to get the data backup file extranet, as shown in.
To download the data backup file, the following steps are described below.
Log in to ECS on cloud server.
Execute the following command to download the data backup file.
wget -c ‘<数据备份文件外网>‘ -O <自定义文件名>.tar.gz
Parameter description:
To restore the downloaded data backup to the local MySQL database, follow the steps below.
-
To unzip the downloaded data backup file by executing the following command.
-
bash rds_backup_extract.sh -f < data backup file name >. Tar. GZ -c /home/ mysql/data
Parameter description:
-
- F: Specifies the backup set file to decompress.
-
-C: Specifies the directory to which the files will be extracted. Optional parameters, if not specified, unzip to the current directory.
-
Executes the following command to query the files generated after decompression.
-
ls -l /home/mysql/ data
After successful execution of the
Command, the system returns the following results, where the blue font is the database that the RDS instance contains when the backup file was generated.
-
Perform the following command to restore the extracted backup files.
-
innobackupex ---file=/home//data/backup-< Span class= "KWD" >my. CNF --apply-log /home/mysql/data
If the system returns similar results as follows, Indicates that the backup file was successfully restored to the local database.
-
To avoid version problems, you need to modify the BACKUP-MY.CNF parameter, following the steps below.
-
Executes the following command to edit the backup-my.cnf file in text mode.
-
vi /home< Span class= "pun" >/mysql/data/ backup-my. CNF
-
Execute the following command, commenting out the following parameters.
#innodb_fast_checksum
#innodb_page_size
#innodb_log_ Block_size
-
Press the ESC key, and then enter : Wq
to save and close the editor.
-
Executes the following command, modifies the owner of the file, and determines that the file belongs to the MySQL user.
Chown -< Span class= "PLN" >r mysql:mysql /home/mysql/data
-
Execute the following command to start the MySQL process.
-
Mysqld_safe -- defaults-file=/home/ mysql/data/backup< Span class= "pun" >-my.--user=mysql --< Span class= "PLN" >datadir=/home/mysql/< Span class= "PLN" >data &
Execute the following command to log in to the MySQL database to verify that the process started successfully.
mysql -uroot
If the system returns the following result and the process starts successfully, the parameter comment and the modified file owner are successfully executed.
When the restore is complete, the user created in the RDS instance is not included in table mysql.user and needs to be new. Before creating a new user, execute the following command.
Delete FromMysql.Dbwhere User<> ' root ' Span class= "KWD" >and Char_length (user0; from Mysql.where User<> ' root ' and Char_length ( user) >0;
1028 Ali RDS How to restore a backup file of a cloud database MySQL to a self-built database