How To Backup And Restore All Zimbra Mailboxes

Backup And Restore All Zimbra Mailboxes

Zimbra Mailbox Backup and Restore Is Very importance because Backups can help save time and money if these failures occur.

To get the full list of accounts in ZIMBRA server

sudo -u zimbra /opt/zimbra/bin/zmprov -l gaa 

Backup All Zimbra Mailboxes

Make file backup-mailbox.sh in /srv directory

vi /srv/backup-mailbox.sh

Fill with the following line

##!/bin/bash
clear

## Backup Format 
FORMAT=tgz

## Backup location
ZBACKUP=/srv/backup/

## Folder name for backup and using date
DATE=`date +"%d%m%y"`

## Backup location separate by date
ZDUMPDIR=$ZBACKUP/$DATE

## zmmailbox location
ZMBOX=/opt/zimbra/bin/zmmailbox

### Backup Option ###

## Based on few day ago until today, example 7 days ago

#HARI=`date --date='7 days ago' +"%m/%d/%Y"`
#query="&query=after:$HARI"

## Based on certain date , example 21 Jan 2015.

#query="&query=date:01/21/2015"

## Based from/to certain date. Example Backup Mailbox before 21 Jan 2015 and after 10 Jan 2015

#query="&query=after:01/10/2015 before:01/21/2015"

if [ ! -d $ZDUMPDIR ]; then
        mkdir -p $ZDUMPDIR
fi

## Looping Account Zimbra
for account in `su - zimbra -c 'zmprov -l gaa | sort'`
do
echo "Processing mailbox $account backup..."
        $ZMBOX -z -m $account getRestURL "//?fmt=${FORMAT}$query" > $ZDUMPDIR/$account.${FORMAT}
done

echo "Zimbra Mailbox backup has been completed successfully."

After Save File and run these 2 command to backup all mailbox automatic.


chmod +x /srv/backup-mailbox.sh
sh /srv/backup-mailbox.sh

Restore All Zimbra Mailboxes

Make file restore-mailbox.sh in /srv directory

vi /srv/restore-mailbox.sh

Fill with the following line
before run this (the backup file is located in /srv/backup/20150128/ ) check this

#!/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"

After Save File and run these 2 command to Restore all mailbox automatic.

chmod +x /srv/restore-mailbox.sh
sh /srv/restore-mailbox.sh
Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply Cancel reply