# Do not change anything beyond this point
#########################################
# Test for an interactive shell
if [[ $- != *i* ]]
then say() { echo -e $1; }
# Colors, yo!
GREEN="\e[1;32m"
RED="\e[1;31m"
CYAN="\e[1;36m"
PURPLE="\e[1;35m"
else say() { true; } # Do nothing
fi
# Output date
say $GREEN"Backup started at "$RED"'date'"$GREEN"."
# Stop the Zimbra services
say $CYAN"Stopping the Zimbra services..."
say $PURPLE" This may take several minutes."
/etc/init.d/zimbra stop
# Create a logical volume called ZimbraBackup
say $GREEN"Creating a LV called ZimbraBackup:"$PURPLE
$lvcreate_cmd -L 10G -s -n ZimbraBackup /dev/$vol_group/$zimbra_vol
# Create a mountpoint to mount the logical volume to
say $GREEN"Creating a mountpoint for the LV..."
# WARNING: this is insecure!
mkdir -p /tmp/ZimbraBackup
# Mount the logical volume to the mountpoint
say $GREEN"Mounting the LV..."
# WARNING: remove nouuid option if the filesystem is not formatted as XFS !!!
mount -t $zimbra_vol_fs -o nouuid,ro /dev/$vol_group/ZimbraBackup /tmp/ZimbraBackup/
# Start the Zimbra services
say $CYAN"Starting the Zimbra services..."
# WARNING: it's safer not to put this command in background
/etc/init.d/zimbra start &
# For testing only
#say $RED"Press Enter to continue...\e[0m"
#read input
# Create the current backup
say $GREEN"Creating the backup directory and backup..."
mkdir -p $backup_dir
tar zcvf $backup_dir/zimbra.backup.tar.gz /tmp/ZimbraBackup/zimbra/ 2&> /dev/null
# Unmount /tmp/ZimbraBackup and remove the logical volume
say $GREEN"Unmounting and removing the LV."$PURPLE
umount /tmp/ZimbraBackup/
$lvremove_cmd --force /dev/$vol_group/ZimbraBackup
# Done!
say $GREEN"Zimbra backed up to "$CYAN$backup_dir$GREEN"!"
say $GREEN"Backup ended at "$RED"'date'"$GREEN".\e[0m"