Updated on 2024-12-16 GMT+08:00

Self-Hosted Redis Cluster Migration with redis-shake (RDB)

redis-shake is an open-source tool for migrating data online or offline (by importing backup files) between Redis Clusters. Data can be migrated to DCS Redis Cluster instances seamlessly because DCS Redis Cluster inherits the native Redis Cluster design.

The following describes how to use Linux redis-shake to migrate self-hosted Redis Cluster to a DCS Redis Cluster instance offline.

If the source Redis and the target Redis cannot be connected, or the source Redis is deployed on other clouds, you can migrate data by importing backup files.

Notes and Constraints

To migrate to an instance with SSL enabled, disable the SSL setting first. For details, see Transmitting DCS Redis Data with Encryption Using SSL.

Prerequisites

  • A DCS Redis Cluster instance has been created. For details about how to create one, see Buying a DCS Redis Instance.

    The memory of the target Redis instance cannot be smaller than that of the source Redis.

  • An Elastic Cloud Server (ECS) has been created. For details about how to create an ECS, see Purchasing and Using an ECS. Select the same VPC, subnet, and security group as the DCS Redis Cluster instance.

Obtaining Information of the Source and Target Redis Nodes

  1. Connect to the source and target Redis instances, respectively. Connect to Redis by referring to redis-cli.
  2. In online migration of Redis Clusters, the migration must be performed node by node. Run the following command to query the IP addresses and ports of all nodes in both the source and target Redis Clusters.
    redis-cli -h {redis_address} -p {redis_port} -a {redis_password} cluster nodes

    {redis_address} indicates the Redis connection address, {redis_port} indicates the Redis port, and {redis_password} indicates the Redis connection password.

    In the command output similar to the following, obtain the IP addresses and ports of all masters.

Installing RedisShake

  1. Log in to the ECS.
  2. Run the following command on the ECS to download the redis-shake: This section uses v2.1.2 as an example. You can also download other redis-shake versions as required.
    wget https://github.com/tair-opensource/RedisShake/releases/download/release-v2.1.2-20220329/release-v2.1.2-20220329.tar.gz
  3. Decompress the redis-shake file.
    tar -xvf redis-shake-v2.1.2.tar.gz

If the source cluster is deployed in the data center intranet, install redis-shake on the intranet server. Export the source cluster backup file by referring to Exporting the Backup File. Upload the backup to the cloud server as instructed by the following steps

Exporting the Backup File

  1. Go to the redis-shake directory.
    cd redis-shake-v2.0.3
  2. Edit the redis-shake.conf file by providing the following information about all the masters of the source:
    vim redis-shake.conf
    The modification is as follows:
    source.type = cluster
    # If there is no password, skip the following parameter.
    source.password_raw = {source_redis_password}
    # IP addresses and port numbers of all masters of the source Redis Cluster, which are separated by semicolons (;).
    source.address = {master1_ip}:{master1_port};{master2_ip}:{master2_port}...{masterN_ip}:{masterN_port}

    Press Esc to exit the editing mode and enter :wq!. Press Enter to save the configuration and exit the editing interface.

  3. Run the following command to export the RDB file:
    ./redis-shake -type dump -conf redis-shake.conf

    If the following information is displayed in the execution log, the backup file is exported successfully:

    execute runner[*run.CmdDump] finished!

Importing the Backup File

  1. Import the RDB file (or files) to the cloud server. The cloud server must be connected to the target DCS instance.
  2. Edit the redis-shake.conf file by providing the following information about all the masters of the target:
    vim redis-shake.conf
    The modification is as follows:
    target.type = cluster
    # If there is no password, skip the following parameter.
    target.password_raw = {target_redis_password}
    # IP addresses and port numbers of all masters of the target instance, which are separated by semicolons (;).
    target.address = {master1_ip}:{master1_port};{master2_ip}:{master2_port}...{masterN_ip}:{masterN_port}
    # List the RDB files to be imported, separated by semicolons (;).
    rdb.input = {local_dump.0};{local_dump.1};{local_dump.2};{local_dump.3}

    Press Esc to exit the editing mode and enter :wq!. Press Enter to save the configuration and exit the editing interface.

  3. Run the following command to import the RDB file to the target instance:
    ./redis-shake -type restore -conf redis-shake.conf

    If the following information is displayed in the execution log, the backup file is imported successfully:

    Enabled http stats, set status (incr), and wait forever.

Verifying the Migration

  1. After the data synchronization, connect to the Redis Cluster DCS instance by referring to redis-cli.
  2. Run the info command to check whether the data has been successfully imported as required.

    If the data has not been fully imported, run the flushall or flushdb command to clear the cached data in the target instance, and migrate data again.

  3. After the verification is complete, delete the redis shake configuration file.