1.快照机制(RDB)
# # Save the DB on disk: # # save <seconds> <changes> # # Will save the DB if both the given number of seconds and the given # number of write operations against the DB occurred. # # In the example below the behaviour will be to save: # after 900 sec (15 min) if at least 1 key changed # after 300 sec (5 min) if at least 10 keys changed # after 60 sec if at least 10000 keys changed # # Note: you can disable saving completely by commenting out all "save" lines. # # It is also possible to remove all the previously configured save # points by adding a save directive with a single empty string argument # like in the following example: # # save "" save 900 1 save 300 10 save 60 10000
如果 900秒(15分钟)内有1个数据发生变化。自动保存一次
如果300秒(5分钟)内有10个数据发生变化,自动保存一次
如果60秒(1分钟)内有10000个数据发生变化,自动保存一次
2.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 no # The name of the append only file (default: "appendonly.aof") appendfilename "appendonly.aof" # The fsync() call tells the Operating System to actually write data on disk # instead of waiting for more data in the output buffer. Some OS will really flush # data on disk, some other OS will just try to do it ASAP. # # Redis supports three different modes: # # no: don't fsync, just let the OS flush the data when it wants. Faster. # always: fsync after every write to the append only log. Slow, Safest. # everysec: fsync only one time every second. Compromise. # # The default is "everysec", as that's usually the right compromise between # speed and data safety. It's up to you to understand if you can relax this to # "no" that will let the operating system flush the output buffer when # it wants, for better performances (but if you can live with the idea of # some data loss consider the default persistence mode that's snapshotting), # or on the contrary, use "always" that's very slow but a bit safer than # everysec. # # 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
1、appendonly no 改为yes 开启aop存储机制
2、appendfilename "appendonly.aof" 备份文件名
3、appendfsync everysec 每秒备份一次 no 随机备份 always 每有一次数据更新就保存一次 效率低。不建议使用
3.混合使用:当两种机制并存时。若aop文件不慎丢失。应及时备份rdb文件。否则重启以后rdb文件也会丢失,招呼丢失的aof文件,覆盖原文件。数据恢复