Zimbra Backup

A mate of mine has started to use the OSS version of Zimbra, and asked me how to best back it up this morning as the OSS version misses out on the backup/restore functions of the NE version.

So what follows is my recommendation, I’m sure others are all ready doing it this way so certainly not something new;

Stop Zimbra using “zmcontrol stop” and check it has ended with “zmcontrol status” as the “zimbra” user.

I have a kill all user processes script I like to run as well just to be sure everything has stopped;

#!/bin/bash
USER=$1
MYNAME=`basename $0`
if [ ! -n “$USER” ]
then
echo “Usage: $MYNAME username” >&2
exit 1
elif ! grep “^$USER:” /etc/passwd >/dev/null
then
echo “User $USER does not exist!” >&2
exit 2
fi
while [ `ps -ef | grep “^$USER” | wc -l` -gt 0 ]
do
PIDS=`ps -ef | grep “^$USER” | awk ‘{print $2}’`
echo “Killing ” `echo $PIDS | wc -w` ” processes for user $USER.”
for PID in $PIDS
do
kill -9 $PID 2>&1 >/dev/null
done
done
echo “User $USER has 0 processes still running.”

script usage is simply ./killuser $username, the script will then systematically nuke all processes belonging to that user. First used to free up server resources when I was working as an operator and needed more cpu cycles to speed my tasks up 🙂

right so next run;

1. “rsync -ra /opt/zimbra /backup –progress”
2. “tar -zcvf /tmp/zimbra.backup.tgz -C /backup”
3. “ncftpput -u $username -p $password $server /zimbrabackups /tmp/zimbra.backup.tgz”

make sure your ftp server has space, as my backups run at about 300 – 400 GB.

This is a CRON Job script I use by the way to automate the process;

#!/bin/bash

# Zimbra Backup Script
# Requires ncftp to run
# This script is intended to run from the crontab as root
# Free to use and free of any warranty!

# Live sync before stopping Zimbra to minimize sync time with the services down
# Comment out the following line if you want to try single cold-sync only
rsync -avHK –delete /opt/zimbra/ /backup/zimbra

# which is the same as: /opt/zimbra /backup
# Including –delete option gets rid of files in the dest folder that don’t exist at the src
# this prevents logfile/extraneous bloat from building up overtime.

# Stop Zimbra Services
sudo -u zimbra /opt/zimbra/bin/zmcontrol stop
sleep 20

# Sync to backup directory
rsync -avHK –delete /opt/zimbra/ /backup/zimbra

# Restart Zimbra Services
sudo -u zimbra /opt/zimbra/bin/zmcontrol start

# Create a txt file in the backup directory that’ll contain the current Zimbra
# server version. Handy for knowing what version of Zimbra a backup can be restored to.
sudo -u zimbra zmcontrol -v > /backup/zimbra/conf/zimbra_version.txt
# or examine your /opt/zimbra/.install_history

# Create archive of backed-up directory for offsite transfer
# cd /backup/zimbra
tar -zcvf /tmp/zimbra.backup.tgz -C /backup/zimbra .

# Transfer file to backup server
ncftpput -u $username -p $password server /zimbrabackups /tmp/zimbra.backup.tgz

Leave a Reply