Backup Zimbra Mailbox

Credit: Ahmad Imanudin

Start

#vim /opt/zimbra/backup/backup-mailbox.sh

Paste the following contents:

##!/bin/bash
clear

## Backup Format
FORMAT=tgz

## Backup location
ZBACKUP=/opt/zimbra/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.

Executive script:
#chmod +x /opt/zimbra/backup/backup-mailbox.sh
#sh /opt/zimbra/backup/backup-mailbox.sh
Advertisements

Author: tminh5969

IT Manager CCNP #CSCO10942210

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s