Bacula pre/post cold backup scripts
This is a little wheel re-inventing as there are already good procedures and scripts for doing backups with for the Open Source version of Zimbra. Basically these two scripts can be used in conjunction with Bacula as pre and post run scripts for a backup defined in and legislated by Bacula.
It has a very large documentation on the Internet. A good one is the "Baculapedia" Project - colaborative documentation for Bacula.
The first script is run before the actual backup to tape takes place. Change the variables as needed. The logic is simple and the same for any cold backup; stop the services, copy all of /opt to an alternate location (/var/backups in this case), and start the services up again. Then back up the copy created, removed the copy upon successful backup, and log everything.
/usr/local/bin/zimbra_pre_back.sh
#!/bin/sh my_user=zimbra stop_zimbra=zmcontrol my_prefix="/opt/zimbra/bin/" my_stop_option=stop my_start_option=start my_date=`date +%d-%m-%Y` my_logdir="/opt/zimbra/backup/" my_logfile=zm_backup-$my_date.log if [ -x $my_prefix$stop_zimbra ]; then su - $my_user -c "$my_prefix$stop_zimbra $my_stop_option" \ 2>&1 >>$my_logdir$my_logfile && echo -e "*****\tSHUTDOWN COMPLETE\t*****" \ >> $my_logdir$my_logfile && echo -e "*****\t`date +%H:%M:%S`\t\t\t*****" \ >> $my_logdir$my_logfile fi if [ -e $my_logdir/zm_backup-$my_date.log ]; then echo "" && \ cp -r /opt /var/backups 2>&1 >>$my_logdir$my_logfile && \ echo -e "*****\tCOPY COMPLETE\t\t*****" >>$my_logdir$my_logfile && \ echo -e "*****\t`date +%H:%M:%S`\t\t\t*****" >> $my_logdir$my_logfile fi if [ -x $my_prefix$stop_zimbra ]; then su - $my_user -c "$my_prefix$stop_zimbra $my_start_option" \ 2>&1 >>$my_logdir$my_logfile && echo -e "*****\tSTARTUP COMPLETE\t*****" \ >> $my_logdir$my_logfile && echo -e "*****\t`date +%H:%M:%S`\t\t\t*****" \ >> $my_logdir$my_logfile echo "" >> $my_logdir$my_logfile echo "Backup completed on: $my_date at: `date +%H:%M:%S`" >> $my_logdir$my_logfile fi exit 0
I just put this in /usr/local/bin and added the following directive to my backup job stanza in Bacula:
ClientRunBeforeJob = "/usr/local/bin/zimbra_pre_back.sh"
The next script just removes the copy once the backup to tape completes:
/usr/local/bin/zimbra_post_back.sh
#!/bin/sh my_date=`date +%d-%m-%Y` my_logdir="/opt/zimbra/backup/" my_logfile=zm_backup-$my_date.log error=ERROR if [ -e $my_logdir/zm_backup-$my_date.log ]; then echo "***** `date +%H:%M:%S` *****" >> $my_logdir$my_logfile && \ rm -rf /var/backups/opt 2>&1 >>$my_logdir$my_logfile && \ echo "*****Delete of Data complete *****" >>$my_logdir$my_logfile && \ echo "***** `date +%H:%M:%S` *****" >> $my_logdir$my_logfile else echo "No previous log file found for $my_date" >> $my_logdir$error$my_logfile exit 2 fi echo "Backup to tape completed on: $my_date at: `date +%H:%M:%S`" >> $my_logdir$my_logfile exit 0
Here is a complete example stanza for a the Bacula job I defined to do cold backups of Zimbra:
Job { Name = "Zimbra" Type = Backup Level = Full Messages = Standard Pool = BTRTG Priority = 10 FileSet = "Zimbra-set" Schedule = "ZimbraWeeklyFull" Storage = "Drive 2" Client = btrtg-fd ClientRunBeforeJob = "/usr/local/bin/zimbra_pre_back.sh" Write Bootstrap = "/var/bacula/zimbra_full.bsr" ClientRunAfterJob = "/usr/local/bin/zimbra_post_back.sh" }
I'm not sure if this will actually help anyone and the scripts could be easily made cleaner. It was just a working example of a config that is currently working with Bacula. I'm sure the existing scripts and perl code out there could also be altered to do the same thing.