databaseredisdata-migrationdatabase-migration

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.


Solution

  • 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.