How do I move a redis database from one server to another?

前端 未结 12 1045
耶瑟儿~
耶瑟儿~ 2020-12-12 09:27

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

相关标签:
12条回答
  • 2020-12-12 10:11

    you can also use rdd

    it can dump & restore a running redis server and allow filter/match/rename dumps keys

    0 讨论(0)
  • 2020-12-12 10:20

    I just published a command line interface utility to npm and github that allows you to copy keys that match a given pattern (even *) from one Redis database to another.

    You can find the utility here:

    https://www.npmjs.com/package/redis-utils-cli

    0 讨论(0)
  • 2020-12-12 10:23

    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.

    0 讨论(0)
  • 2020-12-12 10:24

    Key elements of a zero-downtime migration is:

    • replication (http://redis.io/commands/SLAVEOF)
    • possibility to write into a slave during application switching (CONFIG SET slave-read-only no)

    In short:

    1. setup a target redis (empty) as slave of a source redis (with your data)
    2. wait for replication finish
    3. permit writes to a target redis (which is currently slave)
    4. switch your apps to a target redis
    5. wait for finish datastream from master to slave
    6. turn a target redis from master to slave

    Additionally redis have options which allows to disable a source redis to accept writes right after detaching a target:

    • min-slaves-to-write
    • min-slaves-max-lag

    This topic covered by

    • http://redis.io/topics/admin#upgrading-or-restarting-a-redis-instance-without-downtime

    Very good explanation from RedisLabs team https://redislabs.com/blog/real-time-synchronization-tool-for-redis-migration (use web.archive.org)

    And even their interactive tool for migrate: https://github.com/RedisLabs/redis-migrate

    0 讨论(0)
  • 2020-12-12 10:26

    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.

    0 讨论(0)
  • 2020-12-12 10:26

    I also want to do the same thing: migrate a db from a standalone redis instance to a another redis instances(redis sentinel).

    Because the data is not critical(session data), i will give https://github.com/yaauie/redis-copy a try.

    0 讨论(0)
提交回复
热议问题