我目前有一个live redis服务器运行在一个云实例,我想迁移这个redis服务器到一个新的云实例,并使用该实例作为我的新的redis服务器。如果它是MySQL,我将从旧服务器导出DB并将其导入到新服务器。我该如何用redis做到这一点?
附注:我不指望设置复制。我想完全迁移redis服务器到一个新的实例。
我目前有一个live redis服务器运行在一个云实例,我想迁移这个redis服务器到一个新的云实例,并使用该实例作为我的新的redis服务器。如果它是MySQL,我将从旧服务器导出DB并将其导入到新服务器。我该如何用redis做到这一点?
附注:我不指望设置复制。我想完全迁移redis服务器到一个新的实例。
当前回答
source_host=xxx
source_port=6379
source_db=10
source_auth=xxx
target_host=yyyyy
target_port=6379
target_db=12
target_auth=yyyyy
redis-cli -a $source_auth -h $source_host -p $source_port -n $source_db keys \* | while read key; do
echo "redis-cli -h $source_host -p $source_port -a $source_auth -n $source_db MIGRATE $target_host $target_port "" $target_db 5000 COPY AUTH $target_auth KEYS $key"
redis-cli -h $source_host -p $source_port -a $source_auth -n $source_db MIGRATE $target_host $target_port "" $target_db 5000 COPY AUTH $target_auth KEYS $key
done
我对自己的案子很在行,已经测试过了。
其他回答
我发现导出/备份Redis数据(创建转储文件)的简单方法是通过命令行启动一个服务器,并创建一个动态副本,如下所示(假设源Redis在端口6379上是1.2.3.4):
/usr/bin/redis-server --port 6399 --dbfilename backup_of_master.rdb --slaveof 1.2.3.4 6379
也可以使用SLAVEOF命令迁移数据:
SLAVEOF old_instance_name old_instance_port
检查您是否收到带有keys *的钥匙。你也可以用任何其他方法测试这个新实例,当你完成时,只需打开replication of:
SLAVEOF NO ONE
由于Redis 5.0推荐使用REPLICAOF,因为SLAVEOF已弃用-请参阅手册
source_host=xxx
source_port=6379
source_db=10
source_auth=xxx
target_host=yyyyy
target_port=6379
target_db=12
target_auth=yyyyy
redis-cli -a $source_auth -h $source_host -p $source_port -n $source_db keys \* | while read key; do
echo "redis-cli -h $source_host -p $source_port -a $source_auth -n $source_db MIGRATE $target_host $target_port "" $target_db 5000 COPY AUTH $target_auth KEYS $key"
redis-cli -h $source_host -p $source_port -a $source_auth -n $source_db MIGRATE $target_host $target_port "" $target_db 5000 COPY AUTH $target_auth KEYS $key
done
我对自己的案子很在行,已经测试过了。
我还想做同样的事情:将一个db从一个独立的redis实例迁移到另一个redis实例(redis哨兵)。
因为数据不是关键(会话数据),我将尝试https://github.com/yaauie/redis-copy。
Redis-dump终于为我工作了。它的文档提供了一个如何转储Redis数据库并将数据插入到另一个数据库的示例。