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 a Tair (Redis OSS-compatible) 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.
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 a Tair (Redis OSS-compatible) instance.
Prerequisites
The IP address of your client is added to a whitelist of the Tair (Redis OSS-compatible) instance. For more information, see Configure whitelists.
Append-only file (AOF) persistence is enabled for the self-managed Redis instance. If this feature is not enabled, run the
CONFIG SET appendonly yescommand to enable it.Hybrid persistence is disabled for the self-managed Redis instance. If the self-managed instance is Redis 5.0 or later, run the
CONFIG SET aof-use-rdb-preamble nocommand to disable hybrid persistence.
Procedure
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> BGREWRITEAOFExpected output:
Background append only file rewriting startedUse the AOF to import data to a new Tair (Redis OSS-compatible) instance. In this example, the AOF named appendonly.aof is used.
redis-cli -h <IP address of the Tair (Redis OSS-compatible) instance> -p <Port number> -a <Instance password> --pipe < appendonly.aofExample:
redis-cli -h r-bp1zxszhcgatnx****.redis.rds.aliyuncs.com -p 6379 -a user:password --pipe < appendonly.aofExpected output:
All data transferred. Waiting for the last reply... Last reply received from server. errors: 0, replies: 90If 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 noFAQ
Q: What should I do if the
ERR Protocol error: too big inline requesterror is reported during import?Run the
CONFIG GET aof-use-rdb-preamblecommand to check whether theaof-use-rdb-preambleparameter of the instance is set toyes. If the parameter is set toyes, run theCONFIG SET aof-use-rdb-preamble nocommand to set the parameter tono. Then, regenerate the AOF file and retry.NoteIf the
aof-use-rdb-preambleparameter is set toyes, some data in the AOF file is compressed. This compressed data cannot be parsed or imported by the redis-cli command.How do I export AOFs from Tair (Redis OSS-compatible) instances?
Tair (Redis OSS-compatible) instances do not support the export of AOFs.
Q: Why does the data import fail with an
ERR syntax error?If the version of the Tair (Redis OSS-compatible) instance is earlier than the version of the self-managed Redis instance, this issue may occur. Purchase a Tair (Redis OSS-compatible) instance of the same version or later than the self-managed Redis instance. For example, if both the self-managed Redis instance and the Tair (Redis OSS-compatible) instance are compatible with Redis 7.0, this error does not occur.