All Products
Search
Document Center

Tair (Redis® OSS-Compatible):Use AOFs to migrate data

Last Updated:Apr 10, 2024

redis-cli is a built-in CLI that is native to Redis. You can use redis-cli to migrate data that is saved to an append-only file (AOF) from a self-managed Redis database to an ApsaraDB for Redis instance. This solution features flexibility, efficiency, and automation, and ensures the consistency and integrity of the data being migrated. However, this solution does not support real-time synchronization, but supports only the migration of offline data.

We recommend that you perform data migration during a planned downtime or make sure that no new data is written during the migration process.

Note

redis-cli is a terminal program that sends commands to and reads replies from the Redis server. redis-cli is not designed to handle complex online migration scenarios. If you want to perform online real-time migration, you can use Data Transmission Service (DTS). For more information, see Use DTS to migrate data from a self-managed Redis database to an ApsaraDB for Redis instance.

Prerequisites

  • The IP address of your client is added to a whitelist of the ApsaraDB for Redis instance. For more information, see Configure whitelists.

  • AOF persistence is enabled for the self-managed Redis instance. If AOF persistence is disabled for the instance, run the CONFIG SET appendonly yes command to enable AOF persistence.

  • Hybrid persistence is disabled for the self-managed Redis instance. If the major version of the self-managed instance is Redis 5.0 or later, run the CONFIG SET aof-use-rdb-preamble no command to disable hybrid persistence.

Procedure

  1. Connect to the self-managed Redis instance and manually trigger an AOF rewrite to save the latest AOF.

    redis-cli -h <IP address of the self-managed Redis instance> -p <Port number>  BGREWRITEAOF

    Expected output: Background append only file rewriting started

  2. Use the AOF to import data to a new ApsaraDB for Redis instance. In this example, the AOF named appendonly.aof is used.

    redis-cli -h <IP address of the ApsaraDB for Redis instance> -p <Port number>  -a <Instance password> --pipe < appendonly.aof

    Example: redis-cli -h r-bp1zxszhcgatnx****.redis.rds.aliyuncs.com -p 6379 -a user:password --pipe < appendonly.aof

    Expected output:

    All data transferred. Waiting for the last reply...
    Last reply received from server.
    errors: 0, replies: 90

    If a message similar to the preceding one is returned, the migration is successful.

What to do next

If the self-managed Redis instance does not require AOF persistence to be enabled all the time, run the following command to disable AOF persistence after data is imported:

redis-cli -h <IP address of the self-managed Redis instance> -p <Port number of the self-managed Redis instance> CONFIG SET appendonly no

FAQ

  • What do I do if the ERR Protocol error: too big inline request error message is returned when I import data?

    Run the CONFIG GET aof-use-rdb-preamble command to check whether the aof-use-rdb-preamble parameter of the instance is set to yes. If the parameter is set to yes, run the CONFIG SET aof-use-rdb-preamble no command to set the parameter to no. Trigger an AOF rewrite and then import the data again.

    Note

    If you set the aof-use-rdb-preamble parameter to yes, some data in the AOF is compressed and cannot be parsed or imported by using redis-cli commands.