Redis数据导入导出,实例间db迁移

源实例db0迁移至目标实例db1

[root@172.20.0.1 ~]# cat redis_mv.sh
#!/bin/bash
redis-cli -h 172.20.0.1 -p 6379 -a password -n 0 keys "*" | while read key
do
    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

aof导入方式

  1. 源实例生成aof数据
# 清空上文目标实例全部数据
[root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password flushall
OK
# 源实例开启aof功能,将在dir目录下生成appendonly.aof文件
[root@172.20.0.1 ~]# redis-cli -h 172.20.0.1 -a password config set appendonly yes
OK
  1. 目标实例导入aof数据
# 假设appendonly.aof就在当前路径下
[root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password --pipe < appendonly.aof
All 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 no
OK

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/19/redis-data-import-export-and-database-migration-between-instances/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Redis数据导入导出,实例间db迁移
源实例db0迁移至目标实例db1 [root@172.20.0.1 ~]# cat redis_mv.sh #!/bin/bash redis-cli -h 172.20.0.1 -p 6379 -a password -n 0 keys "*" | wh……
<<上一篇
下一篇>>
文章目录
关闭
目 录