Every information technology system must be backed up frequently. Backup if performed correctly - should allow you for fast recovery after any disaster which might damage the entire system or for recovery of accidentally deleted or corrupted files. Unlike the Professional (commercial) version - open-source Zimbra is not equipped with any build in backup system. You need to take care of backing up your MTA by yourselve. Shell scripting and crontab prove to be useful once again.
#########################################
# Zimbra backup cut and paste howto
#########################################
mkdir /backup
mkdir /backup/zimbra
crontab -e
# Backup Zimbra Nightly
0 1 * * * /usr/local/bin/backup.sh
vim /usr/local/bin/backup.sh
#!/bin/bash
echo Time backup started = $(date +%T)
before="$(date +%s)"
rsync -avHK --delete /opt/zimbra/ /backup/zimbra
before2="$(date +%s)"
su - zimbra -c"/opt/zimbra/bin/zmcontrol stop"
sleep 15
kill -9 `ps -u zimbra -o "pid="`
rsync -avHK --delete /opt/zimbra/ /backup/zimbra
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 Server was down for: "$hours hours $minutes minutes $seconds seconds"
su - zimbra -c "zmcontrol -v > /backup/zimbra/conf/zimbra_version.txt"
echo Displaying Zimbra services status...
su - zimbra -c "/opt/zimbra/bin/zmcontrol status"
tar -zcvf /tmp/mail.backup.tgz -C /backup/zimbra .
echo Time backup finished = $(date +%T)
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo Time taken: "$hours hours $minutes minutes $seconds seconds"
[root@mta002 ~]# less /usr/local/bin/backup.sh
[root@mta002 ~]# date
Mon Mar 29 09:57:26 EDT 2010
[root@mta002 ~]# date
Mon Mar 29 09:57:31 EDT 2010
[root@mta002 ~]# crontab -e
crontab: installing new crontab
[root@mta002 ~]# clear
[root@mta002 ~]# less /usr/local/bin/backup.sh
[root@mta002 ~]# cat /usr/local/bin/backup.sh
echo Time backup started = $(date +%T)
before="$(date +%s)"
rsync -avHK --delete /opt/zimbra/ /backup/zimbra
before2="$(date +%s)"
su - zimbra -c"/opt/zimbra/bin/zmcontrol stop"
sleep 15
kill -9 `ps -u zimbra -o "pid="`
rsync -avHK --delete /opt/zimbra/ /backup/zimbra
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 Server was down for: "$hours hours $minutes minutes $seconds seconds"
su - zimbra -c "zmcontrol -v > /backup/zimbra/conf/zimbra_version.txt"
echo Displaying Zimbra services status...
su - zimbra -c "/opt/zimbra/bin/zmcontrol status"
tar -zcvf /tmp/mail.backup.tgz -C /backup/zimbra .
#Copy to NAS or Windows share
#change 192.168.0.6 to the IP of your network device
#change yourname and yourpassword to the user that has
#permissions to use your network device
mount -t cifs //192.168.0.6/backup /mnt/bac001/ -o "username=yourname,password=yourpassword"
mount -t cifs //192.168.0.7/backup /mnt/bac002/ -o "username=yourusername,password=yourpassword"
cp /tmp/mail.backup.tgz /mnt/bac001/
cp /tmp/mail.backup.tgz /mnt/bac002/
umount /mnt/bac00*
######################################