DBAtlas · 数据库运维图谱

修复因 AOF 损坏而无法启动的 Redis(redis-check-aof、redis-check-rdb)

Redis持久化

命令

# With Redis stopped, copy the files first:
cp -a /var/lib/redis/appendonlydir /var/lib/redis/appendonlydir.bak
# Check (7.0+ multi-part AOF: pass the manifest file):
redis-check-aof /var/lib/redis/appendonlydir/appendonly.aof.manifest
# Repair by truncating everything after the first corrupt point (asks for confirmation):
redis-check-aof --fix /var/lib/redis/appendonlydir/appendonly.aof.manifest
# Verify the RDB file:
redis-check-rdb /var/lib/redis/dump.rdb

作用

验证 AOF 文件(base + incr + manifest)和 RDB 文件;截断 AOF 不完整或损坏的尾部,使 Redis 能够再次启动。

适用场景

断电、磁盘写满或突然关机后,Redis 因 'Bad file format reading the append only file' 或 'Unexpected EOF' 无法启动时。

注意

--fix 会删除从第一个损坏点到文件末尾的所有内容;若损坏位于文件中间,之后的所有写入都会丢失。确认前在输出中检查将被截断的字节数(ok_up_to、diff)。不完整的最后一条命令(如大型 HSET)会被整体丢弃。务必先做一份拷贝。

在 DBAtlas 中打开 →

相关内容