说明:默认rdb方式保存,redis支持主从和哨兵等,但是在某些情况下我们会单机跑,所以有时候我们就会需要设计到备份恢复
环境:原始redis:192.168.1.200
新redis:192.168.1.201
原始redis:192.168.1.200,查看导出备份地址以及备份
[[email protected] ~]#redis-cli
127.0.0.1:6379> auth 123456 #认证
OK
127.0.0.1:6379> save #保存还未写入本地文件的redis数据
OK
(1.06s)
127.0.0.1:6379> CONFIG GET dir #查看备份文件路径,可以看到是root目录
1) "dir"
2) "/root"
127.0.0.1:6379> exit
[[email protected] ~]# ll -h /root/
total 24M
-rw-r--r-- 1 root root 24M Sep 20 15:11 dump.rdb
这就是备份下来的文件
新redis:192.168.1.201搭建和恢复:
[[email protected] ~]cd /usr/local
[[email protected] local]wget http://download.redis.io/releases/redis-4.0.1.tar.gz
[[email protected] local]tar xzf redis-4.0.1.tar.gz
[[email protected] local]cd redis-4.0.1
[[email protected] redis-4.0.1]make
[[email protected] redis-4.0.1]./src/redis-server &
##查看rdb路径
[[email protected] redis-4.0.1]./src/redis-cli
127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/usr/local/redis-4.0.1"
###停止redis,将远程的rdb文件复制到/usr/local/redis-4.0.1
[[email protected] redis-4.0.1]killall redis-server
[[email protected] redis-4.0.1]scp [email protected]:/root/dump.rdb /usr/local/redis-4.0.1
#启动redis,验证数据
[[email protected] redis-4.0.1]./src/redis-server &
[[email protected] redis-4.0.1]./src/redis-cli
127.0.0.1:6379> keys *
......
36300) "exp:userId:login:103829"
36301) "exp:userId:login:92291"
36302) "exp:userId:login:1328"
36304) "exp:userId:login:102208"
36308) "exp:userId:login:33017"
(0.81s)
到此 恢复完成
时间: 2024-10-08 01:45:25