You can use the restore mode of the redis-shake tool to migrate the backup data of an on-premises Redis instance to an ApsaraDB for Redis instance. In this way, you can migrate data from on-premises Redis to the cloud.
- An ApsaraDB for Redis instance is created as the destination of data migration.
- An Elastic Compute Service (ECS) instance is created for running the redis-shake tool.
- The ECS instance can access the destination ApsaraDB for Redis instance.
- The Linux operating system is running on the ECS instance.
- An RDB file is stored on the ECS instance.
Introduction to the redis-shake tool
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 restore mode, the redis-shake tool can use an RDB file to recover or migrate data. This topic describes how to recover data from an RDB file to an ApsaraDB for Redis instance to help you migrate data from on-premises Redis to the cloud.
- Log on to the ECS instance that can access the destination ApsaraDB for Redis instance.
- Download the redis-shake tool on the ECS instance.
Note We recommend that you download the latest version.
- Run the following command to decompress the redis-shake.tar.gz package:
# tar -xvf redis-shake.tar.gzNote In the decompressed folder, the redis-shake file is a binary file that can run in the 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 restore mode of the redis-shake
Table 1. Parameters for the restore mode of the redis-shake tool Parameter Description Example rdb.input The path of the RDB file. You can specify either a relative path or an absolute path. /root/tools/RedisShake/demo.rdb target.address The endpoint and port of the destination ApsaraDB for Redis instance.
target.password_raw The password of the destination ApsaraDB for Redis instance.
TargetPass233Note If you use a database account other than the default database account to connect to the ApsaraDB for Redis instance, set this parameter in the following format:
target.db The database to which the data is recovered in the destination ApsaraDB for Redis instance. Default value: 0. For example, to recover the data of the source on-premises Redis instance to DB10 of the destination ApsaraDB for Redis instance, set this parameter to 10. If you set this parameter to a value less than 0, data is recovered to DB0.
rewrite Specifies whether to overwrite the existing keys that are identical to those in the RDB file. Valid values:
Note Default value: true. We recommend that you back up the valid data of the destination ApsaraDB for Redis instance before migration. If you set this parameter to false and any keys are duplicate in the source and destination databases, an error message is returned.
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.
- Recommended value: 64.
64Note You can use the default values for other parameters unless otherwise specified.
- Run the following command to recover data:
# ./redis-shake -type=restore -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.Note When
restore: rdb doneappears in logs, the data is recovered. You can press Ctrl+C to exit the tool.