Backing up Zimbra using LVM

Now, since we moved to Zimbra I wanted to actually have it backed up.
Small script to do it using LVM:

#!/bin/bash
DATE=`date -u +%d%m%Y`
 
echo "`date +%k:%M:%S` Backup started."
# Stop zimbra, create a snapshot volume, start zimbra
echo -n "`date +%k:%M:%S` Stopping zimbra... "
/etc/init.d/zimbra stop 2&> /dev/null
echo " done."
echo -n "`date +%k:%M:%S` Creating snapshot volume... "
/usr/sbin/lvcreate -L 5G -s -n vol_zimbrabackup /dev/vg0/vol_zimbrarh 2> /dev/null 1> /dev/null
echo " done."
echo -n "`date +%k:%M:%S` Starting zimbra... "
/etc/init.d/zimbra start 2&> /dev/null
echo " done."
 
# Mount the snapshot, create a backup tarball, unmount snapshot, remove the volume
echo -n "`date +%k:%M:%S` Mounting snapshot... "
/bin/mount /dev/vg0/vol_zimbrabackup /zimbrabackup 2> /dev/null 1> /dev/null
echo " done."
echo -n "`date +%k:%M:%S` Packing up stuff... "
/bin/tar jcf /var/backup/zimbra-$DATE.tar.bz2 /zimbrabackup/* 2&> /dev/null
echo " done."
echo -n "`date +%k:%M:%S` Un-mounting snapshot... "
/bin/umount /zimbrabackup
echo " done."
echo -n "`date +%k:%M:%S` Removing the snapshot... "
/usr/sbin/lvremove -f /dev/vg0/vol_zimbrabackup 2> /dev/null 1> /dev/null
echo " done."
 
# Cleanup logs older than a week
echo -n "`date +%k:%M:%S` Cleaning up old stuff... "
/usr/bin/find /var/backup/zimbra*.bz2 -type f -mtime +7 | xargs rm -f 2&> /dev/null
echo " done."
echo "`date +%k:%M:%S` Backup done."
Author: favoretti

1 thought on “Backing up Zimbra using LVM

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.