V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Cola98
V2EX  ›  程序员

redis 持久化疑惑

  •  
  •   Cola98 · 44 天前 · 1368 次点击
    这是一个创建于 44 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近重新看 redis 持久化相关知识,发现官方写的地方有些冲突:

    RDB advantages:

    RDB is a very compact single-file point-in-time representation of your Redis data. RDB files are perfect for backups. For instance you may want to archive your RDB files every hour for the latest 24 hours, and to save an RDB snapshot every day for 30 days. This allows you to easily restore different versions of the data set in case of disasters.

    RDB disadvantages: RDB is NOT good if you need to minimize the chance of data loss in case Redis stops working (for example after a power outage). You can configure different save points where an RDB is produced (for instance after at least five minutes and 100 writes against the data set, you can have multiple save points). However you'll usually create an RDB snapshot every five minutes or more, so in case of Redis stopping working without a correct shutdown for any reason you should be prepared to lose the latest minutes of data.

    前面提到适合容灾场景,但是在遇到断电这种情况表现还不如 AOF ,这是不是起冲突了?

    第 1 条附言  ·  43 天前
    后续文档中写到了,大概率是这个原因:
    The AOF log is an append-only log, so there are no seeks, nor corruption problems if there is a power outage. Even if the log ends with a half-written command for some reason (disk full or other reasons) the redis-check-aof tool is able to fix it easily.

    感谢各位大佬解答
    6 条回复    2024-03-15 08:31:40 +08:00
    uiosun
        1
    uiosun  
       44 天前
    有限灾备吧——备份好的文件非常易于恢复;断电等会导致丢失相对近期数据(取决于你的 x min 备份一次的设置)
    arloor
        2
    arloor  
       43 天前 via Android   ❤️ 1
    rdb 的优势部分提到了 backup snapshot ,这个并不是你以为的适合容灾场景。
    backup 和 snapshot 是指所有数据的快照,你可以认为是 dump 出来了。dump 之后的变更全都没有
    aof 是对写入的 append only 的记录,即使丢也只会丢最后的几条变更。

    能看官方文档是好事,耐心的继续看下去吧
    SoviaPhilo
        3
    SoviaPhilo  
       43 天前   ❤️ 1
    RDB 是全量备份,全量备份意味着要比 AOF 更重, 也就意味着你不可能每秒一次 RDB
    如果真的要用 Redis 做持久化, 视数据的重要性,可能是要两个都开的
    GrayXu
        4
    GrayXu  
       43 天前   ❤️ 1
    严格来说前面不是说容灾,只是说 snapshot 的用途。AOF 才能保障崩溃一致性
    kuituosi
        5
    kuituosi  
       43 天前   ❤️ 1
    rdb 和 aof 都可以灾备,各有优缺点。rds 恢复很快但是丢失最新数据可能就多
    aof 恢复慢但是丢失最新数据相对少,aof 也可能会拖慢写入速度
    所以具体用哪一种需要自己选择,本来也没有完美的方案
    bthulu
        6
    bthulu  
       43 天前
    每毫秒一次 RDB 全量备份就行了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2901 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 07:45 · PVG 15:45 · LAX 00:45 · JFK 03:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.