Subversion Repositories oZimbraBackup

Compare Revisions

Ignore whitespace Rev 1 → Rev 2

/tags/1.0.0/src/changelog.txt
0,0 → 1,13
oZimbraBackup.sh Version 1.0 (2010-06-15)
===============================================
Our first versioned release.
 
Features:
* Full backup.
* Differential backup.
* Full message backup.
* Differential message backup.
* Logging cababilites.
* Offsite backup storage via FTP or SCP
Bugs:
* Our unversioned script had faulty differential backups. [Fixed]
/tags/1.0.0/src/license.txt
0,0 → 1,20
Copyright (c) 2010, 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.
/tags/1.0.0/src/oZimbraBackup.sh
0,0 → 1,700
#!/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 * * * oZimBackup.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.0
# Last updated: 2010-06-15 20:27
 
#### 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/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 ftp 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 [ $ZimFtpEnable = '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() {
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 $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 $ZimInstPath/$ZimHome $ZimFullTmpPath >> $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
 
else
 
# Hot sync before shutdown on zimbra folder
rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
 
# Stopping Zimbra
zimbra_stop
 
# Cold sync of zimbra folder
rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
 
# Starting Zimbra
zimbra_start
 
# Compressing backup for space reduction
tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt
fi
}
 
diff_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 $ZimDiffTmpPath/* >> $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 --delete --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 --delete --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
 
# Starting Zimbra
zimbra_start
 
# Syncing backup folders
echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders..." >> $ZimLogFile
cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/ >> $ZimLogFile
echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders done." >> $ZimLogFile
 
# 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 --delete --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
 
# Stopping Zimbra
zimbra_stop
 
# Cold sync of zimbra folder
rsync -avHK --delete --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
 
# Starting Zimbra
zimbra_start
 
# Syncing files from diff to full backup folder
cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/
 
# 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
 
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
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 --delete --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 --delete --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 [ $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
 
# 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
fi
fi
 
# Transfer with scp
if [ $ZimScpEnable == "yes" ]
then
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
 
# 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
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
sudo -u zimbra /opt/zimbra/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
sudo -u zimbra /opt/zimbra/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
#/etc/init.d/zimbra stop >> $ZimLogFile
sudo -u zimbra /opt/zimbra/bin/zmcontrol stop >> $ZimLogFile
 
# Sending task stop time to log
echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services stopped." >> $ZimLogFile
 
# Sleep for to give shutdown some extra time before backup starts
sleep 10
 
else
 
# Stopping Zimbra
sudo -u zimbra /opt/zimbra/bin/zmcontrol stop
 
fi
}
 
full_restore() {
echo "Full Restore under development"
}
 
diff_restore() {
echo "Diff Restore under development"
}
 
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
}
 
 
restore_guide() {
echo "Restore Guide"
}
 
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 "--restore-guide Shows a short guide on how to restore Zimbra"
#echo "--full-restore Does a complete restore"
#echo "--diff-restore Restores a differential backup"
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. Complete restore:"
#echo " oZimBackup.sh --full-restore /path/to/file/zimbackup.tar.gz"
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
;;
--full-restore)
full_restore
;;
--diff-restore)
diff_restore
;;
--restore-guide)
restore_guide
;;
--check)
pre_check
;;
--help)
script_help
;;
*)
script_help
;;
esac
/tags/1.0.0/src/readme.txt
0,0 → 1,57
oZimBackup v1.0.0
-----------------
 
1. About.
2. Requirements.
3. Installation.
4. Backup Scheduling.
5. Support.
 
 
1. About.
---------
oZimbraBackup is a backup script for Zimbra Collaboration Suite - Open Source Edition.
 
The main functionality is 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.
 
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.
 
The script has been tested with version 6.0.6 of Zimbra Collaboration Suite - OSE but should even work with the latest 5.x OSE branch.
 
 
2. Requirements.
----------------
This script utilize rsync, tar & gzip for basic functionality but needs scp, ftp & expect for file transfers.
 
 
3. Installation.
----------------
To install this script, simply put it where you want it and add it to crontab, make sure it is executable.
You can make it executable by doing this as root:
 
chmod +x oZimBackup.sh
 
 
4. Backup Scheduling.
---------------------
The scheduling of backups is highly individual depending on server load, amount of users a.s.o.
Some possible examples of scheduling with crontab:
 
# m h dom mon dow command
00 3 * * * /opt/scripts/oZimbraBackup.sh --full > /dev/null 2>&1
00 12 * * * /opt/scripts/oZimbraBackup.sh --msg-full > /dev/null 2>&1
00 6,16,23 * * * /opt/scripts/oZimbraBackup.sh --msg-diff > /dev/null 2>&1
 
 
5. Support.
-----------
Visit us at http://dev.osource.se/ for support and bug reporting.