This topic describes how to use redis-port to restore data. You can restore the data of an ApsaraDB for Redis instance in the ApsaraDB for Redis console. You can run the script that is provided in this topic to download a backup of the instance. The script uses redis-port to restore data from the backup.
- The engine version of the source ApsaraDB for Redis instance is Redis 2.8 or 4.0.
- The engine version of the destination ApsaraDB for Redis instance is 2.8, 4.0, or 5.0.
- Create a RAM user and grant the AliyunKvstoreFullAccess permission to the RAM user. This permission allows the RAM user to manage ApsaraDB
for Redis instances.
- Log on to the RAM console.
- Create a RAM user.
- In the left-side navigation pane, choose .
- On the Users page, find the RAM user to which you want to grant permissions and click
Add Permissions in the Actions column.
- In the dialog box that appears, enter AliyunKvstoreFullAccess in the search box and click the policy name to add the policy to the Selected section.
- Click OK.
- Click Complete.
- Create an AccessKey pair for the RAM user. For more information, see Create an AccessKey pair.
- Perform the following operations based on the location where redis-port is installed:
- The ApsaraDB for Redis instances that are mentioned in the following table refer to the source and destination ApsaraDB for Redis instances. Perform the following operations on the source and destination ApsaraDB for Redis instances.
- We recommend that you install redis-port on Elastic Compute Service (ECS) instances. You can connect to the source and destination ApsaraDB for Redis instances through a virtual private cloud (VPC) to achieve lower network latency and higher security.
Location where redis-port is installed Operation ECS instances
- Make sure that the ECS instance and the ApsaraDB for Redis instance belong to the
same VPC. They share the same VPC ID in the Basic Information section.
- If they are deployed in different VPCs, you can change the VPC to which the ECS instance belongs. For more information, see Change the VPC of an ECS instance.
- The network types are distinct. For example, the ECS instance belongs to a classic network and the ApsaraDB for Redis instance belongs to a VPC. For more information about how to connect to an ApsaraDB for Redis instance from an ECS instance when they are deployed in different types of networks, see Connect an ECS instance to an ApsaraDB for Redis instance in different types of networks.
- Obtain the internal IP address of the ECS instance. For more information, see How do I query IP addresses of ECS instances.
- Add the internal IP address of the ECS instance to the whitelist of the ApsaraDB for Redis instance. For more information, see Configure an IP whitelist.
- By default, an ApsaraDB for Redis instance provides only an internal endpoint. You must apply for a public endpoint when you want to connect to an ApsaraDB for Redis instance over the Internet. For more information, see Apply for a public endpoint.
- Run the curl ipinfo.io |grep ip command on the on-premises machine to obtain the public IP address. The returned result is shown in the following figure.
- Add the public IP address of the on-premises machine to the whitelist of the ApsaraDB for Redis instance. For more information, see Configure an IP whitelist.
- Log on to the device where redis-port is installed. The device may be an ECS instance or an on-premises machine.
Note In this example, an ECS instance that runs the Ubuntu 16.04.6 operating system is used.
- Run the following command to install the core library of OpenAPI Explorer:
apt-get update apt install python-pip -y pip install --upgrade "pip < 21.0" pip install aliyun-python-sdk-core
- Run the following command to download the script package:
wget 'https://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/120287/cn_zh/1618924922413/redis-rdb-auto-restore.tar'Note The script package contains the script rdb_restore.py, redis-port, and other files. After you can run the script, the script automatically downloads the specified instance backup file and runs redis-port to restore the backup to the specified ApsaraDB for Redis instance.
- Run the following command to decompress the script package:
tar -xvf redis-rdb-auto-restore.tar
- Run the following command to switch to the directory of the decompressed script package
and modify the configuration file:
cd redis-rdb-auto-restore vim config.jsonNote After you run the preceding command, the system opens an editor. Enter a to use the editing mode.
Table 1. Parameters Parameter Description Example acesskeyID Specify the AccessKey ID and AccessKey secret of the RAM user. For more information, see Prerequisites. LTAI5tBHRFKq************ acesskeySecret SoA0hZtZJ7Lszgy7aL************ regionid The ID of the region where the source ApsaraDB for Redis instance is deployed. For more information about the mappings between region IDs and region names, see Regions and zones. cn-hangzhou
- To save the configuration file and exit the editor, press Esc, enter :wq, and press Enter.
- Run the following command to launch redis-port to migrate data:
python rdb_restore.py -c r-bp1q4xidqiyqpq**** -d 2021-04-19 -t r-bp1q4xidqiyqpq****.redis.rds.aliyuncs.com -p 6379 -a redistest:Pawd123456 -b 9382****2,9382****3 -t r-bp1ky7j6qc7umk****.redis.rds.aliyuncs.com -p 6379 -a Pawd123456
Table 2. Parameters in rdb_restore.py Parameter Required Description Example -c Yes The ID of the source ApsaraDB for Redis instance. SoA0hZtZJ7Lszgy7aL************ -d Yes The timestamp of the backup that you want to download. The timestamp is in the yyyy-MM-dd format. 2021-04-19 -t Yes The endpoint that is used to connect to the destination ApsaraDB for Redis instance. For more information, see View endpoints.
- If the ECS instance is connected to the ApsaraDB for Redis instance through a VPC, you must obtain the internal endpoint of the ApsaraDB for Redis instance.
- If you connect an on-premises machine to the ApsaraDB for Redis instance over the Internet, you must obtain the public endpoint of the ApsaraDB for Redis instance.
r-bp1q4xidqiyqpq****.redis.rds.aliyuncs.com -p Yes The port of the destination ApsaraDB for Redis instance. The default port is 6379. 6379 -a Yes The account that has the read and write permissions and the password of the destination ApsaraDB for Redis instance. Separate the account and password with a colon (:). For more information about how to create an account, see Create and manage database accounts. redistest:Pawd123456 -o No The directory where the downloaded backup of the source instance is saved. The default directory is /root/. /root/ -b No The ID of the backup of the source instance. If multiple backups are created, you can use this parameter to specify the backup that you want to download.Note
- You can check the Backup and Recovery page in the console or call the DescribeBackups operation to query the backup ID.
- If the source instance uses a cluster architecture or read /write splitting architecture, you must download the backup of each shard by specifying this parameter. Separate multiple backup IDs with commas (,).
938261111,938262222 -h No Queries help information about a command. NoneAfter you run the program, the operational log is printed. If the data is restored,
restore: rdb doneappears.