Self-Hosted Codis Migration with redis-cli and redis-port
Codis data can be smoothly migrated to DCS Proxy Cluster instances because DCS Proxy Clusters are based on the open-source Codis. The following describes the procedure of migrating Codis data using redis-cli and redis-port.
- From self-hosted Codis to DCS Proxy Cluster:
Self-hosted Codis deployed in a local data center, HUAWEI CLOUD, or another public cloud is supported. There are no restrictions on exporting data from self-hosted Codis.
- From Codis of another cloud to DCS Proxy Cluster:
Some cloud vendors have restrictions on data export commands. You can export data by downloading backup files on their consoles.
Preparation
- Create a DCS Proxy Cluster instance.
The available memory of the instance must be larger than the size of the data to be imported.
- Prepare a server which will be used for transmitting and importing data.
The server must be connected to the DCS instance and have sufficient disk space for storing migration data.
You can use HUAWEI CLOUD ECS and configure the same VPC, subnet, and security group for the ECS and the DCS instance.
Procedure
- Export the RDB file.
Download and install Redis: http://download.redis.io/releases/redis-5.0.8.tar.gz.
Run the following command to export the RDB file for each shard in the cluster:
redis-cli -h {source_redis_address} -p {source_redis_port} -a {source_redis_password} --rdb {output.rdb}
If "Transfer finished with success." is displayed after the command is executed, the file is exported successfully.
- Migrate data during off-peak hours.
- When exporting Codis data, individually export the data of each shard in the cluster, and then import the data file by file.
- Upload the RDB file to the server. HUAWEI CLOUD ECS is used as an example.
If the files are larger, compress them before transmission.
- Download redis-port.
Log in to the ECS. Run the following commands to download and decompress the tool package. redis-port can be used directly without compilation.
wget https://github.com/CodisLabs/redis-port/releases/download/v2.0-beta/redis-port-v2.0-beta-go1.10.1-linux.tar.gz
tar -xvf redis-port-v2.0-beta-go1.10.1-linux.tar.gz
- Import data.
Run the following commands in redis-port to import all RDB files to the target DCS instance. If the ECS and the DCS instance are in the same VPC, it takes 4 to 10 seconds to export 1 million data records, assuming that each record contains 20 byte data.
redis-restore -n {N} -i {outputfile.rdb} -t {password}@{dcs_instance_address}:{port} [--unixtime-in-milliseconds="yyyy-MM-dd hh:mm:ss"]
By specifying the db parameter, you can import the cached data of the specified DB in the file. -n indicates that multiple CPUs process the import task concurrently.
Parameter description:
root@redis-nodelete:~/port/redis-port-v2.0-beta-go1.10.1-linux# ./redis-restore --help Usage: redis-restore [--ncpu=N] [--input=INPUT|INPUT] --target=TARGET [--aof=FILE] [--db=DB] [--unixtime-in-milliseconds=EXPR] redis-restore --version Options: -n N, --ncpu=N Set runtime.GOMAXPROCS to N. -i INPUT, --input=INPUT Set input rdb encoded file. -t TARGET, --target=TARGET The target redis instance ([auth@]host:port). -a FILE, --aof=FILE Also restore the replication backlog. --db=DB Accept db = DB, default is *. --unixtime-in-milliseconds=EXPR Update expire time when restoring objects from RDB. Examples: $ redis-restore dump.rdb -t 127.0.0.1:6379 $ redis-restore -i dump.rdb -t 127.0.0.1:6379 --aof dump.aof --db=1 $ redis-restore -t 127.0.0.1:6379 --aof dump.aof $ redis-restore -t 127.0.0.1:6379 --db=0 $ redis-restore -i dump.rdb -t 127.0.0.1:6379 --unixtime-in-milliseconds="@209059200000" // ttlms += (now - '1976-08-17') $ redis-restore -i dump.rdb -t 127.0.0.1:6379 --unixtime-in-milliseconds="+1000" // ttlms += 1s $ redis-restore -i dump.rdb -t 127.0.0.1:6379 --unixtime-in-milliseconds="-1000" // ttlms -= 1s $ redis-restore -i dump.rdb -t 127.0.0.1:6379 --unixtime-in-milliseconds="1976-08-17 00:00:00" // ttlms += (now - '1976-08-17')Example:
root@redis-nodelete:~/port/redis-port-v2.0-beta-go1.10.1-linux# ./redis-restore -i save196.rdb -t ******@192.168.0.171:6379 2018/03/26 09:15:33 restore.go:70: [INFO] restore: input = "save196.rdb", aoflog = "" target = "******@192.168.0.171:6379" 2018/03/26 09:15:33 restore.go:126: [INFO] restore: (r,f,s/a,f,s) = (rdb,rdb.forward,rdb.skip/aof,rdb.forward,rdb.skip) 2018/03/26 09:15:34 restore.go:155: [INFO] restore: size = 46721058 - [ 49.94%, 0.00%] (r,f,s/a,f,s)=(23330816,0,599496/0,0,0) ~ (22.25mb,-,-/0,-,-) 2018/03/26 09:15:35 restore.go:155: [INFO] restore: size = 46721058 - [ 99.31%, 0.00%] (r,f,s/a,f,s)=(46399488,12558,1179884/0,0,0) ~ (44.25mb,-,-/0,-,-) 2018/03/26 09:15:35 restore.go:155: [INFO] restore: size = 46721058 - [100.00%, 0.00%] (r,f,s/a,f,s)=(46721058,20000,1179884/0,0,0) ~ (44.56mb,-,-/0,-,-) 2018/03/26 09:15:35 restore.go:159: [INFO] restore: done root@redis-nodelete:~/port/redis-port-v2.0-alpha-go1.9.2-linux#
- Verify the migration.
After the migration is completed, access the DCS instance and run the info command to check whether the data has been successfully imported as required.
If the data import fails, run the flushall or flushdb command to clear the cached data in the instance, and import the data again.
Last Article: Self-Hosted Redis Migration with redis-port (RDB)
Next Article: Self-Hosted Redis Cluster Migration with redis-shake
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.