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 天前
postgresql数据库的安装
数据库
敖云岚1 天前
【疑难解答】MySQL 报错 Public Key Retrieval is not allowed
数据库·mysql
小旺不正经1 天前
Linux介绍及常用命令
linux·运维·数据库
焦糖码奇朵、1 天前
移动通信网络建设-实验2:5G站点选型与设备部署
网络·数据库·人工智能·5g·信号处理·基带工程
l1t1 天前
把ITPUB newkid先生编写的Oracle语法数独求解SQL改写成DuckDB
数据库·人工智能·sql·oracle·duckdb
ヾChen1 天前
MySQL——增删改查操作
数据库·sql·物联网·学习·mysql
betazhou1 天前
Oracle Goldengate 同步过程的同步用户权限设置
数据库·oracle·goldengate·ogg·goldengate授权
0和1的舞者1 天前
《MySQL数据库进阶(九):数据库备份与恢复(二)》
数据库·mysql·oracle·程序员·策略模式·备份与恢复
稻香味秋天1 天前
MySQL和DB2在SQL语法上的差异
数据库·sql