All Products
Search
Document Center

Database Backup:Restore the downloaded backup data

Last Updated:Apr 15, 2024

This topic describes how to restore the downloaded backup data to a database.

Prerequisites

  • Backup data is downloaded. For more information, see Manually download a backup set or Configure automatic download of backup sets.

  • The database service is deployed on the server to which you want to restore the backup data. For example, before you restore the backup data to a MySQL database, make sure that the MySQL service of a specific version is deployed on the server.

  • Database Backup (DBS) built-in storage is supported to back up data. Object Storage Service (OSS) is not supported.

Restore the downloaded data of a physical backup

Usage notes on the downloaded backup data

  • MySQL data is in the same format as the data in Percona XtraBackup and is compressed.

  • SQL Server data is in the same format as the data generated by the native backup command and is compressed.

The following figure shows an example of the downloaded backup data of a physical backup for a MySQL database.物理备份下载数据

Procedure

  1. After the download is complete, decompress the downloaded package. By default, the backup set is compressed in the <Download task ID>.tar.gz package.

    Run the following command to decompress the downloaded package:

    1. Run the gzip -d <Download task ID>.tar.gz command to obtain the <Download task ID>.tar file.

    2. Run the file <Download task ID>.tar command to view the file format after the gzip command is run:

      • If the file format is POSIX tar archive, run the tar xvf <Download task ID>.tar command to obtain the <Download task ID> file.

      • If the file format is Zip archive data, at least v2.0 to extract, run the unzip <Download task ID>.tar command to obtain the <Download task ID> file.

  2. Start the database.

    If you want to start a MySQL database, perform the following operations:

    1. Set the datadir parameter in the my.cnf file to the directory to which data is restored. The my.cnf file is the configuration file of the database.

    2. Start the database. For example, you can start the database in the Linux operating system by running the following command:

      service mysqld start

Restore the downloaded data of a logical backup

Usage notes on the downloaded backup data

The downloaded backup data contains DDL statements used to create tables and SQL data in a database.

The following code provides examples on the downloaded data of a logical backup for a MySQL database:

Sample DDL statements

CREATE TABLE `rds_db`.`orders` (
`order_id`  bigint(20)     COMMENT ''    ,
`product_name`  varchar(32)  CHARSET `utf8` COLLATE `utf8_general_ci`    COMMENT ''    ,
`price`  double     COMMENT ''    ,
`total_amount`  double     COMMENT ''    ,
`created_date`  date     COMMENT ''
) engine=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=`utf8` DEFAULT COLLATE `utf8_general_ci` comment = '' ;
CREATE TABLE `rds_db`.`rds_table` (
`id`  int(11)     COMMENT ''    ,
`price`  decimal(10,2)     COMMENT ''    ,
`trx_time`  timestamp   on update CURRENT_TIMESTAMP  COMMENT ''   NOT NULL   DEFAULT CURRENT_TIMESTAMP
) engine=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=`utf8` DEFAULT COLLATE `utf8_general_ci` comment = '' ;

Sample SQL data

gmt_create,id
"2020-08-06 12:00:00","1"
"2020-08-06 12:00:01","2"
"2020-08-06 12:00:02","3"
"2020-08-06 12:00:03","4"
"2020-08-06 12:00:04","5"
"2020-08-06 12:00:05","6"
"2020-08-06 12:00:06","7"
"2014-09-06 15:56:07","8"

Procedure

  1. After the download is complete, decompress the downloaded package. By default, the backup set is compressed in the <Download task ID>.tar.gz package.

    Note

    The following command applies to only the Linux operating system.

    Run the following command to decompress the downloaded package:

    mkdir download && tar -zvxf 1jewk54******.tar.gz -C ./download
  2. Restore table schemas based on DDL statements and import SQL data.

    For example, you can use an import.py script to restore full backup data for a MySQL database. Before you use this method, you must install Python 3 on your server. To restore full backup data, run the following command:

    python import.py ./download/ <restore_db_host> <restore_db_port> <restore_db_user> <restore_db_password>

    Example:

    python import.py ./download/ 127.0.0.1 3306 root password123

    Parameter

    Description

    ./download/

    The path to which the backup data is downloaded.

    restore_db_host

    The IP address of the destination database to which you want to restore the backup data.

    restore_db_port

    The port number of the destination database to which you want to restore the backup data.

    restore_db_user

    The account that is used to log on to the destination database.

    restore_db_password

    The password that is used to log on to the destination database.

FAQ

Q: What do I do if the "ERROR 1148 (42000): The used command is not allowed with this MySQL version" error message appears when I restore the downloaded backup data to a self-managed MySQL database?

A: Execute the SHOW VARIABLES LIKE 'local_infile'; statement on the self-managed MySQL database. If OFF is displayed in the output, execute the set global local_infile = 1; statement to enable file import. After the preceding operations are performed, run the import script again.