Data Transmission Service (DTS) supports one-way data synchronization between two Redis databases. This feature is applicable to scenarios such as active geo-redundancy and geo-disaster recovery. This topic describes how to synchronize data from a self-managed Redis database connected over Express Connect, VPN Gateway, or Smart Access Gateway to a self-managed Redis database hosted on Elastic Compute Service (ECS).

Warning After you configure a data synchronization task, do not change the architecture type of the source or destination database. For example, if you change the master-replica architecture to the cluster architecture, data synchronization fails.

Prerequisites

  • The version of the source Redis database is 2.8, 3.0, 3.2, 4.0, or 5.0.
    Note The version of the destination Redis database can be 2.8, 3.0, 3.2, 4.0, or 5.0. The version of the destination database must be the same as or later than the version of the source database. If you synchronize data between different versions of Redis databases, make sure that the versions of the source and destination databases are compatible.
  • The available storage space of the destination Redis database is larger than the total size of the data in the source Redis database.
  • If the source Redis database is deployed in a cluster architecture, all nodes of the Redis cluster must support the PSYNC command and share the same password.

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.
  • 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.
  • If the bind parameter is configured in the redis.conf file of the source database, you must set the value of this parameter to the internal IP address of the ECS instance. The setting ensures that DTS can connect to the source database.
  • To ensure the stability of data synchronization, we recommend that you increase the value of the repl-backlog-size parameter in the redis.conf file of the source Redis database.
  • To ensure the synchronization quality, DTS adds the following key to the source Redis database: DTS_REDIS_TIMESTAMP_HEARTBEAT. This key is used to record the time when data is synchronized to ApsaraDB for Redis.
  • We recommend that you do not run the FLUSHDB or FLUSHALL command in the source database during data synchronization. Otherwise, data may become inconsistent between the source and destination databases.
  • 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?
  • During data synchronization, if the number of shards in the self-managed Redis database is increased or decreased, or if the specifications of the database 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 self-managed Redis database is changed, you must submit a ticket to update the change. Otherwise, the append-only files (AOF) of the self-managed Redis database may be reset. In this case, you must reconfigure the task.

Supported synchronization topologies

  • One-way one-to-one synchronization
  • One-way one-to-many synchronization
  • One-way cascade synchronization

For more information, see Synchronization topologies.

Operations that can be synchronized

  • 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 database version of the source ApsaraDB for Redis instance is 4.0)
Note
  • PUBLISH operations cannot be synchronized.
  • 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.

Procedure

  1. Purchase a data synchronization instance. For more information, see Purchase a data synchronization instance.
    Note On the buy page, set both Source Instance and Destination Instance to Redis.
  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.
  5. Find the data synchronization instance and click Configure Synchronization Channel in the Actions column.
  6. Configure the source and destination instances. Configure the source and destination instances
    Section Parameter Description
    N/A Synchronization Task Name DTS automatically generates a task name. We recommend that you specify an informative name for easy identification. You do not need to use a unique task name.
    Source Instance Details 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.
    Peer VPC Select the ID of the virtual private cloud (VPC) that is connected to the self-managed Redis database.
    Database Type The value of this parameter is set to Redis.
    Instance Mode Select Standalone or Cluster based on the architecture of the source Redis database.
    IP Address Enter the server IP address of the source Redis database.
    Note If the source Redis database is deployed in a cluster architecture, enter the IP address of the server to which a master node belongs.
    Port Number Enter the service port number of the source Redis database. The default port number is 6379.
    Note If the source Redis database is deployed in a cluster architecture, enter the service port number of a master node.
    Database Password Enter the password of the source Redis database.
    Note This parameter is optional and can be left blank if no database password is set.
    Destination Instance Details Instance Type Select User-Created Database in ECS 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 ECS instance that hosts the destination Redis database.
    Note If the destination Redis database is deployed in a cluster architecture, select the ID of the ECS instance where a master node resides.
    Instance Mode Select Standalone or Cluster based on the architecture of the destination Redis database.
    Port Number Enter the service port number of the destination Redis database. The default port number is 6379.
    Note If the destination Redis database is deployed in a cluster architecture, enter the service port number of a master node.
    Database Password Enter the password of the destination Redis database.
    Note This parameter is optional and can be left blank if no database password is set.
  7. In the lower-right corner of the page, click Set Whitelist and Next.
    Note DTS adds the CIDR blocks of DTS servers to an inbound rule of the destination ECS instance. This ensures that DTS servers can connect to the destination ECS instance.
  8. Select the processing mode of conflicting tables, and the objects to be synchronized. Select the processing mode and 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.
    Rename Databases and Tables

    You can use the object name mapping feature to rename the objects that are synchronized to the destination instance. For more information, see Object name mapping.

    Replicate Temporary Tables When DMS Performs DDL Operations
    If you use Data Management (DMS) to perform online DDL operations on the source database, you can specify whether to synchronize temporary tables generated by online DDL operations.
    • Yes: DTS synchronizes the data of temporary tables generated by online DDL operations.
      Note If online DDL operations generate a large amount of data, the data synchronization task may be delayed.
    • No: DTS does not synchronize the data of temporary tables generated by online DDL operations. Only the original DDL data of the source database is synchronized.
      Note If you select No, the tables in the destination database may be locked.
    Retry Time for Failed Connections
    By default, if DTS fails to connect to the source or destination database, DTS retries within the next 720 minutes (12 hours). You can specify the retry time based on your needs. If DTS reconnects to the source and destination databases within the specified time, DTS resumes the data synchronization task. Otherwise, the data synchronization task fails.
    Note When DTS retries a connection, you are charged for the DTS instance. We recommend that you specify the retry time based on your business needs. You can also release the DTS instance at your earliest opportunity after the source and destination instances are released.
  9. In the lower-right corner of the page, click Next.
  10. Select the initial synchronization types. The value is set to Include full data + incremental data. Select the initial synchronization types
    Note
    • DTS synchronizes historical data from the source ApsaraDB for Redis instance to the destination ApsaraDB for Redis instance. Then, DTS 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. You can start the data synchronization task only after the task 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 appears: 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.