You can use the sync mode of the redis-shake tool to migrate the data of an on-premises Codis or Redis cluster to an ApsaraDB for Redis instance.
- An ApsaraDB for Redis instance is created as the destination for data migration. For more information about how to create an ApsaraDB for Redis instance, see Create an ApsaraDB for Redis instance.
- An Elastic Compute Service (ECS) instance is created to run the redis-shake tool. The 64-bit Linux operating system is running on the ECS instance. For more information about how to create an ECS instance, see Create an ECS instance.
- The ECS instance is allowed to access the ApsaraDB for Redis instance.
- If the ECS instance and the ApsaraDB for Redis instance are deployed in the same virtual private cloud (VPC), you must add the internal IP address of the ECS instance to the whitelist of the ApsaraDB for Redis instance. For more information, see Set IP address whitelists.
- If the ECS instance and the ApsaraDB for Redis instance are not deployed in the same VPC, the ECS instance can access the ApsaraDB for Redis instance by using the public endpoint. For more information, see Through the Internet.
- The sync mode applies to scenarios such as data migration from on-premises Redis to the cloud. It also applies to data synchronization between on-premises Redis and ApsaraDB for Redis, and data synchronization between on-premises Redis databases. ApsaraDB for Redis cluster instances cannot be used as the source for data migration in sync mode.
- In sync mode, the source Redis must support the SYNC and PSYNC commands.
Introduction to redis-shake
The redis-shake tool is an open source tool developed by Alibaba Cloud. You can use it to parse (decode mode), recover (restore mode), back up (dump mode), and synchronize (sync or rump mode) Redis data. In sync mode, redis-shake runs the SYNC or PSYNC command to synchronize full or incremental data from the source Redis to ApsaraDB for Redis. Incremental synchronization automatically starts after full synchronization is completed. This topic describes how to use the sync mode of the redis-shake tool to migrate the data of an on-premises Codis or Redis cluster to an ApsaraDB for Redis instance.
- Log on to the ECS instance that can access the ApsaraDB for Redis instance.
- Download redis-shake in the ECS instance.
Note We recommend that you download the latest version of redis-shake.
- Run the following command to decompress the downloaded redis-shake.tar.gz package:
tar -xvf redis-shake.tar.gzNote The decompressed redis-shake file is a binary file that runs on a 64-bit Linux operating system. The redis-shake.conf file is the configuration file of the redis-shake tool. You must modify this configuration file in the next step.
- Modify the redis-shake.conf file. The following table describes the parameters for the sync mode of the redis-shake tool.
Parameter Description Example source.type The type of the source Codis or Redis cluster.
source.address The endpoint and port of the source Codis or Redis cluster.Note Data migration will consume resources. To minimize adverse impacts on your services, we recommend that you use the endpoints and ports of replica nodes.
source.password_raw The password of the source Codis or Redis cluster.
target.type The type of the ApsaraDB for Redis instance.
target.address The endpoint and port of the ApsaraDB for Redis instance. For more information, see View endpoints.
target.password_raw The password of the ApsaraDB for Redis instance.
rewrite Specifies whether to overwrite the existing keys in ApsaraDB for Redis that are same as those in the RDB file. Valid values:
Note Default value: true. We recommend that you back up the valid data in ApsaraDB for Redis before data migration. If you set this parameter to false and a key exists in both the source and destination databases, an error is returned.
- true: overwrites the existing keys.
- false: does not overwrite the existing keys.
The database to which the data is migrated in the ApsaraDB for Redis instance.
For example, to migrate data from the on-premises Redis to DB10 of the ApsaraDB for Redis instance, set this parameter to 10.
If you set this parameter to -1, data in the source Redis cluster is migrated to the same database in the ApsaraDB for Redis instance. For example, the data of DB0 in the source Redis cluster is migrated to DB0 in the ApsaraDB for Redis instance, the data of DB1 in the source Redis cluster is migrated to DB1 in the ApsaraDB for Redis instance.
parallel The number of concurrent threads used to synchronize the RDB file. More concurrent threads improve synchronization performance.Note
- Minimum value: 1.
- Maximum value: depends on the server performance.
- We recommend that you set this parameter to 64.
- Run the following command to migrate data:
./redis-shake -type=sync -conf=redis-shake.confNote You must run this command in the same directory as the redis-shake and redis-shake.conf files. Otherwise, you must specify the correct file path in the command.
- Check the synchronization status in synchronization logs. When
sync rdb doneappears in the log, full synchronization is completed and incremental synchronization starts.Note Whenever the data of a node in Codis or Redis is synchronized,
sync rdb doneappears.
- After the data of all nodes is synchronized,
+forwardCommands=0indicates that no data is written to the source database and no incremental data is being synchronized. In this case, switch your services to the new database.