1.append only file (AOF 持久化)
本质:把用户执行的每个“写” 指令 (添加、修改、删除 ) 都备份到文件中,还原数据的时候就是 执行具体 写 指令 而已。
开启 AOF 持久化 ( 会清空 redis 内部的数据 ) :
(同时可以修改备份文件的名字,默认是 appendonly.aof)
# AOF and RDB persistence can be enabled at the same time without problems. # If the AOF is enabled on startup Redis will load the AOF, that is the file # with the better durability guarantees. # # Please check http: appendonly yes
配置文件被修改,需要删除旧进程,再根据新的配置文件启动新进程:
新进程启动好后会看到对应的 aof持久化备份文件 appendonly.aof :
aof追加持久化的备份频率:
# More details please check the following article: # http: # # If unsure, use "everysec" . # appendfsync always appendfsync everysec # appendfsync no
2. 为 aof 备份文件做优化处理
对appendonly.aof 文件内容做优化压缩处理:
(例如 多个 incr指令变为 一个 set指令 )
bgrewriteaof 当日志文件过长时优化AOF日志文件存储