源实例db0迁移至目标实例db1
1 [root@172.20.0.1 ~]# cat redis_mv.sh 2 #!/bin/bash 3 redis-cli -h 172.20.0.1 -p 6379 -a password -n 0 keys "*" | while read key 4 do 5 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 6 echo "migrate key $key" 7 done
aof导入方式:
1.源实例生成aof数据
1 # 清空上文目标实例全部数据 2 [root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password flushall 3 OK 4 # 源实例开启aof功能,将在dir目录下生成appendonly.aof文件 5 [root@172.20.0.1 ~]# redis-cli -h 172.20.0.1 -a password config set appendonly yes 6 OK
2.目标实例导入aof数据
1 # 假设appendonly.aof就在当前路径下 2 [root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password --pipe < appendonly.aof 3 All data transferred. Waiting for the last reply... 4 Last reply received from server. 5 errors: 0, replies: 5 6 # 源实例关闭aof功能 7 [root@172.20.0.1 ~]# redis-cli -h 172.20.0.1 -a password config set appendonly no 8 OK