lacee1986
7/1/2019 - 9:09 AM

Move Redis

Move redis database from one server to another.

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.

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.

This is worked

  • Stop redis (because redis overwrites the current rdb file when it exits).
  • Copy your backup rdb file to the redis working directory (this is the dir option in your redis config). Also make sure your backup filename matches the dbfilename config option.
  • Change the redis config appendonly flag to no (otherwise redis will ignore your rdb file when it starts).
  • Start redis.
  • Run redis-cli BGREWRITEAOF to create a new appendonly file.
  • Restore redis config appendonly flag to yes.