LoginSignup
6
3

More than 5 years have passed since last update.

Docker内のRedisのAOFファイルが壊れてしまった場合の対処法

Posted at

TL;DR

docker-compose run --rm redis redis-check-aof --fix /data/appendonly.aof

Docker内のRedisのAOFファイルが壊れてしまった

ある日突然Dockerで使用しているRedisが起動しなくなってしまいました。

redis_1 | Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename>
redis_1 exited with code 1

AOFファイルがおかしくなっているのでFIXしてあげれば良い模様。
しかしredisが起動してくれないためAOFファイルのパスすらわからない。

What is the default location for Redis AOF file for Ubuntu?

上記のStackOverflowを参考にするとパスは
/var/lib/redis/appendonly.aofであったためこのパスで実行してみます

docker-compose run --rm redis redis-check-aof --fix /var/lib/redis/appendonly.aof
Cannot open file: /var/lib/redis/appendonly.aof

失敗
上記パスのファイルが開けないため、このパスのファイルは存在しないようです...

上司に DockerのRedis内のappendonly.aofのパスを確認してもらうと/data/appendonly.aofでした。

docker-compose run --rm redis redis-check-aof --fix /data/appendonly.aof
0x        1874d306: Expected prefix '
AOF analyzed: size=410310560, ok_up_to=410309382, diff=1178
This will shrink the AOF from 410310560 bytes, with 1178 bytes, to 410309382 bytes
Continue? [y/N]: y
Successfully truncated AOF

truncateされてる!?
しかしコンテナを起動すると無事redisに接続できてデータも残っていた、良かった。

全てのDocker内のAOFファイルのパスが私のと同じとは限らないですが、参考になればと思います。

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3