Subversion Repositories oZimbraBackup

Compare Revisions

No changes between revisions

Ignore whitespace Rev 5 → Rev 6

/tags/1.0.7/oZimbraBackup_1.0.7.tar.gz
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/tags/1.0.7/src/changelog.txt
0,0 → 1,52
2016-04-01 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (core): Fixed backup problem with LDAP database, using built in mdb_copy to not copy db file in sparse mode.
See following link for more info: https://wiki.zimbra.com/wiki/OpenLDAP_Performance_Tuning_8.0#mdb_copy_utility
* oZimbraBackup.sh (core): Removed some obsolete code.
 
2015-12-14 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (core): Modified path to zmcontrol for startup and shutdown.
* oZimbraBackup.sh (core): Removed obsolete code.
 
2014-05-18 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (core): Changed information regarding contact ways.
 
* readme.txt (text): Changed information regarding contact ways.
 
2012-09-30 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (core): Added an option to temporarily disable off-site file transfer with "--no-send" parameter.
 
2012-01-02 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (Logging): Added logging for file transfer in simple log mode.
 
2011-04-21 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (core): Changed how Zimbra startup & shutdown is called within the script.
 
2011-04-19 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (core): Reworked code for differential backups.
 
2010-08-06 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (pre_check): Fixed wrong variable name for SCP checking.
 
2010-07-10 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (Help): Fixed typo.
 
2010-07-02 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (text): Fixed typo.
 
* changelog.txt (text): fixed wrong file format.
 
2010-06-15 Marcus Uddenhed <marcus@osource.se>
 
* oZimbraBackup.sh (diff) fixed faulty differential backups.
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/tags/1.0.7/src/license.txt
0,0 → 1,20
Copyright (c) 2014, oSource Development
 
All rights reserved.
 
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the distribution.
 
* Neither the name of the oSource Development nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/tags/1.0.7/src/oZimbraBackup.sh
0,0 → 1,733
#!/bin/bash
 
#
# This script will do various backups of Zimbra depending on which you choose,
# most of them are cold backups except the msg backup which hot copies the 'store'
# folder for possible individual mail retrieval. Be sure to change the variables below
# to point to where you got the Zimbra folder and where you want it to be backed up to.
#
# This script must be run as root or a user with equal privileges or it will not work.
#
# When you run this script via crontab be sure to add '> /dev/null 2>&1' at the end
# of the script like below or the tar command will fail for no apparent reason.
# 00 12 * * * oZimbraBackup.sh --full > /dev/null 2>&1
#
# As of 2008-04-16 this script uses some extra software to extend this script,
# the scripts standard function will still function without these extra software's but if you
# intend to use this scripts built in file transfer functions you must install the described software below.
#
# Required software: rsync for normal operation and ftp or scp & expect for file transfer capabillities.
#
# Bits and pieces was adopted from a script created by Daniel W. Martin, 9 Sept 2007
# Licensed under BSDL license, see license.txt for information.
#
# Developer: oSource Development(as of 2009-07-01)
# DevTeam: Marcus Uddenhed
# Version: 1.0.7
# Updated: 2016-04-01 15:30
#
 
#### Global Settings ####
ZimInstPath=/opt # Installation path for Zimbra, excluding the Zimbra folder.
ZimHome=zimbra # The Zimbra installation folder, excluding path to folder.
ZimBackupPath=/opt/backup # Root folder for backup where backup files will be placed.
 
#### Log Settings ####
ZimLogEnable=yes # Turns logging on or off(yes/no).
ZimLogLogRotate=no # Enables log rotating(yes/no)
ZimLogRotateInt=day # How often should we rotate logs(day, week or month)
ZimLogPath=/opt/backup/logs # Folder for log files
ZimLogVerbose=no # Activates extra logging information(yes/no)
 
#### File Transfer Settings ####
 
# Enable Services (yes/no)
ZimFtpEnable=no # Enable/Disable ftp file transfer(yes/no)
ZimScpEnable=no # Enable/Disable scp file transfer(yes/no)
 
# Extra FTP Settings
ZimFtpOpt='' # Extra options for ftp file transfer, see manual for ftp command
 
# Extra SCP Settings
ZimScpOpt='' # Extra options for scp file transfer, see manual for scp command
 
# Common Settings
ZimFilehostUser= # Username for file transfers
ZimFilehostPass= # Password for file transfers
ZimFilehostAddress= # Host address for file transfers
ZimFilehostFolder= # Folder on host where files will be placed during file transfer
 
#### File Delete Settings ####
ZimDeleteLocalFile=no # Enable/Disable compressed backup file deletion after successful backup(yes/no)
ZimDeleteTimeSet=0 # Set in minutes above 0 to keep a desired amount of files locally,
# be sure to match the time with your backup schedules.
 
##### Do not change anything below this line unless you know what you are doing #####
 
# Fetch backup type
ZimBackupType=$1
 
pre_check() {
# Set default abort value
ZimAbort=0
 
# Check for rsync
if [ ! -e /usr/bin/rsync ]
then
echo "Cannot find rsync software..."
ZimAbort=1
fi
 
# Check for tar
if [ ! -e /bin/tar ]
then
echo "Cannot find tar software..."
ZimAbort=1
fi
 
# Check for gzip
if [ ! -e /bin/gzip ]
then
if [ ! -e /usr/bin/gzip ]
then
echo "Cannot find gzip software..."
ZimAbort=1
fi
fi
 
# Check if expect, ftp & scp is installed when file transfer is set to yes
if [ $ZimFtpEnable = 'yes' ] || [ $ZimScpEnable = 'yes' ]
then
if [ ! -e /usr/bin/expect ]
then
echo "cannot find expect command..."
ZimAbort=1
fi
if [ $ZimFtpEnable = 'yes' ]
then
if [ ! -e /usr/bin/ftp ]
then
echo "Cannot find ftp command..."
ZimAbort=1
fi
fi
 
if [ $ZimScpEnable = 'yes' ]
then
if [ ! -e /usr/bin/scp ]
then
echo "Cannot find scp command..."
ZimAbort=1
fi
fi
fi
 
if [ $ZimAbort = '1' ]
then
echo "Please install above software, script exiting..."
exit
fi
}
 
pre_load() {
# Get temporary folder layout
temp_folders
 
# Get backup file format
backup_file
 
# Get log file format
log_file
 
# Check to see if the backup folder exist, create if not
mkdir -p $ZimBackupPath
 
# Check which zimbra version that is installed, for recovery purposes
sudo -u zimbra $ZimInstPath/$ZimHome/bin/zmcontrol -v > $ZimBackupPath/zimbra_version.txt
}
 
full_backup() {
# Cleaning LDAP database from backup folder if exist.
if [ -f "$ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb" ];
then
rm $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb
fi
 
# Making backup
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
then
 
# Hot sync before shutdown on zimbra folder
echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
 
# Stopping Zimbra
zimbra_stop
 
# Cold sync of zimbra folder
echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
# Special LDAP DB copying needed.
$ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimFullTmpPath/$ZimHome/data/ldap/mdb/db >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
 
# Starting Zimbra
zimbra_start
 
# Compressing backup for space reduction
echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressed backup folder." >> $ZimLogFile
 
# Cleaning differential folder.
echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
 
else
 
# Hot sync before shutdown on zimbra folder
rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath
 
# Stopping Zimbra
zimbra_stop
 
# Cold sync of zimbra folder
rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath
# Special LDAP DB copying needed.
$ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimFullTmpPath/$ZimHome/data/ldap/mdb/db
 
# Starting Zimbra
zimbra_start
 
# Compressing backup for space reduction
tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt
 
# Cleaning differential folder.
rm -r -f $ZimDiffTmpPath/*
fi
}
 
diff_backup() {
# Checking if LDAP database folder exist and fix it.
if [ ! -f "$ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb" ];
then
if [ ! -d "$ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db" ]
then
mkdir -p $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db
fi
else
rm -R $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb
fi
 
# Make backup
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
then
 
# Hot syncing to backup folder
echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
 
# Stopping Zimbra
zimbra_stop
 
# Cold syncing to backup folder
echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
# Special LDAP DB copying needed.
$ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
 
# Starting Zimbra
zimbra_start
 
# Compressing backup folder
echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
 
else
 
# Hot sync before shutdown on zimbra folder
#rm -R $ZimDiffTmpPath/*
rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
 
# Stopping Zimbra
zimbra_stop
 
# Cold sync of zimbra folder
rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
# Special LDAP DB copying needed.
$ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db
# Starting Zimbra
zimbra_start
 
# Compressing backup for space reduction
tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt
fi
}
 
msgfull_backup() {
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
then
# Hot syncing to backup folder
echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
 
# Compressing backup folder
echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
 
echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
rm -r -f $ZimMsgDiffTmpPath/* >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
 
else
# Hot syncing to backup folder
rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath
 
# Compressing backup folder
tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt
 
# Cleaning differential folder
rm -r -f $ZimMsgDiffTmpPath/*
fi
}
 
msgdiff_backup() {
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
then
# Cleaning backup folder
#echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder..." >> $ZimLogFile
#rm -r -f $ZimMsgDiffTmpPath/* >> $ZimLogFile
#echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder done." >> $ZimLogFile
 
# Hot syncing to backup folder
echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
rsync -avHK --compare-dest=$ZimMsgFullTmpPath/ $ZimInstPath/$ZimHome/store $ZimMsgDiffTmpPath >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
 
# Compressing backup folder
echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmd zimbra_version.txt >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
 
else
# Cleaning backup folder
#rm -r -f $ZimMsgDiffTmpPath/*
 
# Hot syncing to backup folder
rsync -avHK --compare-dest=$ZimMsgFullTmpPath/ $ZimInstPath/$ZimHome/store $ZimMsgDiffTmpPath
 
# Compressing backup folder
tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmd zimbra_version.txt
fi
}
 
file_transfer() {
# Transfer with ftp
if [ $ZimFtpEnable == "yes" ]
then
if [ "$2" = "--no-send" ]
then
# If --no-send is set ignore sending file to off site.
echo "`date "+%Y-%m-%d %H:%M:%S"` - Backup not sending backup file to external storage, --no-send is set." >> $ZimLogFile
echo "Not sending backup to external storage, --no-send is set."
else
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
then
# Send task start time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage..." >> $ZimLogFile
 
# Make a temporary script for expect commands
touch $ZimBackupPath/ftp.exp
 
# Fill script with commands
echo '#!/usr/bin/expect --' >> $ZimBackupPath/ftp.exp
echo 'set timeout -1' >> $ZimBackupPath/ftp.exp
echo 'spawn ftp '$ZimFilehostAddress >> $ZimBackupPath/ftp.exp
echo 'expect ):' >> $ZimBackupPath/ftp.exp
echo 'send '$ZimFilehostUser'\r' >> $ZimBackupPath/ftp.exp
echo 'expect :' >> $ZimBackupPath/ftp.exp
echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/ftp.exp
echo 'expect >' >> $ZimBackupPath/ftp.exp
echo 'send '$ZimFtpOpt'\r' >> $ZimBackupPath/ftp.exp
echo 'send "send '$ZimBackupPath/$ZimBackupFile $ZimFilehostFolder/$ZimBackupFile'\r"' >> $ZimBackupPath/ftp.exp
echo 'expect >' >> $ZimBackupPath/ftp.exp
echo 'send quit\r' >> $ZimBackupPath/ftp.exp
echo 'expect closed' >> $ZimBackupPath/ftp.exp
 
# Run expect with created script
expect $ZimBackupPath/ftp.exp >> $ZimLogFile
 
# Delete temporary expect script
rm $ZimBackupPath/ftp.exp
 
# Send task stop time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage done." >> $ZimLogFile
 
else
 
# Send task start time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage..." >> $ZimLogFile
 
# Make a temporary script for expect commands
touch $ZimBackupPath/ftp.exp
 
# Fill script with commands
echo '#!/usr/bin/expect --' >> $ZimBackupPath/ftp.exp
echo 'set timeout -1' >> $ZimBackupPath/ftp.exp
echo 'spawn ftp '$ZimFilehostAddress >> $ZimBackupPath/ftp.exp
echo 'expect ):' >> $ZimBackupPath/ftp.exp
echo 'send '$ZimFilehostUser'\r' >> $ZimBackupPath/ftp.exp
echo 'expect :' >> $ZimBackupPath/ftp.exp
echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/ftp.exp
echo 'expect >' >> $ZimBackupPath/ftp.exp
echo 'send '$ZimFtpOpt'\r' >> $ZimBackupPath/ftp.exp
echo 'send "send '$ZimBackupPath/$ZimBackupFile $ZimFilehostFolder/$ZimBackupFile'\r"' >> $ZimBackupPath/ftp.exp
echo 'expect >' >> $ZimBackupPath/ftp.exp
echo 'send quit\r' >> $ZimBackupPath/ftp.exp
echo 'expect closed' >> $ZimBackupPath/ftp.exp
 
# Run expect with created script
expect $ZimBackupPath/ftp.exp
 
# Delete temporary expect script
rm $ZimBackupPath/ftp.exp
 
# Send task stop time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage done." >> $ZimLogFile
 
fi
fi
fi
 
# Transfer with scp
if [ $ZimScpEnable == "yes" ]
then
if [ "$2" = "--no-send" ]
then
# If --no-send is set ignore sending file to off site.
echo "`date "+%Y-%m-%d %H:%M:%S"` - Backup not sending backup file to external storage, --no-send is set." >> $ZimLogFile
echo "Not sending backup to external storage, --no-send is set."
else
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
then
 
# Send task start time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage..." >> $ZimLogFile
 
# Make a temporary script for expect commands
touch $ZimBackupPath/scp.exp
 
# Fill script with commands
echo '#!/usr/bin/expect --' >> $ZimBackupPath/scp.exp
echo 'set timeout -1' >> $ZimBackupPath/scp.exp
echo 'spawn scp '$ZimScpOpt $ZimBackupPath/$ZimBackupFile $ZimFilehostUser'@'$ZimFilehostAddress':'$ZimFilehostFolder >> $ZimBackupPath/scp.exp
echo 'expect :' >> $ZimBackupPath/scp.exp
echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/scp.exp
echo 'expect closed' >> $ZimBackupPath/scp.exp
 
# Run expect with created script
expect $ZimBackupPath/scp.exp >> $ZimLogFile
 
# Delete temporary expect script
rm $ZimBackupPath/scp.exp
 
# Send task stop time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage done." >> $ZimLogFile
 
else
 
# Send task start time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage..." >> $ZimLogFile
 
# Make a temporary script for expect commands
touch $ZimBackupPath/scp.exp
 
# Fill script with commands
echo '#!/usr/bin/expect --' >> $ZimBackupPath/scp.exp
echo 'set timeout -1' >> $ZimBackupPath/scp.exp
echo 'spawn scp '$ZimScpOpt $ZimBackupPath/$ZimBackupFile $ZimFilehostUser'@'$ZimFilehostAddress':'$ZimFilehostFolder >> $ZimBackupPath/scp.exp
echo 'expect :' >> $ZimBackupPath/scp.exp
echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/scp.exp
echo 'expect closed' >> $ZimBackupPath/scp.exp
 
# Run expect with created script
expect $ZimBackupPath/scp.exp
 
# Delete temporary expect script
rm $ZimBackupPath/scp.exp
 
# Send task stop time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage done." >> $ZimLogFile
 
fi
fi
fi
 
# Remove local file(s) if ZimDeleteLocalFile is set to 'yes'
if [ $ZimDeleteLocalFile == "yes" ]
then
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
then
 
# Send task start time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Deleting local file(s)..." >> $ZimLogFile
 
# Remove backup files matching criteria
find $ZimBackupPath -maxdepth 1 -type f -mmin +$ZimDeleteTimeSet -name ZimBackup\*.tar.gz -exec rm {} + >> $ZimLogFile
 
# Send task stop time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Deleting local file(s) done." >> $ZimLogFile
 
else
 
# Remove backup files matching criteria
find $ZimBackupPath -maxdepth 1 -type f -mmin +$ZimDeleteTimeSet -name ZimBackup\*.tar.gz -exec rm {} +
 
fi
fi
}
 
log_start() {
if [ $ZimLogEnable = 'yes' ]
then
 
# Sending backup start time to log
echo "" >> $ZimLogFile
echo "-------------------------------------------------------" >> $ZimLogFile
echo "Backup Started: `date "+%Y-%m-%d %H:%M:%S"` Type: $ZimBackupType" >> $ZimLogFile
 
fi
}
 
log_end() {
if [ $ZimLogEnable = 'yes' ]
then
 
# Sending backup stop time to log
echo "Backup Finished: `date "+%Y-%m-%d %H:%M:%S"` Type: $ZimBackupType" >> $ZimLogFile
echo "-------------------------------------------------------" >> $ZimLogFile
 
fi
}
 
zimbra_start() {
if [ "$2" = "--no-start" ]
then
# If --no-start is set ignore starting Zimbra
echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services not starting, --no-start is set." >> $ZimLogFile
echo "Zimbra services not starting, --no-start is set."
else
# Starting Zimbra
if [ $ZimLogEnable = 'yes' ]
then
# Sending task start time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services starting..." >> $ZimLogFile
 
# Starting Zimbra
su zimbra -c -l "$ZimInstPath/$ZimHome/bin/zmcontrol start" >> $ZimLogFile
 
# Send task stop time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services started." >> $ZimLogFile
 
else
 
# Starting Zimbra
su zimbra -c -l "$ZimInstPath/$ZimHome/bin/zmcontrol start"
 
fi
fi
}
 
zimbra_stop() {
# Stopping Zimbra
if [ $ZimLogEnable = 'yes' ]
then
 
# Sending task start time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services stopping..." >> $ZimLogFile
 
# Stopping Zimbra
su zimbra -c -l "$ZimInstPath/$ZimHome/bin/zmcontrol stop" >> $ZimLogFile
 
# Sending task stop time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services stopped." >> $ZimLogFile
 
# Sleep for 10 seconds to give shutdown some extra time before backup starts
sleep 10
 
else
 
# Stopping Zimbra
su zimbra -c -l "$ZimInstPath/$ZimHome/bin/zmcontrol stop"
 
# Sleep for 10 seconds to give shutdown some extra time before backup starts
sleep 10
 
fi
}
 
backup_file() {
# Checks what backup is choosen and sets file-name appropiate
 
# Full system backup
if [ "$ZimBackupType" = "--full" ]
then
ZimBackupFile=ZimBackupSystemFull_`date +%Y%m%d%H%M`.tar.gz
fi
 
# Differential system backup
if [ "$ZimBackupType" = "--diff" ]
then
ZimBackupFile=ZimBackupSystemDiff_`date +%Y%m%d%H%M`.tar.gz
fi
 
# Full message backup
if [ "$ZimBackupType" = "--msg-full" ]
then
ZimBackupFile=ZimBackupMsgFull_`date +%Y%m%d%H%M`.tar.gz
fi
 
# Differential message backup
if [ "$ZimBackupType" = "--msg-diff" ]
then
ZimBackupFile=ZimBackupMsgDiff_`date +%Y%m%d%H%M`.tar.gz
fi
}
 
log_file() {
# Check to see if the log folder exist, create if not
mkdir -p $ZimLogPath
 
# Check log intervall and decide which file-name to use
if [ "$ZimLogLogRotate" = "yes" ]
then
 
# Set log file-name to day
if [ "$ZimLogRotateInt" = "day" ]
then
 
# If file do not exist create it
touch $ZimLogPath/ZimBackupDay_`date +%Y-%m-%d`.log
 
# Set correct file-name
ZimLogFile=$ZimLogPath/ZimBackupDay_`date +%Y-%m-%d`.log
fi
 
# Set log file-name to week
if [ "$ZimLogRotateInt" = "week" ]
then
 
# If file do not exist create it
touch $ZimLogPath/ZimBackupWeek_`date +%Y-%V`.log
 
# Set correct file-name
ZimLogFile=$ZimLogPath/ZimBackupWeek_`date +%Y-%V`.log
fi
 
# Set log file-name to month
if [ "$ZimLogRotateInt" = "month" ]
then
 
# If file do not exist create it
touch $ZimLogPath/ZimBackupMonth_`date +%Y-%m`.log
 
# Set correct file-name
ZimLogFile=$ZimLogPath/ZimBackupMonth_`date +%Y-%m`.log
fi
 
else
 
# If file do not exist create it
touch $ZimLogPath/ZimBackup.log
 
# Set correct file-name
ZimLogFile=$ZimLogPath/ZimBackup.log
 
fi
}
 
temp_folders() {
# Create & set temp folders under $ZimBackupPath
ZimFullTmpPath=$ZimBackupPath/tf
ZimDiffTmpPath=$ZimBackupPath/td
ZimMsgFullTmpPath=$ZimBackupPath/tmf
ZimMsgDiffTmpPath=$ZimBackupPath/tmd
mkdir -p $ZimFullTmpPath
mkdir -p $ZimDiffTmpPath
mkdir -p $ZimMsgFullTmpPath
mkdir -p $ZimMsgDiffTmpPath
}
 
script_help() {
# Show help for script
echo "oZimBackup.sh Usage:"
echo ""
echo "--full For full backup (Cold)"
echo "--diff For differential backup (Cold)"
echo "--msg-full For complete message backup (Hot)"
echo "--msg-diff For differential message backup (Hot)"
echo "--check Check if needed software is installed, depends"
echo " on script configuration"
echo "--help Shows this help"
echo ""
echo "--no-start Tells Zimbra to stay offline after backup"
#echo "<file to restore> File to restore from"
echo ""
echo "Ex. Full backup:"
echo " oZimBackup.sh --full"
echo ""
echo "Ex. Full differential backup leaving Zimbra in offline mode:"
echo " oZimBackup.sh --diff --no-start"
echo ""
}
 
case $1 in
--full)
pre_check
pre_load
log_start
full_backup
file_transfer
log_end
;;
--diff)
pre_check
pre_load
log_start
diff_backup
file_transfer
log_end
;;
--msg-full)
pre_check
pre_load
log_start
msgfull_backup
file_transfer
log_end
;;
--msg-diff)
pre_check
pre_load
log_start
msgdiff_backup
file_transfer
log_end
;;
--check)
pre_check
;;
--help)
script_help
;;
*)
script_help
;;
esac
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/tags/1.0.7/src/readme.txt
0,0 → 1,37
oZimBackup v1.0.7 2016-04-01
----------------------------
 
Overview:
---------
oZimbraBackup is a backup script for Zimbra Collaboration Suite - Open Source Edition.
 
Purpose:
--------
The ability to take different types of backup and sending them off site.
 
The script has the following features:
* Full backup.
* Differential backup.
* Full message store backup.
* Differential message store backup.
* Backup packaging.
* Off site transfer via SCP or FTP.
* Logging with log file rotation.
 
Notes:
------
This script utilize rsync, tar & gzip for basic functionality but needs scp, ftp & expect for file transfers.
 
The script is pre-configured with some basic options, open up the script in a text editor of your choice
and change the options to suite your needs.
 
Has been tested with version 8.0.x & 8.6.x of Zimbra Collaboration Suite but should work on newer versions,
Will not work with earlier versions than 8.0.2 anymore, due to LDAP DB handling.
 
Disclaimer:
-----------
This software is released with the BSDL license and the license is in the license.txt file that should accompany this software.
 
Contact:
--------
http://www.osource.se/
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property