aof恢复简讲过程:
[[email protected] redis]# pkill -9 redis
[[email protected] ~]# cd /var/dir
[[email protected] ~]# rm -rf *
清除掉现有环境备份文件;然后启动服务器进程,添加新数据
[[email protected] redis]# ./bin/redis-server ./redis.conf
[[email protected] redis]# ./bin/redis-server ./redis6380.conf
[[email protected] redis]# ./bin/redis-server ./redis6381.conf
[[email protected] redis]# ./bin/redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set site www.baidu.com
OK
127.0.0.1:6379> set name yjf
OK
127.0.0.1:6379> set addr bj
OK
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> get name
(nil)
此时一定要先停止服务,避免其他人有写入操作,重写aof。况且aof记录着也有flushall操作。
[[email protected] dir]# more laoyang-appendonly.aof
2
$6
SELECT
$1
0
3
$3
set
$4
site
$13
www.baidu.com
3
$3
set
$4
name
$3
yjf
3
$3
set
$4
addr
$2
bj
*1
$8
flushall
127.0.0.1:6379> shutdown nosave ---shutdown 操作不记录日志
not connected>
然后编辑一下aof生成文件。将最后危险操作flushall给dd掉。--注意记录的格式,一般是*开始,命令结尾;
[[email protected] dir]# vim laoyang-appendonly.aof
删除下面三行,保存退出
*1
$8
flushall
然后重启一下服务,登陆查询,如果么有,退出后,再次登陆查询
[[email protected] redis]# ./bin/redis-server ./redis.conf
[[email protected] redis]# ./bin/redis-cli
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> exit
[[email protected] redis]# ./bin/redis-cli
127.0.0.1:6379> get name
yjf
检查rdb文件
[[email protected] redis]# ./bin/redis-check-rdb /var/dir/dump6380.rdb
[offset 0] Checking RDB file /var/dir/dump6380.rdb
[offset 27] AUX FIELD redis-ver = ‘3.2.13‘
[offset 41] AUX FIELD redis-bits = ‘64‘
[offset 53] AUX FIELD ctime = ‘1561537890‘
[offset 68] AUX FIELD used-mem = ‘880976‘
[offset 77] Checksum OK
[offset 77] \o/ RDB looks OK! \o/
[info] 0 keys read
[info] 0 expires
[info] 0 already expired
原文地址:https://blog.51cto.com/yangjunfeng/2414275