Migrate Redis Keys Without RDB Files

1 minute read

Recently we moved the Transloadit status page from an unmanaged EC2 instance to the Nodejitsu platform. We kept status uptime history in redis, and obviously I wanted to preserve that data.

For the new setup I did not have access to the filesystem, I only had a redis port to talk to. So instead of rsyncing the .rdb file I used Redis replication to migrate the data between instances.

Here's the redacted terminal transcript, the sending host is old-redis.transloadit.com, the receiving host is new-redis.transloadit.com.

$ # First let's connect to the new host
$ redis-cli -h new-redis.transloadit.com
redis new-redis.transloadit.com:6379> AUTH ...:...
OK

# Let's start with a clean slate, first make sure it stands alone
redis new-redis.transloadit.com:6379> SLAVEOF NO ONE
OK

# WARNING! This will trash all existing data on the receiving host
redis new-redis.transloadit.com:6379> FLUSHALL
OK

# Now setup replication so that redis copies all keys from old to new
redis new-redis.transloadit.com:6379> SLAVEOF old-redis.transloadit.com 6379
OK

# Wait until INFO shows `role:slave`, and the
# same amount of keys as on the old server.
redis new-redis.transloadit.com:6379> INFO
...
role:slave
...
OK

# Check some random keys to see if you have all the data.
redis new-redis.transloadit.com:6379> LRANGE history 0 1
 1) "{\"message\":\"All services operational\",\"date\":\"2013-04-15\"}"
OK

# Looks good, now let's disable slave mode, make it stand alone again
redis new-redis.transloadit.com:6379> SLAVEOF NO ONE
OK

And that's it, you've copied all the redis keys without using .rdb files.

Hope this helps, let me know if you have suggestions.

Leave a Comment Right Here