Beruflich Dokumente
Kultur Dokumente
#!/bin/bash
time=`date +%Y-%m-%d_%H-%M-%S`
# Output date
say $GREEN"Backup started at "$RED"`date`"$GREEN"."
# Done!
say $GREEN"Zimbra backed up to "$CYAN$backup_dir$GREEN"!"
say $GREEN"Backup ended at "$RED"`date`"$GREEN".\e[0m"
Backup Simple con FTP
#!/bin/bash
# Live sync before stopping Zimbra to minimize sync time with the services down
# Comment out the following line if you want to try single cold-sync only
rsync -avHK --delete /opt/zimbra/ /backup/zimbra
# Now we need to shut down Zimbra to rsync any files that were/are locked
# whilst backing up when the server was up and running.
before2="$(date +%s)"
# Only enable the following command if you need all Zimbra user owned
# processes to be killed before syncing
# ps auxww | awk '{print $1" "$2}' | grep zimbra | kill -9 `awk '{print $2}'`
# Calculates and outputs amount of time the server was down for
after="$(date +%s)"
elapsed="$(expr $after - $before2)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo Server was down for: "$hours hours $minutes minutes $seconds seconds"
# Create a txt file in the backup directory that'll contains the current Zimbra
# server version. Handy for knowing what version of Zimbra a backup can be
restored to.
su - zimbra -c "zmcontrol -v > /backup/zimbra/conf/zimbra_version.txt"
# or examine your /opt/zimbra/.install_history
One further note: I have observed some odd behavior in this and other scripts that, when run from
the command line work flawlessly, but when run from crontab the script may get ahead of itself
and, for example, try to ftp the file before tar is done creating it; resulting in a useless backup.
Loading the script into crontab with the parameters to create a log file, for example
. /etc/zimbra.backup > /temp/zbackup.log 2>&1
seems to solve this problem (while creating the log, or showing the output on the screen, the script
seems to follow the sequence more carefully), while giving you a line-by-line record of the backup
procedure. In my installation with just over 3GB backed up, the logfile is 2.5 mb and is overwritten
each night.
NB You may find that using su on your operating system has problems and some services don't start
or stop correctly. If that's the case use 'sudo -u zimbra' in the following format for the commands:
sudo -u zimbra zmcontrol start