This topic describes how to migrate data from a self-managed Redis database to an ApsaraDB for Redis instance by using Data Transmission Service (DTS). DTS supports full data migration and incremental data migration. When you migrate data from a self-managed Redis database to Alibaba Cloud, you can select the two migration types to ensure service continuity.

Prerequisites

  • The version of the self-managed Redis database is 2.8, 3.0, 3.2, 4.0, 5.0, or 6.0.
  • The self-managed Redis database is deployed in the standalone architecture rather than the cluster architecture.
    Note If the self-managed Redis database is deployed in the cluster architecture, you can migrate data by using the data synchronization feature. For more information, see Synchronize data from a self-managed Redis cluster to an ApsaraDB for Redis cluster instance.
  • The PSYNC or SYNC command can be run on the self-managed Redis database.
  • The available storage space of the destination ApsaraDB for Redis database is larger than the total size of the data in the self-managed Redis database.

Precautions

  • DTS consumes the resources of the source and destination databases during full data migration. This may increase the loads of the database servers. If you migrate a large volume of data or the server specifications cannot meet your requirements, database services may become unavailable. Before you migrate data, evaluate the impact of data migration on the performance of the source and destination databases. We recommend that you migrate data during off-peak hours.
  • 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.
  • 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 migration, the destination database does not explicitly return the execution results of Lua scripts.
  • When you run the PSYNC or SYNC command to transfer data of the LIST type, DTS does not perform the flush operation on the existing data. Therefore, the destination database may contain duplicate data records.
  • During data migration, 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 migrated to the destination Redis database before you reconfigure the task.
  • During data migration, 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.
  • If a data migration task fails, DTS automatically resumes the task. Before you switch your workloads to the destination instance, stop or release the data migration task. Otherwise, the data in the source database will overwrite the data in the destination instance after the task is resumed.

Billing

Migration type Task configuration fee Internet traffic fee
Schema migration and full data migration Free of charge. Charged only when data is migrated from Alibaba Cloud over the Internet. For more information, see Pricing.
Incremental data migration Charged. For more information, see Pricing.

Migration types

  • Full data migration
    DTS migrates historical data of the required objects from the self-managed Redis database to the destination ApsaraDB for Redis instance.
    Note To ensure data consistency, we recommend that you do not write data to the self-managed Redis database during full data migration.
  • Incremental data migration

    After full data migration is complete, DTS synchronizes incremental data from the self-managed Redis database to the destination ApsaraDB for Redis instance. Incremental data migration allows you to ensure service continuity when you migrate data from a self-managed Redis database to Alibaba Cloud.

Operations that can be synchronized during incremental data migration

  • APPEND
  • BITOP, BLPOP, BRPOP, and BRPOPLPUSH
  • DECR, DECRBY, and DEL
  • EVAL, EVALSHA, EXEC, EXPIRE, and EXPIREAT
  • FLUSHALL and FLUSHDB
  • 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, PSETEX, and PUBLISH
  • 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

Preparations before incremental data migration

To ensure that the incremental data migration task runs as expected, we recommend that you remove the limit on the replication output buffer. This topic uses a server that runs on Linux as an example.

Note If you perform only full data migration, skip the following steps.
  1. Use the redis-cli program to connect to the self-managed Redis database.
    Note You can use the redis-cli program after you install the Redis client. For more information, visit Redis community official website.
    redis-cli -h <host> -p <port> -a <password>
    Note
    • <host>: the endpoint that is used to connect to the self-managed Redis database. You can use 127.0.0.1 in this example.
    • <port>: the service port number of the self-managed Redis database. The default port number is 6379.
    • <password>: the password of the self-managed Redis database.

    Example:

    redis-cli -h 127.0.0.1 -p 6379 -a Test123456
  2. Run the following command to remove the limit on the replication output buffer:
    config set client-output-buffer-limit 'slave 0 0 0'

Procedure

  1. Log on to the DTS console.
  2. In the left-side navigation pane, click Data Migration.
  3. At the top of the Migration Tasks page, select the region where the destination instance resides. Select a region
  4. In the upper-right corner of the page, click Create Migration Task.
  5. Configure the source and destination databases. Configure the source and destination databases
    Section Parameter Description
    N/A 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 Database Instance Type Select an instance type based on the deployment of the source database. In this example, select User-Created Database with Public IP Address.
    Note If you select other instance types, you must deploy the network environment for the source database. For more information, see Preparation overview.
    Instance Region If you select User-Created Database with Public IP Address as the instance type, you do not need to specify the Instance Region parameter.
    Note If a whitelist is configured for the self-managed Redis database, you must add the CIDR blocks of DTS servers to the whitelist of the database. You can click Get IP Address Segment of DTS next to Instance Region to obtain the CIDR blocks of DTS servers.
    Database Type Select Redis.
    Instance Mode The value of this parameter is set to Standalone and cannot be changed to Cluster.
    Hostname or IP Address Enter the endpoint that is used to connect to the self-managed Redis database. In this example, enter the public IP address.
    Port Number Enter the service port number of the self-managed Redis database. The default port number is 6379.
    Note The service port of the self-managed Redis database must be accessible over the Internet.
    Database Password Enter the password of the self-managed Redis database.
    Note After you specify the source database parameters, click Test Connectivity next to Database Password to verify whether the specified parameters are valid. If the specified parameters are valid, the Passed message appears. If the Failed message appears, click Check next to Failed. Modify the source database parameters based on the check results.
    Destination Database Instance Type Select Redis Instance.
    Instance Region Select the region where the destination ApsaraDB for Redis instance resides.
    Redis Instance ID Select the ID of the destination ApsaraDB for Redis instance.
    Database Password Enter the database password of the destination ApsaraDB for Redis instance.
    Note After you specify the destination database parameters, click Test Connectivity next to Database Password to verify whether the parameters are valid. If the specified parameters are valid, the Passed message appears. If the Failed message appears, click Check next to Failed. Modify the destination database parameters based on the check results.
  6. In the lower-right corner of the page, click Set Whitelist and Next.
    Note DTS adds the CIDR blocks of DTS servers to the whitelist of the destination ApsaraDB for Redis instance. This ensures that DTS servers can connect to the destination ApsaraDB for Redis instance.
  7. Select the migration types and the objects to be migrated. Select the migration types and the objects to be migrated
    Setting Description
    Select the migration types
    • To perform only full data migration, select only Full Data Migration.
    • To ensure service continuity during data migration, select Full Data Migration and Incremental Data Migration.
    Note If Incremental Data Migration is not selected, we recommend that you do not write data to the self-managed Redis database during data migration. This ensures data consistency between the source and destination databases.
    Select the objects to be migrated

    Select one or more objects from the Available section and click the Rightwards arrow icon to move the objects to the Selected section.

    Note You can select only databases as the objects to be migrated.
    Specify whether to rename objects You can use the object name mapping feature to rename the objects that are migrated to the destination instance. For more information, see Object name mapping.
    Specify the retry time for failed connections to the source or destination database By default, if DTS fails to connect to the source or destination database, DTS retries within the next 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 migration task. Otherwise, the data migration 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.
  8. Click Precheck.
    Note
    • A precheck is performed before the migration task starts. The migration task only starts after the precheck succeeds.
    • If the precheck fails, click the Note icon next to each failed check item to view the related details. Fix the issues as instructed and run the precheck again.
  9. After the task passes the precheck, click Next.
  10. In the Confirm Settings dialog box, specify the Channel Specification parameter and select Data Transmission Service (Pay-As-You-Go) Service Terms.
  11. Click Buy and Start to start the data migration task.
    • Full data migration

      We recommend that you do not manually stop the task during full data migration. Otherwise, the data migrated to the destination instance will be incomplete. You can wait until the data migration task automatically stops.

    • Incremental data migration

      The task does not automatically stop during incremental data migration. You must manually stop the task.

      Note We recommend that you select an appropriate time to manually stop the data migration task. For example, you can stop the task during off-peak hours or before you switch your workloads to the destination instance.
      1. Wait until Incremental Data Migration and The migration task is not delayed appear in the progress bar of the migration task. Then, stop writing data to the source database for a few minutes. The delay time of incremental data migration may be displayed in the progress bar.
      2. After the status of incremental data migration changes to The migration task is not delayed again, manually stop the migration task. The migration task is not delayed
  12. Switch your workloads to the destination ApsaraDB for Redis instance.

What to do next

The database accounts that are used for data migration have the read and write permissions. After the data migration task is completed, you must change the passwords of the self-managed Redis database and the ApsaraDB for Redis instance to ensure database security.