Migrate data between Redis servers

There is a reasonable simple way to move data between Redis servers: Simply temporarily configure the new server as a replica of the old server.

To do this:

  1. Make sure the new Redis server can access the old server. If they are on different networks, a simple SSH tunnel will do.
  2. Connect to the new server using redis-cli.
  3. Tail the log of the redis server (found in /var/logs/redis) in another terminal.
  4. Make sure the server is currently master and not already a replica (check INFO replication)
  5. Enable replication with REPLICAOF <host> <port> (on older Redis versions this is called SLAVEOF).
  6. Redis will then drop all current data and fetch everything from the master.
  7. Check the log. It will tell you if replication works and when it is done. It should usually only take a few seconds.
  8. Disable replication with REPLICAOF no one.

This even works if the new server is itself master to other replicas.

Tobias Kraze Almost 4 years ago