I want to rsync resulting file/s should did I modify the the script properly?
code is toward the bottom. I have the remote computer set up for automatic ssh authentication.
Code:
#!/bin/bash
# This script will do various backups of Zimbra depending on wich you choose,
# most of them are cold backups except the msg backup wich hot copies the 'store'
# folder for possible individual mail retrival. 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.
#
# Usage: ZimBackup.sh full - For full backup (Cold)
# ZimBackup.sh diff - For diffrential backup (Cold)
# ZimBackup.sh msgfull - For complete message backup (Hot)
# ZimBackup.sh msgdiff - For diffrential message backup (Hot)
#
# 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 * * * ZimBackup.sh full > /dev/null 2>&1
#
# Bits and pieces was adopted from a script created by Daniel W. Martin, 9 Sept 2007
# Free to use and free of any warranty! Marcus Uddenhed, 3 feb 2008
#
# Last updated: 2008-03-09
ZimInstPath=/opt
ZimHome=zimbra
ZimBackupPath=/opt/backup
ZimTempPath=/opt/backup/tmp
# Do not change anything below this line unless you know what you are doing
pre_check() {
# Check to see if the tmp folder exist, and create if not
mkdir -p $ZimTempPath
# Check which zimbra version that is installed, for recovery purpose
sudo -u zimbra $ZimInstPath/$ZimHome/bin/zmcontrol -v > $ZimTempPath/zimbra_version.txt
}
full_backup() {
# Removing possible old zimbra backup folder
rm -r -f $ZimTempPath/$ZimHome
# Stopping Zimbra
/etc/init.d/zimbra stop
sleep 20
# Backing up zimbra folder
cp -rv $ZimInstPath/$ZimHome $ZimTempPath/
# Starting Zimbra
/etc/init.d/zimbra start
# Compressing backup for space reduction
tar -zcvf $ZimBackupPath/ZimBackupTypeFull_`date +%Y%m%d%H%M`.tar.gz -C $ZimTempPath $ZimHome zimbra_version.txt
}
diff_backup() {
# Hot sync before shutdown on zimbra folder
rsync -avHK --delete $ZimInstPath/$ZimHome $ZimTempPath/
# Stopping Zimbra
/etc/init.d/zimbra stop
sleep 20
# Cold sync of zimbra folder
rsync -avHK --delete $ZimInstPath/$ZimHome $ZimTempPath/
# Starting Zimbra
/etc/init.d/zimbra start
# Compressing backup for space reduction and removing unpacked folder
tar -zcvf $ZimBackupPath/ZimBackupTypeDiff_`date +%Y%m%d%H%M`.tar.gz -C $ZimTempPath $ZimHome zimbra_version.txt
}
msgfull_backup() {
# Removing possible old store backup folder
rm -r -f $ZimTempPath/store
# Make dir for hot sync
mkdir -p $ZimTempPath/store
# Hot sync of mailbox messages
rsync -avHK --delete $ZimInstPath/$ZimHome/store/0 $ZimTempPath/store/
# Compressing store folder for space reduction
tar -zcvf $ZimBackupPath/ZimBackupTypeMsg_`date +%Y%m%d%H%M`.tar.gz -C $ZimTempPath store zimbra_version.txt
}
msgdiff_backup() {
# Make dir for hot sync
mkdir -p $ZimTempPath/store
# Hot sync of mailbox messages
rsync -avHK --delete $ZimInstPath/$ZimHome/store/0 $ZimTempPath/store/
# Compressing store folder for space reduction
cd $ZimTempPath
tar -zcvf $ZimBackupPath/ZimBackupTypeMsg_`date +%Y%m%d%H%M`.tar.gz -C $ZimTempPath store zimbra_version.txt
}
################################
rsync -e ssh -varuzP $ZimBackupPath/ remotemachine:/backup
################################
case $1 in
full)
pre_check
full_backup
;;
diff)
pre_check
diff_backup
;;
msgfull)
pre_check
msgfull_backup
;;
msgdiff)
pre_check
msgdiff_backup
;;
*)
echo "Usage: ZimColdBackup.sh {full|diff|msgfull|msgdiff}"
;;
esac