redis 支持 json_Redis数据迁移利器之redisshake

当需要进行Redis实例或集群数据迁移时,我们可以采用导出/导入的方式进行数据迁移,但当需要做数据异地灾备或双活时,再使用传统的方式就不合适了,我们需要借助工具(如redis-port/redis-shake)来完成。


redis-shake介绍

redis-shake就是一款非常好用的工具,可以支持备份、恢复、解析、同步等功能,主要的功能有:

  • decode,对RDB文件进行读取,并以json格式存储
  • restore,将RDB文件恢复到目的Redis服务器
  • dump,将源Redis服务器的数据通过RDB文件的方式保存下来
  • sync,支持源Redis和目的Redis的数据同步,通过模拟成Slave(使用psync),支持全量和增量数据的同步,对单节点、主从、集群环境之间进行同步(2.8-5.0版本,codis环境),也支持云上环境
  • rump,使用scan和restore命令进行数据迁移,对不支持psync命令的环境可以使用这种方式,仅支持全量的数据迁移

数据迁移原理

redis-shake通过模拟成一个从节点加入到源Redis,进行全量拉取并回放,然后进行增量的拉取。

6a23a80a4e6beb42b9f7ee4879f8168c.png

其对大key的同步支持分批拉取,同时提供监控数据。

迁移演练

如从云上Redis迁移到线下Redis:

./redis-shake.linux \
-type sync \
-conf redis-shake.conf

576215ec155a806d758c2b1647f46b6f.png参考配置文件:

# id
id = redis-shake
# parallel routines number used in RDB file syncing.
parallel = 4
# source redis configuration.
# used in `dump` and `sync`.
# ip:port
source.address = 172.17.134.223:6379
# password.
source.password_raw = xxx
# auth type, don't modify it
source.auth_type = auth
# version number, default is 6 (6 for Redis Version <= 3.0.7, 7 for >=3.2.0)
source.version = 6

# target redis configuration. used in `restore` and `sync`.
# used in `restore` and `sync`.
# ip:port
target.address = 10.0.2.23:6379
# password.
target.password_raw = xx
# auth type, don't modify it
target.auth_type = auth
# version number, default is 6 (6 for Redis Version <= 3.0.7, 7 for >=3.2.0)
target.version = 6
# all the data will come into this db. # used in `restore` and `sync`.
target.db = -1# big key threshold, the default is 500 * 1024 * 1024. The field of the big key will be split in processing.
big_key_threshold = 524288000# use psync command.# used in `sync`.# 默认使用sync命令,启用将会使用psync命令
psync = false

同时也提供迁移的状态监控:

curl 127.0.0.1:9320/metric|jq

a5305d34903216b2b0e130f04733f7a8.png

数据一致性校验

迁移后数据的一致性使用redis-full-check进行检查,通过多次对比的方式进行源端和目的端的数据校验,每次都会抓取源和目的端的数据进行差异化比较,记录不一致的数据(存储在sqlite3中)进入下一轮对比,支持对key、value或两者的一致性进行校验。

e6cf20f8e0c5a059d298f7746780a35c.png

云上服务之间我们可以使用DTS来进行,毕竟是付费服务,相对来说更简单,需要在Redis服务上创建复制类型的账号。


dc5f896cd34770e4cb93343a358c41d8.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值