« Lenge leve ODP | Hjem | Den norske delen av O… »

Howto repair a Cyrus IMAP mailbox

Publisert mandag 10 mars 2008 klokka 16:07 Brukte merkelapper: , ,

Disclaimer: The following tip was written for FreeBSD 6.2, running Cyrus IMAP 2.2.13. It worked for me, but maybe not for you.

Prelude

Some days ago the web mail on my server stopped working - it couldn't save some settings file. I immediately guessed that my /var partition was full again. (It's not the first time... Very long ago, when I didn't know better, I selected a too small /var partition. Since it normally goes OK, it's 65% full, I haven't fixed it yet.) I decided the quickest solution was to delete the content if the biggest Trash mailbox. It worked OK, the /var partition was down at 70% and the computer usable again. However, I expected the Trash mailbox index to rebuild successfully automatically, but no such luck. I then decide to copy the (cache, header, index) files from another empty Trash mailbox. Unfortunately, I screwed up even more, because I copied the file into the inbox... I tried running the normal reconstruct command in cyradm, but it just didn't fix anything.

The solution

If you have broken a mailbox so badly that using reconstruct doesn't help, try the following:

  1. Preserve the existing messages for all folders.
    cp -p /var/spool/imap/user/username/Foldername/[0-9]*. ~username/Foldername/
  2. Connect to the Cyrus IMAP server immediately (to not loose any messages), delete the mailbox and recreate it:
    cyradm -u cyrus localhost
    In cyradm, do
    localhost> sam user.username cyrus c
    localhost> dm user.username
    localhost> cm user.username
    
  3. Stop the IMAP server immediately after quiting cyradm, to not loose any messages.
    /usr/local/etc/rc.d/imapd stop
  4. Copy back the messages for all (non-empty) folders.
    mv ~username/Foldername/* /var/spool/imap/user/username/Foldername/
  5. Finally repair (or reconstruct) the mailbox.
    sudo -u cyrus /usr/local/cyrus/bin/reconstruct -r -f user.username
  6. Start the IMAP server again.
    /usr/local/etc/rc.d/imapd start

PS! This tip doesn't solve problems related the mailbox database, mailboxes.db.

2 kommentarer

Skriv en kommentar

Husk personlig info?
Skjul e-post
Merk: Alle HTML-tagger utenom <b> og <i> fjernes fra kommentarer. Du kan lage lenker ved å skrive URLen eller e-postadressen rett inn i teksten.