You can use Data Transmission Service (DTS) to perform one-way synchronization between ApsaraDB for Redis cluster instances (Redis instances in short) that belong to different Alibaba Cloud accounts. The data synchronization feature is applicable to scenarios such as resource migration or resource merging across Alibaba Cloud accounts and business architecture adjustment.

Prerequisites

  • If the source Redis instance is a Community Edition instance, the engine version must be 4.0 or 5.0. If the source Redis instance is an Enhanced Edition instance, the engine version must be 5.0.
    Note The engine version of the destination Redis instance can be 4.0 or 5.0. The engine version of the destination Redis instance cannot be earlier than the engine version of the source Redis instance. Before you synchronize data between two Redis instances that use different engine versions, check the compatibility of the two versions. For example, you can create a destination Redis instance based on the pay-as-you-go billing method to verify the compatibility between the source and destination instances. Then, you can release this instance or change the billing method of the instance to subscription.
  • The source Redis instance is deployed in a virtual private cloud (VPC). If the source instance is deployed in the classic network, you can change the network type to VPC. For more information, see Change the network type from classic network to VPC.
  • Secure Sockets Layer (SSL) encryption is disabled for the source Redis instance. For more information, see Configure SSL encryption for an ApsaraDB for Redis instance.
  • The available storage space of the destination Redis instance is larger than the total size of the data in the source Redis instance.
  • ApsaraDB for Redis Enhanced Edition (Tair) is integrated with more Redis modules than ApsaraDB for Redis Community Edition. For more information, see Integration of multiple Redis modules. To ensure compatibility between the source and destination instances, the edition of the destination instance must be Enhanced if the edition of the source instance is Enhanced.
  • The source instance is not an ApsaraDB for Redis Enhanced Edition instance (storage-optimized instance).
  • The disk type of the source or destination ApsaraDB for Redis instance is local disk rather than cloud disk.

Background information

Two Redis instances are created by different Alibaba Cloud accounts. You need to migrate data from the instance of Account A to the instance of Account B. The following figure shows the architecture of the migration solution. Data migration between Redis instances of different accounts
Notice To synchronize data between Redis instances of different accounts, note that the source and destination instances must be deployed in the cluster or standard architecture. In this scenario, the read/write splitting architecture is not supported.

DTS provides the following data migration solution:

You cannot use the data migration feature to migrate data between ApsaraDB for Redis cluster instances. In this solution, the data synchronization feature of DTS is used to synchronize data to the destination instance. The following table describes how to configure a data synchronization task.

Step Description
1. Use Account A to log on to the Alibaba Cloud Management Console and grant the required permission to a RAM role. For more information, see Step 1 in Before you begin. When you configure the RAM role, set Account B as the trusted account, and authorize the RAM role to access the resources of Account A.
2. Use Account A to log on to the Alibaba Cloud Management Console and prepare the environment that is required for the source Redis instance. For more information, see Steps 2 to 4 in Before you begin. Add the CIDR blocks of DTS servers to the whitelist of the source Redis instance. Apply for a private endpoint for the source Redis instance, and create a database account that is authorized to replicate the data of the source Redis instance.
Note By default, you are not allowed to create a database account that is authorized to replicate the data of an ApsaraDB for Redis cluster instance. To do this, submit a ticket.
3. Use Account B to log on to the Alibaba Cloud Management Console and configure the data synchronization task. For more information, see Procedure. DTS cannot read the information of source Redis instance across Alibaba Cloud accounts. When you configure the data synchronization task, you must specify the source instance as a self-managed database that is connected to DTS over Express Connect.

Precautions

  • DTS uses the resources of the source and destination databases during full data synchronization. This may increase the loads of the database servers. If you synchronize a large volume of data or the server specifications cannot meet your requirements, the database services may become unavailable. Before you synchronize data, evaluate the impact of data synchronization on the performance of the source and destination databases. We recommend that you synchronize data during off-peak hours.
  • We recommend that you do not run the FLUSHDB or FLUSHALL command on the source instance during data synchronization. If you run one of the two commands, data may become inconsistent between the source and destination instances.
  • If the data eviction policy (maxmemory-policy) of the destination database is not set to noeviction, data may become inconsistent between the source and destination databases. For more information about data eviction policies, see How does ApsaraDB for Redis evict data by default?
  • If an expiration policy is enabled for some keys in the source database, these keys may not be deleted in a timely manner after they expired. Therefore, the number of keys in the destination database may be less than that in the source database. You can run the info command to view the number of keys in the destination database.
    Note The number of keys that do not have an expiration policy or have not expired is the same in the source and destination databases.
  • During data synchronization, if the number of shards in the source ApsaraDB for Redis instance is increased or decreased, or if the database specifications are changed (for example, the memory capacity is scaled up), you must reconfigure the task. To ensure data consistency, we recommend that you clear the data that has been synchronized to the destination Redis database before you reconfigure the task.
  • During data synchronization, if the endpoint of the source ApsaraDB for Redis instance is changed (for example, the zone of the instance is changed or the network type is changed from classic network to VPC), you must submit a ticket to update the change. Otherwise, the append-only files (AOF) of the source ApsaraDB for Redis instance may be reset. In this case, you must reconfigure the task.

Operations that can be synchronized

Edition Operation
ApsaraDB for Redis Community Edition
  • APPEND
  • BITOP, BLPOP, BRPOP, and BRPOPLPUSH
  • DECR, DECRBY, and DEL
  • EVAL, EVALSHA, EXEC, EXPIRE, and EXPIREAT
  • GEOADD and GETSET
  • HDEL, HINCRBY, HINCRBYFLOAT, HMSET, HSET, and HSETNX
  • INCR, INCRBY, and INCRBYFLOAT
  • LINSERT, LPOP, LPUSH, LPUSHX, LREM, LSET, and LTRIM
  • MOVE, MSET, MSETNX, and MULTI
  • PERSIST, PEXPIRE, PEXPIREAT, PFADD, PFMERGE, and PSETEX
  • RENAME, RENAMENX, RESTORE, RPOP, RPOPLPUSH, RPUSH, and RPUSHX
  • SADD, SDIFFSTORE, SELECT, SET, SETBIT, SETEX, SETNX, SETRANGE, SINTERSTORE, SMOVE, SPOP, SREM, and SUNIONSTORE
  • ZADD, ZINCRBY, ZINTERSTORE, ZREM, ZREMRANGEBYLEX, ZUNIONSTORE, ZREMRANGEBYRANK, and ZREMRANGEBYSCORE
  • SWAPDB and UNLINK (supported only if the engine version of the source Redis instance is 4.0)
ApsaraDB for Redis Enhanced Edition (Tair)
  • APPEND
  • BITOP, BLPOP, BRPOP, and BRPOPLPUSH
  • DECR, DECRBY, and DEL
  • EVAL, EVALSHA, EXEC, EXPIRE, and EXPIREAT
  • GEOADD and GETSET
  • HDEL, HINCRBY, HINCRBYFLOAT, HMSET, HSET, and HSETNX
  • INCR, INCRBY, and INCRBYFLOAT
  • LINSERT, LPOP, LPUSH, LPUSHX, LREM, LSET, and LTRIM
  • MOVE, MSET, MSETNX, and MULTI
  • PERSIST, PEXPIRE, PEXPIREAT, PFADD, PFMERGE, and PSETEX
  • RENAME, RENAMENX, RPOP, RPOPLPUSH, RPUSH, and RPUSHX
  • SADD, SDIFFSTORE, SELECT, SET, SETBIT, SETEX, SETNX, SETRANGE, SINTERSTORE, SMOVE, SPOP, SREM, and SUNIONSTORE
  • UNLINK, ZADD, ZINCRBY, ZINTERSTORE, ZREM, ZREMRANGEBYLEX, ZUNIONSTORE, ZREMRANGEBYRANK, and ZREMRANGEBYSCORE
Note
  • If you run the EVAL or EVALSHA command to call Lua scripts, DTS cannot identify whether these Lua scripts are executed on the destination database. During incremental data synchronization, the destination database does not explicitly return the execution results of Lua scripts.
  • When DTS calls the SYNC or PSYNC command to transfer data of the LIST type, DTS does not clear the existing data. In this case, the destination database may contain duplicate data records.

Before you begin

Use the Alibaba Cloud account that owns the source Redis instance to log on to the Alibaba Cloud Management Console. Then, perform the following steps:

  1. Create a RAM role and authorize the RAM role to access the resources of the Alibaba Cloud account. For more information, see Configure RAM authorization for data migration or synchronization from a user-created database in a VPC across different Alibaba Cloud accounts.
  2. Apply for a private endpoint for the source Redis instance. For more information, see Enable the direct connection mode.
  3. Select the CIDR blocks of the DTS servers that are deployed in the region of the source Redis instance. Add these CIDR blocks to the whitelist of the source Redis instance. For more information, see Step 2: Set IP address whitelists.
    Note For more information about the CIDR blocks of the DTS servers in each region, see Add the CIDR blocks of DTS servers to the security settings of on-premises databases.
  4. Create a database account for the source Redis instance.
    1. Submit a ticket to create a database account that is authorized to replicate the data of your ApsaraDB for Redis cluster instance.
      Note By default, you are not allowed to create a database account that is authorized to replicate the data of an ApsaraDB for Redis cluster instance. To do this, submit a ticket.
    2. Create a database account that is authorized to replicate data of the source instance. For more information, see Create and manage database accounts.

Procedure

  1. Use the Alibaba Cloud account that owns the destination Redis instance to log on to the Alibaba Cloud Management Console. Then, purchase a data synchronization instance. For more information, see Purchase a DTS instance.
    Note On the buy page, set the following parameters:
    • Set Source Instance to Redis, set Destination Instance to Redis, and set Synchronization Topology to One-way Synchronization.
    • Set the Source Region parameter based on the region where the source Redis instance resides, and set the Destination Region parameter based on the region where the destination Redis instance resides.
  2. Log on to the DTS console.
  3. In the left-side navigation pane, click Data Synchronization.
  4. At the top of the Synchronization Tasks page, select the region where the destination instance resides.
    Select a region
  5. Find the data synchronization instance and click Configure Synchronization Channel in the Actions column.
  6. Configure the source and destination instances.
    1. Optional:Specify an informative task name for easy identification. You do not need to specify a unique task name.
    2. Select User-Created Database Connected over Express Connect, VPN Gateway, or Smart Access Gateway as the instance type. Then, click VPC of Another Alibaba Cloud Account next to the Peer VPC field.
      Note DTS cannot read the information of source Redis instance across Alibaba Cloud accounts. When you configure the data synchronization task, you must specify the source instance as a self-managed database that is connected to DTS over Express Connect.
      Select the VPC of another Alibaba Cloud account
    3. Configure the source instance.
      Configure the source instance
      Parameter Description
      Instance Type Select User-Created Database Connected over Express Connect, VPN Gateway, or Smart Access Gateway.
      Instance Region The source region that you selected on the buy page. You cannot change the value of this parameter.
      Alibaba Cloud Account ID Enter the ID of the Alibaba Cloud account that owns the source Redis instance.
      Note To obtain the ID of the Alibaba Cloud account that owns the source Redis instance, you must log on to the Account Management console by using this account. The account ID is displayed on the Security Settings page.
      Obtain an Alibaba Cloud account ID
      Role Name Enter the name of the RAM role that you created in Step 1 of Before you begin.
      Peer VPC Select the VPC where the source Redis instance is deployed.
      Database Type Select Redis.
      Instance Mode Select Cluster.
      IP Address Enter the IP address corresponding to the private endpoint that you obtained for the source Redis instance in Step 2 of Before you begin. In this example, enter 192.168.0.153.
      Note To obtain the IP address corresponding to the private endpoint of your source Redis instance, run the ping command, for example, ping r-********.redis.rds.aliyuncs.com.
      Port Number Enter the service port number of the source Redis instance.
      Database Password Enter the password of the account that you created in Step 4 of Before you begin. This account is authorized to replicate the data of the source Redis instance.
      Note The database password is in the <user>:<password> format. For example, if the username of a custom account is admin and the password is Rp829dlwa, the database password is admin:Rp829dlwa.
    4. Configure the destination instance.
      Configure the destination instance
      Parameter Description
      Instance Type Select Redis Instance.
      Instance Region The destination region that you selected on the buy page. You cannot change the value of this parameter.
      Instance ID Select the ID of the destination Redis instance.
      Database Password Enter the database password of the destination Redis instance. The account must have the read and write permissions on the destination database.
      Note The database password is in the <user>:<password> format. For example, if the username of a custom account is admin and the password is Rp829dlwa, the database password is admin:Rp829dlwa.
  7. In the lower-right corner of the page, click Set Whitelist and Next.
    Note In this step, DTS adds the CIDR blocks of DTS servers to the whitelist of the destination Redis instance. This ensures that the DTS servers can connect to the source and destination Redis instances.
  8. Select the processing mode of conflicting tables, and the objects to be synchronized.
    Select the objects to be synchronized
    Setting Description
    Select the processing mode of conflicting tables
    • Pre-check and Intercept: checks whether the destination database is empty. If the destination database is empty, the precheck is passed. If the database is not empty, an error is returned during the precheck and the data synchronization task cannot be started.
    • Ignore: skips the check for empty destination databases.
      Warning If you select Ignore, the data records in the source database overwrite the data records that have the same keys in the destination database. Proceed with caution.
    Select the objects to be synchronized
    • Select one or more databases from the Available section and click the icon to move the databases to the Selected section.
    • You can select only databases as the objects to be synchronized. You cannot select keys as the objects to be synchronized.
  9. In the lower-right corner of the page, click Next.
  10. Select the initial synchronization types.
    Select the initial synchronization types
    Note
    • The value is set to Include full data + incremental data. DTS synchronizes historical data of the source Redis instance to the destination Redis instance and then synchronizes incremental data.
    • If a version-related error message appears, you can upgrade the source ApsaraDB for Redis instance to a specified version. For more information, see Upgrade the major version and Update the minor version.
  11. In the lower-right corner of the page, click Precheck.
    Note
    • Before you can start the data synchronization task, DTS performs a precheck. The data synchronization task can be started only after it passes the precheck.
    • If the task fails to pass the precheck, you can click the Info icon icon next to each failed item to view details.
      • You can troubleshoot the issues based on the causes and run a precheck again.
      • If you do not need to troubleshoot the issues, you can ignore failed items and run a precheck again.
  12. Close the Precheck dialog box after the following message is displayed: The precheck is passed. Then, the data synchronization task starts.
  13. Wait until initial synchronization is completed and the data synchronization task is in the Synchronizing state.
    Status of the data synchronization task
    Note You can view the status of the data synchronization task on the Synchronization Tasks page.