You can use redis-shake in restore mode to restore Redis Database (RDB) files to a Tair or ApsaraDB for Redis instance. This method allows you to migrate data to Alibaba Cloud.

Prerequisites

  • The self-managed Redis database runs Redis 2.8, 3.0, 4.0, 5.0, 6.0, or 7.0.
  • A Tair instance or an ApsaraDB for Redis instance is created. For more information about how to create an instance, see Step 1: Create an ApsaraDB for Redis instance.
    Note When you create an instance, we recommend that you specify a Redis version that is the same as or later than that of the source database. For example, you can restore data from a source database that runs Redis 2.8 to an instance that runs Redis 6.0.

    When you restore data across Redis versions, we recommend that you first create a pay-as-you-go instance to test the compatibility. After you confirm that no compatibility issue exists, you can change the instance into a subscription one. For more information about how to change the billing method of an instance, see Change the billing method to subscription.

redis-shake

redis-shake is an open source Redis tool developed by Alibaba Cloud to transfer and filter data. This tool is flexible, efficient, and easy to deploy. redis-shake is available in three modes: sync, restore, and scan. In sync mode, redis-shake supports full and incremental data migration. In restore mode, redis-shake supports the restoration of local Redis Database (RDB) files to the destination instance. In scan mode, redis-shake runs the SCAN command to obtain the source Redis keys, runs the DUMP command to obtain the key values, and then runs the RESTORE command to restore the keys and their values to the destination instance. The following figure shows the synchronization processes in different modes.
Figure 1. redis-shake modes
redis-shake data migration processes

Precautions

  • If the maxmemory-policy parameter of the destination instance is not set to noeviction, data may be inconsistent between the source database and the destination instance. For more information about data eviction policies, see How does ApsaraDB for Redis evict data by default?
  • If an expiration policy is used on specific keys in the source database, these keys may not be deleted at the earliest opportunity after they expire. Therefore, the number of keys in the destination instance may be less than that in the source database. You can run the info command to view the number of keys in the destination instance.

Procedure

  1. Configure a whitelist based on the device on which you want to install redis-shake.
    Note We recommend that you install redis-shake on the device in which the self-managed Redis database resides to reduce network latency and prevent connection failures caused by the firewall settings of the self-managed Redis database.
    Device on which you want to install redis-shake Operation
    Elastic Compute Service (ECS) instance
    1. Make sure that the ECS instance and the ApsaraDB for Redis instance are deployed in the same VPC. The ECS instance and ApsaraDB for Redis instance must have the same VPC ID.
      Note If they are deployed in different VPCs, you must change the VPC to which the ECS instance belongs. For more information, see Change the VPC of an ECS instance.
    2. Obtain the internal IP address of an ECS instance. For more information, see How do I query IP addresses of ECS instances?
    3. Add the internal IP address of the ECS instance to the whitelist of the ApsaraDB for Redis instance. For more information, see Configure whitelists.
    On-premises device
    1. By default, an ApsaraDB for Redis instance provides only an internal endpoint. You must apply for a public IP address when you want to connect to an ApsaraDB for Redis instance over the Internet. For more information, see Apply for a public endpoint for an ApsaraDB for Redis instance.
    2. Run the curl ipinfo.io |grep ip command on the on-premises host to obtain the public IP address. The returned result is shown in the following figure:View the public IP address
    3. Add the public IP address of the on-premises host to the whitelist of the ApsaraDB for Redis instance. For more information, see Configure whitelists.
  2. Install redis-shake. If it is already installed, skip this step.
    1. Log on to the ECS instance or on-premises device on which you want to install redis-shake.
    2. Run the following command to download the redis-shake package:
      wget 'https://github.com/alibaba/RedisShake/releases/download/v3.1.7/redis-shake-linux-amd64.tar.gz'
      Note In this example, redis-shake v3.1.7 is used. We recommend that you use the latest version of redis-shake. For more information, visit redis-shake-v3.1.7.
    3. Run the following command to decompress the redis-shake package:
      tar xzf redis-shake-linux-amd64.tar.gz
  3. Perform data restoration on the device on which redis-shake is installed.
    1. Run the following command in the redis-shake directory to go to the page for modifying the configuration file:
      vim restore.toml
    2. Enter a to enter the edit mode.
    3. Modify the configuration file.
      Table 1. Parameters
      Section Parameter Description Example
      None type

      The redis-shake mode. Set the value to restore.

      restore
      source rdb_file_path The relative or absolute path of the RDB file. In this example, the path is set to /root/redisdump.
      Note
      • If no RDB files are generated, run the BGSAVE command to generate RDB files.
      • redis-shake can restore only a single RDB file at a time.

        If the source database uses the cluster architecture, you can restore the RDB file of each node one by one or start redis-shake for multiple nodes at a time to restore data.

      /root/redisdump/dump.rdb
      target type The architecture of the destination instance. Valid values: standalone
      address The endpoint and port number of the destination instance. Separate the endpoint and port number with a colon (:). For more information about how to obtain the endpoint and port number of an instance, see View endpoints.
      • If the Elastic Compute Service (ECS) instance and the destination instance reside in the same virtual private cloud (VPC), data can be restored over the VPC. In this case, you must obtain the VPC endpoint of the destination instance.

        If the ECS instance and the destination instance reside in different regions or VPCs, data can be restored only over the Internet.

      • If you use an on-premises device, data can be restored over the Internet. In this case, you must obtain the public endpoint of the destination instance.
      r-bp1wcw2rlw76acc5k****.redis.rds.aliyuncs.com:6379
      password The account and password used to log on to a database of the destination instance. The account must have read and write permissions.
      • If you use the default account whose username is the same as the instance ID, enter the password.
      • If you use a custom account, enter the password in the user:password format. For example, if the username of the custom account is testaccount and the password is Rp829dlwa, enter testaccount:Rp829dlwa as the password.
      For information about how to create a database account, see Create and manage database accounts.
      testaccount:Rp829dlwa
      Note Other parameters do not need to be set in most cases. For more information, see the parameter comments in the restore.toml file.
    4. Press the Esc key to exit the edit mode. Then, enter :wq and press the Enter key to save the configuration file and exit the editor.
    5. Run the following command to start redis-shake. Then, redis-shake starts data restoration.
      ./redis-shake restore.toml
      redis-shake displays operational logs on the screen.
      Note For information about the causes and troubleshooting methods of errors, see Common errors and solutions.
  4. View the displayed logs and wait until the data is restored.
    2022-10-20 14:47:51 INF RDB AUX fields. key=[ctime], value=[1666148547]
    2022-10-20 14:47:51 INF RDB AUX fields. key=[used-mem], value=[2467744]
    2022-10-20 14:47:51 INF RDB repl-stream-db: 0
    2022-10-20 14:47:51 INF RDB AUX fields. key=[repl-id], value=[22851cf87ab1c8fd3fad0101471626bbccb837e7]
    2022-10-20 14:47:51 INF RDB AUX fields. key=[repl-offset], value=[0]
    2022-10-20 14:47:51 INF RDB AUX fields. key=[aof-preamble], value=[0]
    2022-10-20 14:47:51 INF RDB resize db. db_size=[9], expire_size=[0]
    2022-10-20 14:47:51 INF send RDB finished. path=[/root/redisdump/dump.rdb]
    2022-10-20 14:47:51 INF finished.
    When send RDB finished is displayed in the logs, data restoration is complete and redis-shake stops running.
  5. Optional: Verify the restored data. For more information, see Verify data after migration.