Migrate redis server data from one instance to another instance
This blog will be helpful for people who looking for migrate redis server from one service to another like from AWS to GoogleCloud, DigitalOcean to AWS etc. Or just move redis data from one instance to another instance or live sync their redis data in another slave machine.
We are going to use master/slave approach to achieve this. Following steps are need to complete this.
1. Open redis ports
Please make sure to open redis port (default port is
6379) in both slave and master for data transfer between them. If you are using AWS, please update inbound rules in security group associated with redis instance.
Note: Port need to be opened in both master and slave to make it work.
2. Update auth details
If you are using password authentication in master, please update let slave know what is the password used for authentication by update redis configuration file(redis.conf).
#> masterauth <password-used-in-master>
If you are not using password in master, then please set this for secure communication. You can do this by set your password in master configuration file(redis.conf) as mentioned below.
#> requirepass <your-secure-password>
Note: After update configuration we need to restart redis server to apply last changes.
3. Start replication
There are two way to start replication.
3.1 First way is to run following commands from slave machine to start data replication. Login to redis-cli console using redis host, port and password.
=> redis-cli -h <domain-or-public-ip-of-redis-server-instace> -p 6379
=> auth <password>
Once entered into redis-cli console, please run following.
=> slaveof <master-ip> <master-port>
=> slaveof 220.127.116.11 6379
3.2 Second way is to update configuration file(redis.conf) in redis to start replication. Please update following property and restart to start replication.
=> replicaof <public-ip-of-master> port
4. Verify replication
That’s all, replication should have started now. You can check it by run keys command in redis to check keys replicated from master. Also you can run
info command to check replication detail.
=> keys *OR
=> info replication
Migration will be completed within few seconds/minutes. If you are ready to use slave as a master. Please do the following from slave instance. If you used slaveof command to start replication then run following command
=> slaveof no one
If you used
replicaof property in configuration to start replication then remove this property from configuration file and restart the redis server.
That’s all. New instance is ready to use in live application as master.