What happens if Redis's persistence files, whether RDB or AOF, become corrupted, and how would you attempt to recover?
Short answer
For a corrupted RDB file, you generally need to restore from an earlier valid backup since there is limited built-in repair capability, while for a corrupted AOF file, Redis provides a redis-check-aof tool that can attempt to fix the file by truncating it at the point where…
Advertisement
AModel answer
For a corrupted RDB file, you generally need to restore from an earlier valid backup since there is limited built-in repair capability, while for a corrupted AOF file, Redis provides a redis-check-aof tool that can attempt to fix the file by truncating it at the point where corruption begins, potentially losing only the most recent, damaged portion of the log rather than the entire file.
Example
redis-check-aof --fix appendonly.aof
Real-world example
A team recovers from a partially corrupted AOF file caused by an unexpected server crash using the redis-check-aof repair tool, losing only the last few seconds of writes rather than the entire dataset.
Likely follow-ups
- How often should backup files be tested to confirm they are not corrupted?
- What steps can reduce the risk of persistence file corruption happening in the first place?
Related topics