Home > Braindump > Backing up Zimbra using LVM

Backing up Zimbra using LVM

March 17th, 2012 Leave a comment Go to comments

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

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."
  1. john
    August 22nd, 2013 at 16:43 | #1

    Thank you.

    Exactly what i’ve been looking for.

  1. No trackbacks yet.