Monday, October 17, 2011

broken cyrus seen file

Someday I'm going to give up on running my own mail server. I say this especially when my hard drive fills up an my cyrus "seen" database files inevitably corrupt. This db file keeps track of your mailbox message status (whether you've read a message or not).

If you have this problem, you'll see a line like this in  your mail log:
DBERROR: skiplist recovery /home/cyrus/user/u/username.seen: ADD at 4C48 exists
The recommended way to fix this is to truncate the file at the location the problem is detected. In the case above, at the hex byte 4C48.

I've had to do this often enough that I've written a shell script to do it, which just needs the username and hex location supplied via command line.

  • it's a shell script, but python is used to do hex conversion.
  • you'll probably need to change the path (/home/cyrus/user/) to your cyrus user directory (mine is non-standard).
  • you must supply the hex location where the corruption is detected. You can find this in your mail log file (usually /var/log/mail.log). 
  • if your cyrus files are owned by other than user cyrus and group mail, you'll need to change the chown cyrus:mail.
  • the existing *.seen file is backed up with a unique filename (current timestamp), so it can be restored if something goes wrong.

if [ $# != 2 ]; then
    echo "USAGE: $0 login hex"

TRUNC=`python -c "print int('$2', 16)"`
DATE=`date +%Y%m%dT%H%M`

if [ -d $DBPATH ]; then
    dd if=$DBPATH/$1.seen of=$DBPATH/$1.seen.fixed bs=1 count=$TRUNC
    chown cyrus:mail $DBPATH/$1.seen.fixed
    chmod 600 $DBPATH/$1.seen.fixed
    mv $DBPATH/$1.seen $DBPATH/$1.seen.$$TRUNC
    mv $DBPATH/$1.seen.fixed $DBPATH/$1.seen
    echo "No such directory: $DBPATH"

No comments:

Post a Comment