You can restore data from RDB files by using redis-shake in restore mode. This allows you to migrate the data of a self-managed Redis instance to an ApsaraDB for Redis instance on Alibaba Cloud.

Prerequisites

  • An ApsaraDB for Redis instance is created as the destination of data migration.
  • An Elastic Compute Service (ECS) instance is created to run the redis-shake tool.
  • The ECS instance can access the destination ApsaraDB for Redis instance.
  • The ECS instance runs Linux.
  • A Redis database backup (RDB) file is stored on the ECS instance.

Background

Redis-shake is an open source tool developed by Alibaba Cloud. You can use it to parse (decode mode), recover (restore mode), back up (dump mode), and synchronize (sync or rump mode) Redis data. In restore mode, you can use redis-shake to restore or migrate data from RDB files. This topic describes how to restore data from an RDB file to an ApsaraDB for Redis instance. This way, you can migrate a self-managed Redis instance to Alibaba Cloud.

Note For more information about the redis-shake tool, see redis-shake on GitHub or FAQ.

Procedure

  1. Log on to the ECS instance that can access the ApsaraDB for Redis instance.
  2. Download redis-shake to the ECS instance.
    Note We recommend that you download the latest version of redis-shake.
  3. Run the following command to decompress the downloaded redis-shake.tar.gz package:
    tar -xvf redis-shake.tar.gz
    Note The decompressed redis-shake file is a binary file that is executable in the 64-bit Linux operating system. The redis-shake.conf file is the configuration file of redis-shake. You must modify this configuration file.
  4. Modify the redis-shake.conf file. The following table describes the parameters for the restore mode of redis-shake.
    Table 1. Parameters for the restore mode of redis-shake
    Parameter Description Example
    rdb.input The path of the RDB file. You can specify a relative path or an absolute path. /root/tools/RedisShake/demo.rdb
    target.address The endpoint and port of the ApsaraDB for Redis instance. r-bp1xxxxxxxxxxxxx.redis.rds.aliyuncs.com:6379
    target.password_raw The password of the ApsaraDB for Redis instance. TargetPass233
    Note If you use a database account other than the default database account to connect to the ApsaraDB for Redis instance, set this parameter in the following format: account:password.
    target.db Specifies whether to migrate data from all databases in the source ApsaraDB for Redis instance to the specified database in the destination ApsaraDB for Redis instance. Valid values:
    • -1: disables this feature. This is the default value.
    • 0 to 255: enables this feature. The value specifies the destination database in the destination ApsaraDB for Redis instance. For example, a value of 0 indicates that the data of all databases in the source ApsaraDB for Redis instance is migrated to database 0 in the destination ApsaraDB for Redis instance.
    Note If the source ApsaraDB for Redis instance uses the master-replica architecture and the destination ApsaraDB for Redis instance uses the cluster architecture, only database 0 is synchronized in this scenario. Data from other databases is not migrated. Set this parameter to 0 to migrate all the databases from the source ApsaraDB for Redis instance to database 0 in the destination ApsaraDB for Redis instance.
    -1
    rewrite Specifies whether to overwrite the existing keys in ApsaraDB for Redis that are the same as those in the RDB file. Valid values:
    • true: overwrites the existing keys.
    • false: does not overwrite the existing keys.
    Note Default value: true. We recommend that you back up the valid data in ApsaraDB for Redis before you migrate data. If you set this parameter to false and a key exists in both the source and destination databases, an error message is returned.
    true
    parallel The number of concurrent threads used to restore the RDB file. More concurrent threads improve the synchronization performance.
    Note
    • Minimum value: 1.
    • Maximum value: depends on the server performance.
    • We recommend that you set the parameter to 64.
    64
    Note You can use the default values of other parameters unless otherwise specified.
  5. Run the following command to migrate data:
    ./redis-shake.linux -type=restore -conf=redis-shake.conf
    Note You must run this command in the directory where the redis-shake and redis-shake.conf files are stored. Otherwise, you must specify the correct file path in the command.
    Figure 1. Migration example
    Note When restore: rdb done is printed in the log, the data is restored. You can press Ctrl+C to exit the tool.