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.

Note For more information about how to migrate the data of a standalone Redis instance, see Use redis-shake to migrate data.

Prerequisites

  • 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.
    Note
    • 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.

Limits

  • 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.

Note
  • The sync mode supports data synchronization between different Redis versions. For example, when you synchronize data between Redis 2.8 and Redis 4.0.
  • For more information about the redis-shake tool, see redis-shake on GitHub or FAQ.

Procedure

  1. Log on to the ECS instance that can access the ApsaraDB for Redis instance.
  2. Download redis-shake in the ECS instance.
    Note We recommend that you download the latest version of redis-shake.
  3. Run the following command to decompress the downloaded redis-shake.tar.gz package:
    tar -xvf redis-shake.tar.gz
    Note 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.
  4. 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. 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.
    10.xx.xx.1:7000;10.xx.xx.1:7002;10.xx.xx.1:7003;10.xx.xx.1:7004
    source.password_raw The password of the source Codis or Redis cluster. SourcePass233
    target.type The type of the ApsaraDB for Redis instance. proxy
    target.address The endpoint and port of the ApsaraDB for Redis instance. For more information, see View endpoints. r-bpxxxxxxxxxxxxxxx.redis.rds.aliyuncs.com:6379
    target.password_raw The password of the ApsaraDB for Redis instance. TargetPass233
    rewrite Specifies whether to overwrite the existing keys in ApsaraDB for Redis that are same as those in the RDB file. Valid values:
    • true: overwrites the existing keys.
    • false: does not overwrite the existing keys.
    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
    target.db

    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.

    0
    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.
    64
  5. Run the following command to migrate data:
    ./redis-shake -type=sync -conf=redis-shake.conf
    Note 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.
  6. Check the synchronization status in synchronization logs. When sync rdb done appears in the log, full synchronization is completed and incremental synchronization starts.
    Figure 1. Synchronization logs
    Migrate data from on-premises Codis or Redis to ApsaraDB for Redis
    Note Whenever the data of a node in Codis or Redis is synchronized, sync rdb done appears.
  7. After the data of all nodes is synchronized, +forwardCommands=0 indicates 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.