本文共 1849 字,大约阅读时间需要 6 分钟。
172.20.0.1 redis源实例
172.20.0.2 redis目标实例 172.20.0.3 任意linux系统[root@172.20.0.3 ~]# yum install ruby rubygems ruby-devel -y
[root@172.20.0.3 ~]# gem sources -a http://ruby.taobao.orgError fetching http://ruby.taobao.org: bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
访问,公告通知镜像维护站点已迁往Ruby China镜像
#gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/[root@172.20.0.3 ~]# gem sources --add http://gems.ruby-china.org/ --remove http://rubygems.org/http://gems.ruby-china.org/ added to sourcessource http://rubygems.org/ not present in cache[root@172.20.0.3 ~]# gem sources -l*** CURRENT SOURCES *** http://gems.ruby-china.org/[root@172.20.0.3 ~]# gem install redis-dump -V
[root@172.20.0.3 ~]# redis-dump -u :password@172.20.0.1:6379 > 172.20.0.1.json
[root@172.20.0.3 ~]# cat 172.20.0.1.json | redis-load -u :password@172.20.0.2:6379
清空上文目标实例全部数据
[root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password flushallOK
源实例开启aof功能,将在dir目录下生成appendonly.aof文件
[root@172.20.0.1 ~]# redis-cli -h 172.20.0.1 -a password config set appendonly yesOK
假设appendonly.aof就在当前路径下
[root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password --pipe < appendonly.aofAll data transferred. Waiting for the last reply...Last reply received from server.errors: 0, replies: 5
源实例关闭aof功能
[root@172.20.0.1 ~]# redis-cli -h 172.20.0.1 -a password config set appendonly noOK
暂略
[root@172.20.0.1 ~]# cat redis_mv.sh#!/bin/bashredis-cli -h 172.20.0.1 -p 6379 -a password -n 0 keys "*" | while read keydo redis-cli -h 172.20.0.1 -p 6379 -a password -n 0 --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h 172.20.0.2 -p 6379 -a password -n 1 -x restore $key 0 echo "migrate key $key"done
转载地址:http://izdeo.baihongyu.com/