
Originally Posted by
mowglie
sure, i wouldnt mind your script
Nothing sacred - basically the same thing you've seen in this thread and in other posts - I've modified it slightly since my version is in OpenVZ - instead of the zmcontrol stop/start, I'm actually turning off the virtual container, and doing all the rsyncs from the host rather than from the zimbra server. I'll post both scripts here.
These scripts assume you have an rsync server set up at host "backup" and you're using the rsync username "backup" with a password file stored with "400" perms at /root/rsync.passwd on the local computer.
IMPORTANT -- this script is using the --delete option. If for some reason your Zimbra installation vanishes or your files become corrupted, your backup will vanish right along with it once this script runs.
Standard "bare metal" Zimbra backup:
Code:
#!/bin/bash
rsync --exclude=data/ldap/mdb/db --delete --password-file=/root/rsync.passwd -azHpr /opt/zimbra backup@backup::zimbra/
mydir="/opt/zimbra/ldap-backup/`date +%s`"
mkdir -p $mydir
chown zimbra $mydir
su - zimbra -c /opt/zimbra/libexec/zmslapcat $mydir
su - zimbra -c /opt/zimbra/libexec/zmslapcat -c $mydir
gzip $mydir/*
su - zimbra -c /opt/zimbra/bin/zmcontrol stop
/bin/sync
rsync --exclude=data/ldap/mdb/db --delete --password-file=/root/rsync.passwd -azHpr /opt/zimbra backup@backup::zimbra/
su - zimbra -c /opt/zimbra/bin/zmcontrol start
For the OpenVZ version - in my case my container ID is 203 that Zimbra runs in - so that's what the 203 below refers to - my rsync server host a relating backup host "203" - you'll need to change this to suit your needs.
Code:
#!/bin/bash
rsync --exclude=opt/zimbra/data/ldap/mdb/db --delete --password-file=/root/rsync.passwd -azHpr /vz/private/203/* backup@backup::203/
#Back up LDAP - this is just a script that contains the slapcat commands in the previous example seen above
vzctl exec 203 /opt/scripts/run-ldap-backup-as-zimbra.sh
/usr/sbin/vzctl stop 203
rsync --exclude=opt/zimbra/data/ldap/mdb/db --delete --password-file=/root/rsync.passwd -aHpr /vz/private/203/* backup@backup::203/
/usr/sbin/vzctl start 203