将 Redis 转储恢复到不同的数据库 [英] Restore Redis dump to a different database

查看:69
本文介绍了将 Redis 转储恢复到不同的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何转储在数据库 0 上运行的 redis 并将其恢复到我本地机器上的不同数据库 (8) 上?

How can I dump a redis that's running on database 0 and restore it in my local machine on a different database (8) ?

我已经安全复制了转储文件:

I already secure copied the dump file:

scp hostname@/var/lib/redis/dump.rdb .

但是如果我用这个更改我的本地 redis dump.rdb,我将获得数据库 0 上的数据.如何将其恢复到特定数据库?

But if I change my local redis dump.rdb with this one, I'll get the data on database 0. How can I restore it to a specific database?

推荐答案

我最终用 Ruby 创建了一个脚本来转储和恢复我想要的密钥.(请注意,这种方法很慢,200 个键需要大约 1 分钟).

I ended up creating a script in Ruby to dump and restore the keys I wanted. (Please note that this approach is slow, takes around 1 min for 200 keys) .

  • 获取转储/恢复的密钥

ssh 主机名 redis-cli --scan --pattern 'awesome_filter_pattern*'

  • 打开到生产服务器的 ssh 连接
  • 转储遥控钥匙

dump = ssh.exec!("redis-cli dump #{key}").chomp

  • 在本地主机上恢复

$redis.connection.restore(key, 0, dump)

这篇关于将 Redis 转储恢复到不同的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆