You are on page 1of 3

Bacula pre/post cold backup scripts - Zimbra :: Wiki

1 de 3

http://wiki.zimbra.com/wiki/Bacula_pre/post_cold_backup_scripts

User Help | Forums | Blog | Contact Us | Buy Zimbra


Learn
Products
Community
Support
Partners
Downloads
About

From Zimbra :: Wiki


- This article is a community contribution and may include unsupported customizations for network edition customers.

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" (http://bacula.neocodesoftware.com) 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`

19/01/2015 11:42 a.m.

Bacula pre/post cold backup scripts - Zimbra :: Wiki

2 de 3

http://wiki.zimbra.com/wiki/Bacula_pre/post_cold_backup_scripts

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.
Verified Against: unknown
Article ID: http://wiki.zimbra.com/index.php?title=Bacula_pre/post_cold_backup_scripts
Retrieved from "http://wiki.zimbra.com/index.php?title=Bacula_pre/post_cold_backup_scripts&oldid=10217"
Category: Backup and Restore

Date Created: 5/8/2007


Date Modified: 09/7/2008

Zimbra.com
|
Popular Searches
|
About Zimbra

Learn
What is Zimbra?
Benefits
Demos and Videos
Industry Solutions
Customers
Case Studies
Awards

Products
Zimbra Collaboration Server
Zimbra Cloud and Virtualization
Zimbra Open Source
Zimbra Desktop
Compare Products
Pricing
Whats New
Downloads

Community
Forums
Documentation
Wiki
Blog
Gallery
Submit Bug
Release Status
Developer Zone
Contribute

19/01/2015 11:42 a.m.

Bacula pre/post cold backup scripts - Zimbra :: Wiki

3 de 3

http://wiki.zimbra.com/wiki/Bacula_pre/post_cold_backup_scripts

Support
Zimbra Support Program Overview
User Help
Zimbra Customer Support Portal

Partners
Zimbra Hosting Providers
Zimbra VARs
Zimbra Training Providers
Resources For Partners

About
Careers
News
Events
Webinars
Media
Contact Us
Twitter
LinkedIn
Facebook
Email Software
Email Hosting
Zimbra Mail Server
Email Archiving and Compliance Software
Calendar and Collaboration
Microsoft Outlook Alternative
Zimbra for BlackBerry & iPhone
Secure Email & Anti Spam
Unified Messaging
Zimbra powers collaboration for the way you work. Zimbra connects people and information with unified collaboration software that includes email,
calendaring, file sharing, activity streams, social communities and more. With technology designed for social, mobile and the cloud, Zimbra gives
individuals the flexibility to work from virtually anywhere, through nearly every computer, tablet and mobile device.

19/01/2015 11:42 a.m.

You might also like