You can use the restore mode of the redis-shake tool to migrate data from ApsaraDB for Redis to on-premises Redis through a backup file.
- An on-premises Redis instance is created as the destination of data migration.
- The 64-bit Linux operating system is running on the server for running the redis-shake tool.
- The Linux server can access the on-premises Redis instance.
- The data of the source ApsaraDB for Redis instance is backed up in the console. For more information, see Back up and recover data in the console.
Download a backup file in the ApsaraDB for Redis console
- Log on to the ApsaraDB for Redis console.
- In the top navigation bar, select the region where the instance resides.
- On the Instance List page, find the target instance. Then, click the instance ID or click Manage in the Actions column.
- In the left-side navigation pane, click Backup and Recovery.
- On the Backup and Recovery page, find the backup file to migrate and click Download in the Actions column.
Note A backup file is generated for each node of an ApsaraDB for Redis cluster.
Download the redis-shake tool
Download the redis-shake tool.
Run the following command to decompress the redis-shake.tar.gz package:
# tar -xvf redis-shake.tar.gz
Use a backup file to migrate data
- Modify the redis-shake.conf file. The following table describes the parameters for the restore mode of the redis-shake
Table 1. Parameters for the restore mode of the redis-shake tool Parameter Description Example rdb.input The path of the RDB file. You can specify either a relative path or an absolute path. /root/tools/RedisShake/demo.rdb target.address The endpoint and port of the destination on-premises Redis instance.
target.password_raw The password of the destination on-premises Redis instance.
TargetPass233Note If you use a database account other than the default database account to connect to the on-premises Redis instance, set this parameter in the following format:
target.db The database to which the data is recovered in the destination on-premises Redis instance. Default value: 0. For example, to recover the data of the source ApsaraDB for Redis instance to DB10 of the destination on-premises Redis instance, set this parameter to 10. If you set this parameter to a value less than 0, data is recovered to DB0.
rewrite Specifies whether to overwrite the existing keys that are identical to those in the RDB file. Valid values:
Note Default value: true. We recommend that you back up the valid data of the destination on-premises Redis instance before migration. If you set this parameter to false and any keys are duplicate in the source and destination databases, an error message is returned.
parallel The number of concurrent threads used to synchronize the RDB file. More concurrent threads improve synchronization performance.Note
- Minimum value: 1.
- Maximum value: depends on the server performance.
- Recommended value: 64.
64Note You can use the default values for other parameters unless otherwise specified.
- Run the following command to recover data:
# ./redis-shake -type=restore -conf=redis-shake.confNote You must run this command in the same directory as the redis-shake and redis-shake.conf files. Otherwise, you must specify the correct file path in the command.
restore: rdb doneappears in logs, the data is recovered. You can press Ctrl+C to exit the tool.Note You must repeat the preceding procedure to migrate the backup data of all nodes in an ApsaraDB for Redis cluster.