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://redis.io/topics/persistence for more information.
appendonly yes
配置文件被修改,需要删除旧进程,再根据新的配置文件启动新进程:
新进程启动好后会看到对应的aof持久化备份文件appendonly.aof:
aof追加持久化的备份频率:
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".
# appendfsync always
appendfsync everysec
# appendfsync no
2. 为aof备份文件做优化处理
对appendonly.aof文件内容做优化压缩处理:
(例如多个incr指令变为一个set指令)
bgrewriteaof 当日志文件过长时优化AOF日志文件存储