Script backup zimbra mail

##!/bin/bash
clear
echo Start time of the backup = $(date +%T)
before=”$(date +%s)”
## 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”

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.”

echo “Sending files to backup all email accounts for Machine2 …”
rsync -avH $ZBACKUP root@ipaddress:/backup/zimbra_backup_accounts
before2=”$(date +%s)”
#
echo The process lasted = $(date +%T)
# Calculating time
after=”$(date +%s)”
elapsed=”$(expr $after – $before)”
hours=$(($elapsed / 3600))
elapsed=$(($elapsed – $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed – $minutes * 60))
echo The complete backup lasted : “$hours hours $minutes minutes $seconds seconds”

Leave a Reply

Please log in using one of these methods to post your comment:

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