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"
相关推荐
大数据张老师1 小时前
对比Redis与向量数据库(如Milvus)在AI中的应用
数据库·redis·milvus
白嫖不白嫖1 小时前
MySQL 8.0 和 5.7 快速生成测试数据
android·数据库·mysql
CAT_cwds1 小时前
使用MybatisPlus实现sql日志打印优化
数据库·python·sql
一刀到底2111 小时前
阿里云ecs 8核 16G 内存 装有redis6 分配了3G内存,和2个tomcat 每个tomcat 4G 服务器反应迟钝,如何确认不是redis的问题
redis·阿里云·tomcat
YUNYINGXIA2 小时前
Python操作MySQL数据库
数据库·oracle
java1234_小锋3 小时前
一周学会Pandas2 Python数据处理与分析-Pandas2数据合并与对比-pd.merge():数据库风格合并
数据库·python·pandas
影子24014 小时前
sqlserver数据库查询执行慢的sql、查询隔离级别、设置快照模式、查询锁表进程、锁表sql、解锁等
数据库·sql·sqlserver
Volunteer Technology5 小时前
大厂缓存架构方案-Caffeine+Redis双层缓存架构
redis·缓存·架构
master-dragon5 小时前
分布式锁总结
redis·分布式·zookeeper
寒士obj5 小时前
SQL语句的执行流程
数据库·sql