oZimbraBackup

– Installation – Configuration  – Troubleshooting – RestoreDownload – Source –


Full fledge backup script for Zimbra OSE version. Handles full and differential backups for complete Zimbra system or for Zimbra Store where mail resides.
The backup type for the message store within Zimbra is highly experimental as of today, see restore to get an understanding of why this is.
The latest version of this script works with Zimbra 8.6.x and newer, versions below 8.0.x needs to use version 1.0.5 due to compatibility issues. Scripts are tested on Ubuntu version 10.04.4 LTS & Ubuntu 14.04 LTS and Zimbra version 8.0.9 and 8.6.0.

Installation

The script can be placed anywhere on your system since it will be called through CRON or other scheduling services.
  • Unpack script to desired folder on your server.
  • Make sure it is owned på ROOT user and ZIMBRA group.
    # chmod 770 /path/to/script/oZimbraBackup.sh
    # chown root:zimbra /path/to/script/oZimbraBackup.sh
  • Configure script with desired settings, se configuration below.
  • Add desired CRON schedules, this is an example on a multiple schedule, where every Sunday a full backup is performed and Monday to Friday a differential backup is performed.
    00 23 * * 0     /path/to/script/oZimbraBackup.sh –full > /dev/null 2>&1
    00 12 * * 1-6   /path/to/script/oZimbraBackup.sh –diff > /dev/null 2>&1

If you are going to use file transfers in the script you need to install “Expect”, it’s used for building actions on top of programs that needs user input and do not have a sensible commandline options.

On Ubuntu install it like this.

# sudo apt-get install expect

On other systems you should be able to install it with the package software for that system in particular.

Back to top

Configuration

The script has a few configuration options available, below you can see those you must configure before running the script.
Global Settings
ZimInstPath=/opt # Installation path for Zimbra, excluding the Zimbra folder.
ZimHome=zimbra # The Zimbra installation folder, excluding path to folder.
ZimBackupPath= # Root folder for backup where backup files will be placed.
Log Settings
ZimLogEnable=no # 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= # Folder for log files
ZimLogVerbose=no # Activates extra logging information(yes/no)
File Transfer Settings
ZimFtpEnable=no # Enable/Disable ftp file transfer(yes/no)
ZimScpEnable=no # Enable/Disable scp file transfer(yes/no)
ZimFtpOpt=” # Extra options for ftp file transfer, see manual for ftp command
ZimScpOpt=” # Extra options for scp file transfer, see manual for scp command
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=14400 # Set in minutes above 0 to keep a desired amount of files locally,
# be sure to match the time with your backup schedules.
Back to top

Troubleshooting

When troubleshooting be sure to check your configuration of the script first so you haven’t made any typos when changing any settings.
The script itself should not generate much trouble when configured properly, should you experience any issues contact us via contact with a description of your problem and we will assist you as much as we can.

Restore

The script itself does not contain any restore options, this is something you have to do manually, below we will try to explain the way to restore from the backups the script have made.
Steps described below assumes some knowledge on how to use console commands on Ubuntu or other Linux distribution.
All examples below assumes default settings for installation directory on Ubuntu so make sure every path is accurate on your system before starting a restore.

System restore

System backups is the most common used functionality, it takes backup of every file in Zimbra thus is easier to restore.
Full system restore
Full backup takes and backups everything every time and is the easiest backup to restore.
Steps to take for restore.
  • Shutdown Zimbra services.
    # /etc/init.d/zimbra stop
  • Create temporary folder for restoration process.
    # mkdir -p /tmp/ZimRestore
  • Unpack latest full backup to the temporary directory created earlier, not into Zimbra installation directory.
    # tar xvfz ZimBackupSystemFull_2015xxxxxx.tar.gz -C /tmp/ZimRestore
  • move everything from within the unpacked Zimbra directory into the working directory of your Zimbra installation.
    # mv /tmp/ZimRestore/tf/zimbra/* /opt/zimbra/
  • Repair security rights on Zimbra directories and files.
    # /opt/zimbra/libexec/zmfixperms
  • Start Zimbra services.
    # /etc/init.d/zimbra start
  • Done.
Full system restore with differential on top
When using the differential backups you must do full backups to since differential backups rely on the latest full backup done.
Basically you have to restore the latest full backup first and then restore the latest differential backup that has been done after the latest full backup.
Steps to take for restore.
  • Shutdown Zimbra services.
    # /etc/init.d/zimbra stop
  • Create temporary folder for restoration process.
    # mkdir -p /tmp/ZimRestore
  • Unpack the latest full backup to the temporary directory created earlier, not into Zimbra installation directory.
    # tar xvfz ZimBackupSystemFull_2015xxxxxx.tar.gz -C /tmp/ZimRestore
  • Unpack the latest differential backup to same folder as the full backup.
    # tar xvfz ZimBackupSystemDiff_2015xxxxxx.tar.gz -C /tmp/ZimRestore
  • move everything from within the unpacked Zimbra directories into the working directory of your Zimbra installation.
    # mv /tmp/ZimRestore/tf/zimbra/* /opt/zimbra/
    # mv /tmp/ZimRestore/td/zimbra/* /opt/zimbra/
  • Repair security rights on Zimbra directories and files.
    # /opt/zimbra/libexec/zmfixperms
  • Start Zimbra services.
    # /etc/init.d/zimbra start
  • Done.
When an upgrade has failed after you made a full backup you must remember that it will restore the previous version of Zimbra for you since it will replace the complete Zimbra directory. In some rare cases you must do an re-installation of the same version on top of your restored Zimbra installation to get it to work, this is often a must if you restore to a completely freshly installed system.

Store restore

The script also makes it possible to take backup on the message store only in Zimbra. This type of backup is useful when you want the possibility to restore single mail files, the restore method is completely different from the system backups and requires deeper knowledge af the inner workings of Zimbra.
The information for each individual mail is stored in 2 ways, one part is in the database and the the other part is as an file under the Store directory of Zimbra. For now this script only supports the second part and messages can only be restored with an so called injection of mail through the file based storage back to users mailbox. All injected messages end up at inbox with injection date, this is a limitation of the zmlmtpinject command within Zimbra, this tool is foremost for testing purposes and not to used in a daily to daily mail restore routine.
Full Store restore
This backup takes a complete backup of the Store folder within Zimbra installation folder.
Steps to take for restore.
  • Create temporary folder for restoration process.
    # mkdir -p /tmp/ZimRestore
  • Unpack latest full Store backup to the temporary directory created earlier, not into Zimbra installation directory.
    # tar xvfz ZimBackupMsgFull_2015xxxxxx.tar.gz -C /tmp/ZimRestore
  • Identify ID number of user to which you want to restore from, this will generate quite the list, this can be fine tuned for better result.
    # grep -R “To: * <user@domain.com>” /opt/zimbra/store/*
    /opt/zimbra/store/0/1/msg/0/456-215.msg:To: <user@domain.com>
  • Search that users ID number in the temporary folder where you unpacked the backup for files with matching content to what user has given you.
    # grep -R “From: * <user@domain2.com>” /tmp/ZimRestore/tmf/zimbra/store/0/1/*
    /tmp/ZimRestore/tmf/zimbra/store/0/1/msg/0/3245-085.msg:From: <user@domain2.com>
    /tmp/ZimRestore/tmf/zimbra/store/0/1/msg/0/4265-365.msg:From: <user@domain2.com>
  • Inject each message file into users mailbox on the Zimbra server. This command is a bit trial and error, read up on what it does and what parameters to use, research these links on Google to start with: Google Search.
    # /opt/zimbra/bin/zmlmtpinject -s olduser /tmp/ZimRestore/tmf/zimbra/store/0/1/msg/0/4265-365.msg -r user@domain.com)
  • Tell the user that the messages has been restored.
Full Store restore with differential on top
When using the differential backups you must do full Store backups to since differential Store backups rely on the latest full backup done.
Basically you have to restore the latest full Store backup first and then restore the latest differential Store backup that has been done after the latest full backup.
Steps to take for restore
  • Create temporary folder for restoration process.
    # mkdir -p /tmp/ZimRestore
  • Unpack latest full Store backup to the temporary directory created earlier, not into Zimbra installation directory.
    # tar xvfz ZimBackupMsgFull_2015xxxxxx.tar.gz -C /tmp/ZimRestore
  • Unpack the latest differential Store backup to same folder as the full Store backup.
    # tar xvfz ZimBackupMsgDiff_2015xxxxxx.tar.gz -C /tmp/ZimRestore
  • Identify ID number of user to which you want to restore from, this will generate quite the list, this can be fine tuned for better result.
    # grep -R “To: * <user@domain.com>” /opt/zimbra/store/* /opt/zimbra/store/0/1/msg/0/456-215.msg:To: <user@domain.com>
  • Search that users ID number in the temporary folder where you unpacked the backup for files with matching content to what user has given you.
    # grep -R “From: * <user@domain2.com>” /tmp/ZimRestore/tmf/zimbra/store/0/1/* /tmp/ZimRestore/tmf/zimbra/store/0/1/msg/0/3245-085.msg:From: <user@domain2.com> /tmp/ZimRestore/tmf/zimbra/store/0/1/msg/0/4265-365.msg:From: <user@domain2.com>
  • Inject each message file into users mailbox on the Zimbra server. This command is a bit trial and error, read up on what it does and what parameters to use, research these links on Google to start with: Google Search
    # /opt/zimbra/bin/zmlmtpinject -s olduser /tmp/ZimRestore/tmf/zimbra/store/0/1/msg/0/4265-365.msg -r user@domain.com)
  • Tell the user that the messages has been restored.
If you have several differential Store backups you might need to restore each one in the search for the missing mail, this is somewhat tedious work so it is really up to you if you want to do it.
Back to top

Download

Download latest version here.

Users with Zimbra versions earlier than 8.0.2, please use version 1.0.5 since newer version is not compatible anymore.

Back to top

Source

Old versions and development status are available through the repository here: SVN
Back to top