redis的AOF恢复数据

  1. 启用AOF
  2. 使用AOF文件恢复数据

步骤一:启用AOF

bash 复制代码
127.0.0.1:6379> config set appendonly yes
OK
127.0.0.1:6379> CONFIG GET appendonly
1) "appendonly"
2) "yes"
127.0.0.1:6379> CONFIG rewrite
OK
[root@redis170 ~]# ls /var/lib/redis/
appendonly.aof  dump.rdb
[root@redis170 ~]# wc -l  /var/lib/redis/appendonly.aof
1 /var/lib/redis/appendonly.aof
[root@redis170 ~]# !redis
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> mset x 1 y 2 c 3
OK
127.0.0.1:6379> exit
[root@redis170 ~]# wc -l  /var/lib/redis/appendonly.aof
21 /var/lib/redis/appendonly.aof

步骤二:使用AOF文件恢复数据

bash 复制代码
1)备份aof文件
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> CONFIG GET appendonly
1) "appendonly"
2) "no"
127.0.0.1:6379> CONFIG set appendonly yes
OK
127.0.0.1:6379> exit
[root@redis170 ~]# ll /var/lib/redis/
总用量 8
-rw-r--r-- 1 redis redis 92 5月  24 11:35 appendonly.aof
-rw-r--r-- 1 redis redis 92 5月  24 11:34 dump.rdb
127.0.0.1:6379> mset x 1 y 2 z 3
OK
127.0.0.1:6379> keys *
1) "x"
2) "z"
3) "y"
127.0.0.1:6379> exit
[root@redis170 ~]# cp /var/lib/redis/appendonly.aof  /opt/
2)删除数据
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> keys *
1) "x"
2) "z"
3) "y"
127.0.0.1:6379> flushall
OK


3)恢复数据

[root@redis170 ~]# cp /opt/appendonly.aof  /var/lib/redis/
cp:是否覆盖'/var/lib/redis/appendonly.aof'? y
[root@redis170 ~]# systemctl start redis
[root@redis170 ~]# !redis
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> keys *
1) "z"
2) "y"
3) "x"
相关推荐
汪子熙2 小时前
HSQLDB 数据库锁获取失败深度解析
数据库·后端
VvUppppp2 小时前
Redis应用
redis
无色海4 小时前
mysql连接生命周期-连接阶段
数据库
无色海5 小时前
MySQL协议中的TLS实现
数据库
麓殇⊙6 小时前
redisson锁的可重入、可重试、超时续约原理详解
redis·分布式锁
jstart千语6 小时前
【Redisson】锁可重入原理
redis·分布式·redisson
weixin_418007606 小时前
SpringJPA统计数据库表行数及更新频率
数据库
2301_767233226 小时前
怎么优化MySQL中的索引
数据库·mysql
无色海7 小时前
MySQL 压缩数据包详解
数据库
海尔辛7 小时前
防御性安全:数字取证
数据库·安全·数字取证