This is an example mail report from the script
=====================================================================
Starting Zimbra Backup Process for: 2009-07-25
=====================================================================
Starting rsync before stopping zimbra at: 17:56:43
Stopping zimbra at: 17:57:10
Starting rsync with zimbra down at: 17:57:57
Starting zimbra services at: 17:58:17
Zimbra services down for: 0 hours 2 minutes 35 seconds
Checking zimbra status at: 17:59:52
Host your.zimbra.host
antispam Running
antivirus Running
ldap Running
logger Running
mailbox Running
mta Running
snmp Running
spell Running
stats Running
Tar and gzip of /backup/zimbra to /backup/2009-07-25.zimbra.backup.tgz
Putting /backup/2009-07-25.zimbra.backup.tgz to your.ftp.server
=====================================================================
Backup finished at: 18:11:36
=====================================================================
Final backup process: 0 hours 14 minutes 53 seconds
And here is the script!
#!/bin/bash
# Zimbra Backup Script for the community edition
# This script will take full backup every day and put a gzipped file to another server using ftp
# Requires ncftp and mailx or mutt to run
# Original scrip can be found at http://wiki.zimbra.com/index.php?title=Open_Source_Edition_Backup_Procedure
# This script is intended to run from the crontab as root
# Free to use and free of any warranty! Daniel W. Martin, 5 Dec 2008
# Modified by Albert Ragnarsson, 22 Jul 2009
# crontab works like this "23 05 * * * /root/bin/backup.sh > /dev/null 2>&1"
# This script has been tested on Ubuntu server 8.04 LTS (should work on other platforms but not tested)
BACKUPDIR=/backup # Change to your backup directory
RM=/bin/rm # Change to your rm proc
TAR=/bin/tar # Change to your tar proc
$RM -f $BACKUPDIR/*.txt # No need to change
$RM -f $BACKUPDIR/*.tgz # No need to change
DAY=`date +%Y-%m-%d` # Date in the form of Year-month-date (2009-07-22)
TGZ="$BACKUPDIR/$DAY.zimbra.backup.tgz" # No need to change
TXT="$BACKUPDIR/$DAY.zimbra.backup.txt" # No need to change
FTPSERVER=your.ftp.server # Change to name of your ftp server
FTPUSER=ftp.username # Change to your ftp username
PASSWORD=ftp.password # Change to your ftp user password
FTPPROC=/usr/bin/ncftpput # Install ncftp if needed
MAILPROC=/usr/bin/mutt # Install mutt or mailx if needed
MAILUSER="report@your.domain" # Change to who will get report in mail
# No need to edit below this line!
before="$(date +%s)"
echo "=====================================================================" > $TXT
echo "" >> $TXT
echo "Starting Zimbra Backup Process for: $DAY" >> $TXT
echo "" >> $TXT
echo "=====================================================================" >> $TXT
echo "" >> $TXT
echo "Starting rsync before stopping zimbra at: $(date +%T)" >> $TXT
rsync -avHK --delete /opt/zimbra/ $BACKUPDIR/zimbra
before2="$(date +%s)"
echo "Stopping zimbra at: $(date +%T)" >> $TXT
su - zimbra -c"/opt/zimbra/bin/zmcontrol stop"
sleep 15
kill -9 `ps -u zimbra -o "pid="`
# ps auxww | awk '{print $1" "$2}' | grep zimbra | kill -9 `awk '{print $2}'`
echo "Starting rsync with zimbra down at: $(date +%T)" >> $TXT
rsync -avHK --delete /opt/zimbra/ $BACKUPDIR/zimbra
echo "Starting zimbra services at: $(date +%T)" >> $TXT
su - zimbra -c "/opt/zimbra/bin/zmcontrol start"
after="$(date +%s)"
elapsed="$(expr $after - $before2)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo Zimbra services down for: "$hours hours $minutes minutes $seconds seconds" >> $TXT
echo "Checking zimbra status at: $(date +%T)" >> $TXT
echo "" >> $TXT
su - zimbra -c "/opt/zimbra/bin/zmcontrol status" >> $TXT
echo "" >> $TXT
echo "Tar and gzip of $BACKUPDIR/zimbra to $TGZ" >> $TXT
$TAR -zcvf $TGZ -C $BACKUPDIR/zimbra .
echo "Putting $TGZ to $FTPSERVER" >> $TXT
$FTPPROC -u $FTPUSER -p $PASSWORD $FTPSERVER /home/$FTPUSER $TGZ
echo "" >> $TXT
echo "=====================================================================" >> $TXT
echo "" >> $TXT
echo "Backup finished at: $(date +%T)" >> $TXT
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo "" >> $TXT
echo "=====================================================================" >> $TXT
echo "" >> $TXT
echo Final backup process: "$hours hours $minutes minutes $seconds seconds" >> $TXT
$MAILPROC -s "Zimbra Backup for $DAY" $MAILUSER < $TXT