How do I move a redis database from one server to another?
I currently have a live redis server running on a cloud instance and I want to migrate this redis server to a new cloud instance and use that instance as my new redis server. If it were MySQL, I would export the DB from the old server and import it into the new server. How should I do this with redis?
P.S.: I'm not looking to set-up replication. I want to completely migrate the redis server to a new instance.
First, create a dump on server A.
A$ redis-cli
127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/var/lib/redis/"
127.0.0.1:6379> SAVE
OK
This ensures dump.rdb
is completely up-to-date, and shows us where it is stored (/var/lib/redis/dump.rdb
in this case). dump.rdb
is also periodically written to disk automatically.
Next, copy it to server B:
A$ scp /var/lib/redis/dump.rdb myuser@B:/tmp/dump.rdb
Stop the Redis server on B, copy dump.rdb (ensuring permissions are the same as before), then start.
B$ sudo service redis-server stop
B$ sudo cp /tmp/dump.rdb /var/lib/redis/dump.rdb
B$ sudo chown redis: /var/lib/redis/dump.rdb
B$ sudo service redis-server start
The version of Redis on B must be greater or equal than that of A, or you may hit compatibility issues.
Save a snapshot of the database into a dump.rdb by either running BGSAVE
or SAVE
from the command line. This will create a file named dump.rdb in the same folder as your redis server. See a list of all server commands.
Copy this dump.rdb to the other redis server you want to migrate to. When redis starts up, it looks for this file to initialize the database from.
If you have the connectivity between servers it is better to set up replication (which is trivial, unlike with SQL) with the new instance as a slave node - then you can switch the new node to master with a single command and do the move with zero downtime.