Date

I don't need a hot backup solution for Zimbra I do try and sleep at night...

So I wrote the following script that will do the following :

  • stop zimba
  • tar the /opt zimbra
  • check the tar ball against /opt/zimbra * encrypt the tar ball
  • Email out the results.

Edit the following to suit your install :

BKDIR=/backup
ZMHOME=/opt/zimbra
TARTL=/
GPGUSR=zimbra
LLOC=/var/log
DESTINIATION@EMAIL
#!/bin/bash

BKDIR=/backup
ZMHOME=/opt/zimbra
TARTL=/
GPGUSR=zimbra
LLOC=/var/log/backups

DATE=`date +%Y-%m-%d`
ZMBVER=`su - zimbra -c '/opt/zimbra/bin/zmcontrol -v | awk '\''{print $2}'\'''`


function loghd() {
  echo "Starting Zimbra Full Backup" > $LLOC/ZM-FB-$DATE.log
  echo "Backup started on `date +%c`" >> $LLOC/ZM-FB-$DATE.log
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
}

function zmstart() {
  /bin/su - zimbra -c '/opt/zimbra/bin/zmcontrol start'
}

function zmstop() {
  /bin/su - zimbra -c '/opt/zimbra/bin/zmcontrol stop'
  echo "Stopping Zimbra" >> $LLOC/ZM-FB-$DATE.log
  echo "Status $?" >> $LLOC/ZM-FB-$DATE.log
  sleep 20
}

function zmstatus() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Zimbra Status :-" >> $LLOC/ZM-FB-$DATE.log 
  /bin/su - zimbra -c '/opt/zimbra/bin/zmcontrol status' >> $LLOC/ZM-FB-$DATE.log
  sleep 20
}

function tarbk() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Starting backup on `date +%c`" >> $LLOC/ZM-FB-$DATE.log
  echo "Backing up $ZMHOME :-" >> $LLOC/ZM-FB-$DATE.log
  /bin/tar -zpcf $BKDIR/zimbra-$ZMBVER-$DATE.tgz $ZMHOME
  echo "Tar exit exist status $?" >> $LLOC/ZM-FB-$DATE.log
}

function chktar() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Checking status of tarball :-" >> $LLOC/ZM-FB-$DATE.log
  /bin/tar -df $BKDIR/zimbra-$ZMBVER-$DATE.tgz -C $TARTL >> $LLOC/ZM-FB-$DATE.log
  echo "Tarball integrity $?" >> $LLOC/ZM-FB-$DATE.log
}

function encbk() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Encripting file zimbra-$ZMBVER-$DATE.tgz" >> $LLOC/ZM-FB-$DATE.log
  echo "Output :- zimbra-$ZMBVER-$DATE.tgz.gpg" >> $LLOC/ZM-FB-$DATE.log
  /usr/bin/gpg -es -r $GPGUSR $BKDIR/zimbra-$ZMBVER-$DATE.tgz
  echo "GPG exit status $?" >> $LLOC/ZM-FB-$DATE.log
}

function killzm() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Killing all Zimbra owned process" >> $LLOC/ZM-FB-$DATE.log
  /usr/bin/pkill -9 -u zimbra
  echo "Kill status $?" >> $LLOC/ZM-FB-$DATE.log
}

function bkend() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Backup and GPG ended on `date +%c`" >> $LLOC/ZM-FB-$DATE.log
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo zimbra-$ZMBVER-$DATE.tgz.gpg > /tmp/curzmbk
}

function mailrpt() {
  /bin/cat $LLOC/ZM-FB-$DATE.log | /bin/mail -s "Backup Report for `date +%c`" admin@basstech.net
}

loghd
zmstop
killzm
zmstatus
tarbk
chktar
encbk
zmstart
zmstatus
bkend
mailrpt

Comments

There are no comments yet. Email me and I will add your comment.