Relational Database ServiceRelational Database Service

Compute
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Enterprise Switch
Security & Compliance
Anti-DDoS
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Compass
Cloud Certificate Manager
Anti-DDoS Service
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB NoSQL
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
ServiceStage
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain Service
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
DevCloud
ProjectMan
CodeHub
CloudRelease
CloudPipeline
CloudBuild
CloudDeploy
Cloud Communications
Message & SMS
Cloud Ecosystem
Marketplace
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
enterprise-collaboration
Meeting
IoT
IoT
Intelligent EdgeFabric
DeveloperTools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Help Center> Relational Database Service> User Guide> Working with RDS for MySQL> Backups and Restorations> Restoring from Backup Files to a Self-Built MySQL Database
Updated at: Apr 02, 2022 GMT+08:00

Restoring from Backup Files to a Self-Built MySQL Database

Scenarios

You can download backup files by referring to Downloading a Full Backup File and restore data from them.

Backup data cannot be restored to local databases that run the Windows operating system.

Only x86 packages of the open-source backup tool XtraBackup are supported. Therefore, you are advised to restore backup data to self-built databases on Arm-based ECSs by migrating data with DRS or exporting and importing data. For details, see Database Migration.

Prerequisites

When you restore data from backup files to self-built MySQL databases, ensure that the target MySQL version is later than or equal to the original MySQL version.

During data restoration, run the following command to view the restoration process:

ps -ef | grep mysql

Procedure

  1. Download qpress-11-linux.x64.tar from the website and upload it to the ECS.

    tar -xvf qpress-11-linux-x64.tar

    mv qpress /usr/bin/

  2. Download the XtraBackup software and upload it to the ECS for installation.

    Download XtraBackup from the website and upload it to the ECS. Then, run the following command to install percona-xtrabackup-24-2.4.9-1.el7.x86_64.rpm:

    rpm -ivh percona-xtrabackup-24-2.4.9-1.el7.x86_64.rpm --nodeps --force

  3. On the ECS, decompress the full backup file that has been downloaded.

    1. Create a temporary directory, for example, mysqlbackup.

      mkdir mysqlbackup

    2. Decompress the file to the temporary directory.
      • For MySQL 5.6 and 5.7:

        xbstream -x -p 4 < ./Full backup file.qp -C ./mysqlbackup/

        innobackupex --parallel 4 --decompress ./mysqlbackup

      • For MySQL 8.0:

        xbstream -x -p 4 < ./Full backup file.qp -C ./mysqlbackup/

        xtrabackup --parallel 4 --decompress --target-dir=./mysqlbackup

    3. Delete full backup files ending in ".qp":

      find ./mysqlbackup/ -name '*.qp' | xargs rm -f

  4. Apply the log.

    • For MySQL 5.6 and 5.7, run innobackupex --apply-log ./mysqlbackup
    • For MySQL 8.0, run xtrabackup --prepare --target-dir=./mysqlbackup

  5. Back up data.

    1. Stop MySQL database services.

      service mysql stop

      For MySQL 5.7, run the following command to stop MySQL database services:

      /bin/systemctl stop mysqld.service

    2. Back up the original database directory.

      mv /var/lib/mysql/data/var/lib/mysql/data_bak

    3. Create a new database directory and change the permissions.

      mkdir /var/lib/mysql/data

      chown mysql:mysql /var/lib/mysql/data

  6. Copy the full backup file and change directory permissions.

    • For MySQL 5.6 and 5.7, run innobackupex --defaults-file=/etc/my.cnf --copy-back ./mysqlbackup
    • For MySQL 8.0, run xtrabackup --defaults-file=/etc/my.cnf --copy-back --target-dir=./mysqlbackup

    chown -R mysql:mysql /var/lib/mysql/data

    Before performing this step, ensure that the my.cnf file is correctly configured.

    /etc/my.cnf

    datadir=/var/lib/mysql/data

  7. Start the database.

    service mysql start

    For MySQL 5.7, run the following command to start the database:

    /bin/systemctl start mysqld.service

  8. Run the following commands to log in to the database and view the restoration result:

    mysql -u root

    show databases

    Figure 1 Viewing the restoration result

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel