1

I have a huge problem with Zimbra. The ibdata file is corrupted, and I can't open the mailboxes. I have all the msg files inside store/0/*, but I only have database backup from a week ago. I have tried to restore the files from last week, but it does not show emails we received this week. Adding them one by one is impossible, since we have hundreds of email in a week, and lots of mboxgroup folders.

Is there any way to scan all mailboxes and let Zimbra rebuild the database? If I have to make a script, how can we differentiate mails between backup and server crashed?

We are using community edition of Zimbra.

0

Ok.. since no one answered, I have it worked out..

Since we have a lot of emails, and spread to multiple folders, we need to separate those in database and those which are not..

Make sure you copy these... er.. broken data folder into another folder. So if something goes wrong, you can always put them back together.

  1. So first step, is of course shutdown zimbra

    service zimbra stop
    
  2. then copy older working mysql database to non working zimbra.

    cp /mnt/mail/db/* /opt/zimbra/db -R
    
  3. Now, we need to compare those mails in ~/store in July backup, versus mails in ~/store in running zimbra. Then I moved every mail not in july to another corresponding folder at /opt/backup. The script below is to scan all available .msg in all stores and volumes, and move to another folder. Save this script below to i.e. compare.sh

    SOURCE=/opt/zimbra/store/0
    DESTINATION=/opt/backup
    COMPARE=/mnt/mail/store/0
    for f in $SOURCE/*;
    do
        echo "scanning folder ${f##*/}";
        for v in $f/msg/*;
        do
            comp=$COMPARE/${f##*/}/msg/${v##*/}
            dst=$DESTINATION/${f##*/}
            if [ ! -d $dst ]; then
                    echo "create $dst"
                    mkdir $dst;
            fi
    
            echo "comparing volume $v to $comp"
            if [ -d $comp ] ; then
                    for m in $v/*; do
                            if [ ! -f $comp/${m##*/} ]; then
                                    echo "move $m to $dst"
                                    mv -b $m $dst
                            fi
                    done
            else
                    echo "move $v/* to $dst"
                    mv -b $v/* $dst
            fi
        done;
    done;
    

    Make sure you modify SOURCE, COMPARE dan DESTINATION variables to mirror your own folders.

    SOURCE: Current running zimbra store folder
    DESTINATION: Where do you want your missing files moved
    COMPARE: Where your old working zimbra backup resides, the one that you use its database.

    Then chmod a+x compare.sh to make it executable then ./compare.sh to execute it.

    result will be /opt/backup/1 to /opt/backup/xx where xx is mailbox stores. All messages that moved to /opt/backup/x are not in original mailbox, and will be added.

    So now we have 2 folders. /opt/backup/xx which contains files not in database, and /opt/zimbra/ which should be largely identical /mnt/mail/

  4. Start Zimbra back

    service zimbra start
    
  5. Now, we need to get all mailboxes

     mysql "zimbra" -e"select id,comment from mailbox"
    
  6. The rest is easy, we only need to call CreateFolder and addMessage like these to re-attach those missing mails:

    zmmailbox -z -m <user@domain.net> cf "/Inbox/Recovered"
    zmmailbox -z -m <user@domain.net> am "/Inbox/Recovered" "/opt/backup/<xx>"
    

for example:

Let's say we have from step 2 above

+----+----------------------------------------------------+
| id | comment                                            |
+----+----------------------------------------------------+
|  1 | mymailbox@bogusmail.xcom                           |
|  2 | awesome@bogusmail.xcom                             |
+----+----------------------------------------------------+

We should add those messages as:

zmmailbox -z -m mymailbox@bogusmail.xcom cf "/Inbox/Recovered"
zmmailbox -z -m mymailbox@bogusmail.xcom am "/Inbox/Recovered" "/opt/backup/1"

zmmailbox -z -m awesome@bogusmail.xcom cf "/Inbox/Recovered"
zmmailbox -z -m awesome@bogusmail.xcom am "/Inbox/Recovered" "/opt/backup/2"

Feel free to change that /Inbox/Recovered to anything you like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.