How To Restore Zimbra Mailbox

Posted by

After success backup mailbox as described from previous article on this section : Zimbra Tips : How To Backup Mailbox Daily, Weekly and Monthly, you could restore the backup mailboxes with zmmailbox command who has been provided by Zimbra. The example command is like below :

su - zimbra -c "zmmailbox -z -m username postRestURL '//?fmt=tgz&resolve=skip' folder/file-location.tgz";

Note :
resolve = skip. This parameters will keep mailboxes existing on users.

resolve = reset. This parameters will delete mailboxes existing on user and will be changed with mailbox backup. The reset parameter could be changed with skip, replace, modify.

folder/file-location.tgz is folder/file location backup mailboxes.

Example

su - zimbra -c "zmmailbox -z -m admin@example.com postRestURL '//?fmt=tgz&resolve=skip' /srv/backup/20150128/admin@example.com.tgz";

The above command will be restore backup mailboxes admin@example.com user with reset resolver and the backup file is located in /srv/backup/20150128/admin@example.com.tgz

For restore backup all user, you could make a script as below :

#!/bin/bash

BACKUPDIR="/srv/backup/20150128";

clear

echo "Retrieve all zimbra user name..."

USERS=`su - zimbra -c 'zmprov -l gaa | sort'`;

for ACCOUNT in $USERS; do
NAME=`echo $ACCOUNT`;
echo "Restoring $NAME mailbox..."
su - zimbra -c "zmmailbox -z -m $NAME postRestURL '//?fmt=tgz&resolve=skip' $BACKUPDIR/$NAME.tgz";
done
echo "All mailbox has been restored sucessfully"

Good luck and hopefully useful 😀

37 comments

  1. Failure while Restore Zimbra Mailbox
    ***********************************
    [root@mail ~]# sh /srv/restore-mailbox.sh
    Retrieve all zimbra user name…
    Restoring admin@aajsc.com.vn mailbox…
    ERROR: service.FAILURE (system failure: POST failed, status=302 Found)
    Restoring abc@aajsc.com.vn mailbox…
    ERROR: service.FAILURE (system failure: POST failed, status=302 Found)
    Restoring xyz@aajsc.com.vn mailbox…
    ERROR: service.FAILURE (system failure: POST failed, status=302 Found)
    .
    .
    .
    All mailbox has been restored sucessfully
    [root@mail ~]#
    ***********************************
    But i login mailbox -> No data??? Help me???

    1. Hi FA,

      How about test with single command?

      su - zimbra -c "zmmailbox -z -m username postRestURL '//?fmt=tgz&resolve=reset' folder/file-location.tgz";
      
      1. Dear iman!
        I tried to test with single command. I still the same issue…
        ***********************************************
        Type 1:

        [root@mail ~]# su – zimbra -c “zmmailbox -z -m admin@aajsc.com.vn postRestURL ‘//?fmt=tgz&resolve=reset’ /srv/backup/110316/admin@aajsc.com.vn.tgz”;
        ERROR: service.FAILURE (system failure: POST failed, status=302 Found)
        [root@mail ~]#
        ***********************************************
        Type 2:

        [root@mail ~]# /opt/zimbra/bin/zmmailbox -z -m khietht@aajsc.com.vn postRestURL “//?fmt=tgz&resolve=reset” /srv/backup/110316/khietht@aajsc.com.vn.tgz;
        ERROR: service.FAILURE (system failure: POST failed, status=302 Found)
        [root@mail ~]#
        ***********************************************

          1. Hi FA,

            Please try to import message via webmail. Go to Zimbra Webmail | Preferences | Export/Import. If process working fine, there something wrong with CLI 😀

  2. Dear iman!
    I try to import message via webmail. Go to Zimbra Webmail | Preferences | Export/Import => Browse -> khietht@aajsc.com.vn.tgz -> It’s OK
    And I also Export/Import a new file -> It’s OK
    Only run the commands (sh /srv/restore-mailbox.sh) or (su – zimbra -c “zmmailbox -z -m username postRestURL ‘//?fmt=tgz&resolve=reset’ folder/file-location.tgz”;) -> Not OK
    ****************************************
    How to fix? thanks you very much…

      1. Dear iman!
        I tried to run the above command:
        (chmod 777 /srv/backup/110316/khietht@aajsc.com.vn.tgz)
        and try (chmod 777 /srv/backup/110316)
        and try (chmod 777 /srv/backup/)
        But still not be, the same result…
        => ERROR: service.FAILURE (system failure: POST failed, status=302 Found)

    1. Hi,
      Please try to add -u options.

      su - zimbra -c "zmmailbox -z -m username -u https://ZIMBRAIP postRestURL '//?fmt=tgz&resolve=skip' folder/file-location.tgz";
      
  3. Hi,

    I got same error too when tryin your script :
    ERROR: service.FAILURE (system failure: POST failed, status=302 Moved Temporarily)

    Any solution ?

      1. Hi iman,

        All services looks running well :
        Host mail.xxxxxxxx.co.id
        amavis Running
        antispam Running
        antivirus Running
        dnscache Running
        ldap Running
        logger Running
        mailbox Running
        memcached Running
        mta Running
        opendkim Running
        proxy Running
        service webapp Running
        snmp Running
        spell Running
        stats Running
        zimbra webapp Running
        zimbraAdmin webapp Running
        zimlet webapp Running
        zmconfigd Running

    1. para el error 302 en servidores 8.7 intenta las siguientes lineas

      zmprov md dominio.example.com zimbraPublicServiceProtocol https

      o

      zmprov md dominio.example.com zimbraPublicServiceProtocol both

      reinicias servicios
      zmcontrol restart

      e intentas hacer el import

      1. Excelente realicé la migración de correos en un ministerio y no podía subir los respaldos, hice lo que indicas y funciona a la perfección, gracias totales!!!!!

  4. iman,

    how can i transfer may user and mailbox settings on my new zimbra. need to transfer my zimbra server to a new computer i am using ubuntu 14.04 with zimbra 8.6 is it possible to copy all my user settings and mailbox thanks.

  5. Hello imam,
    When I am trying to restore the mail box in zimbra 8.7 post migration I am getting following error :
    finished
    ERROR: service.FAILURE (system failure: POST failed, status=500 Server Error)

  6. thanks for this documents i wnat to ask a question if i m importing a second time using this command does it skip or duplicate emails. thanks.

  7. Hai, can you help me.
    *sorry my English bad (gatel mau pake bahasa tapi ga enak sama yang lain.

    I use bulk restore mailbox from command but getting error with status 500, then I use script in this post the system asking about password.

    this the command
    for i in `cat /backups/zmigrate/emails.txt`; do zmmailbox -z -m $i postRestURL “/?fmt=tgz&resolve=skip” /backups/zmigrate/$i.tgz ; echo “$i — finished “; done

  8. Restore via cli in zimbra 8.8.12 have a problem, i was try with different options but always show error, now i’m trying restore via webmail and all run normally. I’m waiting tho finish the recovery process. Could someone run the recevery via cli?

  9. “zmmailbox -z -m admin@example.com postRestURL ‘//?fmt=tgz&resolve=skip’ /srv/backup/20150128/admin@example.com.tgz”;

    pake cara ini berhasil tapi ga masuk inbox nya knp ya mas?

  10. Hi Pak Iman,
    Nice article,
    when I running backup restore all mailbox from your script, I get failed like below:
    # sh restore-mailbox.sh
    Restoring dwi@esign.id mailbox…
    ERROR: zclient.CLIENT_ERROR (file not found: /home/infras/080124/dwi@esign.id.tgz) (cause: java.io.FileNotFoundException /home/infras/080124/dwi@esign.id.tgz (Permission denied))
    Restoring edho@esign.id mailbox…
    ERROR: zclient.CLIENT_ERROR (file not found: /home/infras/080124/edho@esign.id.tgz) (cause: java.io.FileNotFoundException /home/infras/080124/edho@esign.id.tgz (Permission denied))

    my backup file on /home/infras/080124/ directory
    I have try set chmode -R 777 on my backup folder, but still get the same error. My know, how to fix my case?

    Thanks a lot Pak Iman.

    Era

  11. Hi Pak Iman,
    Great,
    restoring mailbox running well since mailbox backup folder move to /tmp path.
    Just I need to know, if mailbox backup folder located on /home/username, is it restricted and
    not recommended?
    or are there any optional way to make it working?

    Thanks a lot for your help

    Era

  12. Hi Iman,
    Ok, I will try placed mailbox backup folder on another path directory beside of /home/username.

    Thanks a lot for your help.

    Era

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.