Difference between revisions of "Backing up and restoring Zimbra (Open Source Version)"

(Preparing to Back Up)
 
(31 intermediate revisions by 9 users not shown)
Line 1: Line 1:
 +
{{Archive}}{{Unsupported}}
 +
 
If you wish to have a more automated backup feature, you should try the [Network Version of Zimbra.]
 
If you wish to have a more automated backup feature, you should try the [Network Version of Zimbra.]
  
Line 17: Line 19:
  
  
If you get some kind of error, you may want to make sure that Zimbra has completly stopped by running:
+
If you get some kind of error, you may want to make sure that Zimbra has completely stopped by running:
  
 
>ps auxww | grep zimbra
 
>ps auxww | grep zimbra
Line 23: Line 25:
 
and kill any left over processes such as the log.
 
and kill any left over processes such as the log.
  
== Copying Your Working Files to a Safe Location ==
+
== Making a Backup ==
 
''Make sure that the copy location has enough space to support your backup copy (i.e. the /tmp folder probably isn't the best location). ''
 
''Make sure that the copy location has enough space to support your backup copy (i.e. the /tmp folder probably isn't the best location). ''
  
Line 29: Line 31:
 
Since all of the components Zimbra needs are stored in the Zimbra folder itself, you can simply copy the folder to a safe location.
 
Since all of the components Zimbra needs are stored in the Zimbra folder itself, you can simply copy the folder to a safe location.
  
It may be possible to create a cron job to do these tasks automatically.
+
It may be possible to create a cron job to do these tasks automatically. This it the command:
  
Copy Command: cp -r /opt/zimbra [location path]
+
>cp -rp /opt/zimbra [location of backup]/zimbra_backup
  
 
Depending on your hardware and the amount of data contained in your Zimbra installation, this process can take a while.
 
Depending on your hardware and the amount of data contained in your Zimbra installation, this process can take a while.
Line 38: Line 40:
  
 
== Restoring ==
 
== Restoring ==
''Before restoring, you should make sure that all of the processes accociated with the damaged/failed Zimbra installation are terminated. Failure to terminate all of the processes could have dire consquences. See "Preparing to Backup" for additional info.''  
+
''Before restoring, you should make sure that all of the processes associated with the damaged/failed Zimbra installation are terminated. Failure to terminate all of the processes could have dire consequences. See "Preparing to Backup" for additional info.''  
  
  
'''Rename your "broken" Zimbra installation.'''  
+
''' 1) Rename your "broken" Zimbra installation.'''  
  
You may be able to scavenge data, if needed. If you simply do not want the old data, you can skip this part.
+
You may be able to scavenge data, if needed. If you simply do not want the old data, you can skip this part. This is how you do it:
  
>[insert command for renaming here]
+
>mv /opt/zimbra /opt/zimbra_broken
  
''You may want to move it completly out of the /opt folder just to be safe.''
+
You may want to move it completly out of the /opt folder just to be safe. After that, copy your backup Zimbra installation to the /opt folder and name it "zimbra" by using the following commands:
  
Copy your backup Zimbra installation to the /opt folder and name it "zimbra".
+
>cp -rp [location of backup]/zimbra_backup /opt
  
>cp -r [location of backup] /opt
+
>mv /opt/zimbra_backup /opt/zimbra
  
>[insert command for renaming here]
 
  
  
 
+
''' 2) Download a dummy copy of Zimbra'''
'''Downloading a Dummy Copy of Zimbra'''
 
  
 
Now, we need to know what build/version of zimbra you were running. If you followed the backup instructions above, then the backup folder should be tagged with the version/build you have backed up.
 
Now, we need to know what build/version of zimbra you were running. If you followed the backup instructions above, then the backup folder should be tagged with the version/build you have backed up.
Line 63: Line 63:
 
You need to download the full install of the Zimbra version you were running. You may find all Zimbra releases at: [http://sourceforge.net/project/showfiles.php?group_id=153217 Sourceforge.]
 
You need to download the full install of the Zimbra version you were running. You may find all Zimbra releases at: [http://sourceforge.net/project/showfiles.php?group_id=153217 Sourceforge.]
  
If you don't know your version number, you can find it by [insert way here].
+
If you don't know your version number, you can find it by performing the following steps:
 +
cd /opt/zimbra
 +
cat .install_history
 +
 
 +
Review the output and there should be an entry near the bottom that will show the last upgrade/install you did. It looks something like this:
 +
1203106102: INSTALL SESSION START
 +
1203106124: UPGRADED zimbra-core-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
 +
1203106126: UPGRADED zimbra-ldap-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
 +
1203106134: UPGRADED zimbra-logger-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
 +
1203106150: UPGRADED zimbra-mta-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
 +
1203106154: UPGRADED zimbra-snmp-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
 +
1203106167: UPGRADED zimbra-store-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
 +
1203106171: UPGRADED zimbra-apache-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
 +
1203106173: UPGRADED zimbra-spell-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
 +
1203106173: INSTALL SESSION COMPLETE
 +
For non-rpm installations you might see .deb instead of .rpm but this should work on all platforms.
  
  
  
'''Installing the Dummy Copy of Zimbra'''
+
''' 3) Install the dummy copy of Zimbra'''
  
 
Once you have downloaded the tar file, you will need to uncompress it by:
 
Once you have downloaded the tar file, you will need to uncompress it by:
Line 73: Line 88:
 
>tar -xvzf [name of file].tgz
 
>tar -xvzf [name of file].tgz
  
This will create a folder in the directory named "zcs", cd to it and run the install script:
+
This will create a folder in the directory named "zcs", open it and run the install script:
  
 
>cd zcs
 
>cd zcs
Line 85: Line 100:
 
If all goes well, you will see the following:
 
If all goes well, you will see the following:
  
The Zimbra Collaboration Suite appears already to be installed.
+
''The Zimbra Collaboration Suite appears already to be installed.
  
It can be upgraded with no effect on existing accounts,
+
''It can be upgraded with no effect on existing accounts,
  
or the current installation can be completely removed prior
+
''or the current installation can be completely removed prior
  
to installation for a clean install.
+
''to installation for a clean install.
  
Do you wish to upgrade? [Y]  
+
''Do you wish to upgrade? [Y] ''
  
 
Choose Y.
 
Choose Y.
Line 99: Line 114:
  
 
The script will remove the existing packages, and install them again. '''The script will attempt to stop Zimbra Services and "UPGRADE FAILED - exiting". This is okay, simply rerun the script, and it will install normally.'''
 
The script will remove the existing packages, and install them again. '''The script will attempt to stop Zimbra Services and "UPGRADE FAILED - exiting". This is okay, simply rerun the script, and it will install normally.'''
 +
 +
If you experience error 389, -1, connection refused errors, please search the Forums. These errors are covered extensively.
 +
 +
 +
''' 4) Reset permissions'''
 +
 +
If you are up and running now, you may have one more hurdle to overcome: permissions.
 +
 +
You may need to reset the permissions on the message store by running the following:
 +
 +
>chown -R zimbra:zimbra /opt/zimbra/store
 +
 +
>chown -R zimbra.zimbra /opt/zimbra/index
 +
 +
Also as root run the following:
 +
/opt/zimbra/libexec/zmfixperms
 +
 +
 +
----
 +
----
 +
Some scripts can be found here: http://wiki.zimbra.com/index.php?title=Open_Source_Edition_Backup_Procedure
 +
 +
== Another option ==
 +
 +
'''Zimbra Backup and Restore "hot".'''
 +
[By Richardson Lima http://br.linkedin.com/in/richardsonlima ]
 +
--------------------------------------------------------------------------
 +
'''BACKUP'''
 +
--------------------------------------------------------------------------
 +
'''* Script 1'''
 +
* This script must be run as root, it runs the script runBackupAll.sh and also sends the entire backup to a second machine.
 +
 +
--------------------------------------------------------------------------
 +
echo "*******************************************************"
 +
echo "*    Zimbra - Backup all email accounts              *"
 +
echo "*******************************************************"
 +
echo""
 +
#
 +
echo Start time of the backup = $(date +%T) 
 +
before="$(date +%s)"
 +
#
 +
echo ""
 +
ZHOME=/opt/zimbra
 +
ZBACKUP=$ZHOME/backup/mailbox
 +
echo "Generating backup files ..."
 +
su - zimbra -c "/opt/backup/SCRIPT_ZIBRA_BACKUP_ALL_ACCOUNTS/zimbra_backup_allaccounts.sh"
 +
echo "Sending files to backup all email accounts for Machine2 (10.0.0.X - CrossOver Cable on eth1 \o/ ) ..."
 +
rsync -avH $ZBACKUP root@ipaddress:/opt/zimbra_backup_accounts
 +
before2="$(date +%s)"
 +
#
 +
echo The process lasted = $(date +%T)
 +
# Calculating time
 +
after="$(date +%s)"
 +
elapsed="$(expr $after - $before)"
 +
hours=$(($elapsed / 3600))
 +
elapsed=$(($elapsed - $hours * 3600))
 +
minutes=$(($elapsed / 60))
 +
seconds=$(($elapsed - $minutes * 60))
 +
echo The complete backup lasted : "$hours hours $minutes minutes $seconds seconds"
 +
 +
--------------------------------------------------------------------------
 +
'''* Script 2'''
 +
zimbraBackupAllAccounts.sh
 +
 +
 +
ZHOME=/opt/zimbra
 +
ZBACKUP=$ZHOME/backup/mailbox
 +
ZCONFD=$ZHOME/conf
 +
DATE=`date +"%a"`
 +
ZDUMPDIR=$ZBACKUP/$DATE
 +
ZMBOX=/opt/zimbra/bin/zmmailbox
 +
if [ ! -d $ZDUMPDIR ]; then
 +
mkdir -p $ZDUMPDIR
 +
fi
 +
echo " Running zmprov ... "
 +
        for mbox in `zmprov -l gaa`
 +
do
 +
echo " Generating files from backup $mbox ..."
 +
        $ZMBOX -z -m $mbox getRestURL "//?fmt=zip" > $ZDUMPDIR/$mbox.zip
 +
done
 +
--------------------------------------------------------------------------
 +
'''RESTORE'''
 +
--------------------------------------------------------------------------
 +
'''* Script 3'''
 +
* This script must be run as root, it runs the script runRestoreAll.sh and also sends the entire backup to machine.
 +
zimbra_restore_allaccounts.sh
 +
 +
 +
echo "*******************************************************"
 +
echo "*    Zimbra - Restore all email accounts              *"
 +
echo "*******************************************************"
 +
echo ""
 +
#
 +
echo Start Time Restore = $(date +%T)       
 +
before="$(date +%s)"
 +
#
 +
echo ""
 +
echo "Starting the process restore the backup files ..."
 +
su - zimbra -c "/opt/zimbra_backup_accounts/zimbra_restore_allaccounts.sh"
 +
before2="$(date +%s)"
 +
echo The process lasted = $(date +%T)
 +
# Calculating time
 +
after="$(date +%s)"
 +
elapsed="$(expr $after - $before)"
 +
hours=$(($elapsed / 3600))
 +
elapsed=$(($elapsed - $hours * 3600))
 +
minutes=$(($elapsed / 60))
 +
seconds=$(($elapsed - $minutes * 60))
 +
echo "The complete restore lasted : "$hours hours $minutes minutes $seconds seconds"
 +
echo "Process completed successfully!"
 +
 +
'''* Script 4'''
 +
zimbra_restore_allaccounts.sh
 +
 +
#!/bin/bash
 +
ZHOME=/opt/zimbra
 +
#!/bin/bash
 +
ZHOME=/opt/zimbra
 +
#ZBACKUP=$ZHOME/backup/mailbox
 +
ZBACKUP=/opt/zimbra_backup_accounts/mailbox
 +
ZCONFD=$ZHOME/conf
 +
DATE=`date +"%a"`
 +
ZDUMPDIR=$ZBACKUP/$DATE
 +
ZMBOX=/opt/zimbra/bin/zmmailbox
 +
if [ ! -d $ZDUMPDIR ]; then
 +
echo "Backups do not exist !"
 +
exit 255;
 +
fi
 +
for mbox in `zmprov -l gaa`
 +
do
 +
echo " Restoring files from backup $mbox ..."
 +
$ZMBOX -z -m $mbox postRestURL "//?fmt=zip&resolve=reset" $ZDUMPDIR/$mbox.zip
 +
done
 +
 +
 
 +
'''*** Soon I will be sending this improved script!'''''Italic text''
 +
 +
{{Article Footer|unknown and Richardson Lima|3/28/2006}}
 +
 +
[[Category:Backup and Restore]]

Latest revision as of 17:43, 24 March 2015


If you wish to have a more automated backup feature, you should try the [Network Version of Zimbra.]


Preparing to Back Up

Before we begin, make sure that you are logged in as a user that can perform the tasks outlined here.


It is always good practice to backup your copy of Zimbra in the event of unforeseen circumstances.

To prevent changes to any Zimbra databases during the backup processes you may wish to use:

>su zimbra

>zmcontrol stop

to terminate Zimbra.


If you get some kind of error, you may want to make sure that Zimbra has completely stopped by running:

>ps auxww | grep zimbra

and kill any left over processes such as the log.

Making a Backup

Make sure that the copy location has enough space to support your backup copy (i.e. the /tmp folder probably isn't the best location).


Since all of the components Zimbra needs are stored in the Zimbra folder itself, you can simply copy the folder to a safe location.

It may be possible to create a cron job to do these tasks automatically. This it the command:

>cp -rp /opt/zimbra [location of backup]/zimbra_backup

Depending on your hardware and the amount of data contained in your Zimbra installation, this process can take a while.

Note: It is a very good idea to tag your installation with the version/build of zimbra that will be backed up (ie 3.0.0_GA_156) and the date of backup. You'll need this later.

Restoring

Before restoring, you should make sure that all of the processes associated with the damaged/failed Zimbra installation are terminated. Failure to terminate all of the processes could have dire consequences. See "Preparing to Backup" for additional info.


1) Rename your "broken" Zimbra installation.

You may be able to scavenge data, if needed. If you simply do not want the old data, you can skip this part. This is how you do it:

>mv /opt/zimbra /opt/zimbra_broken

You may want to move it completly out of the /opt folder just to be safe. After that, copy your backup Zimbra installation to the /opt folder and name it "zimbra" by using the following commands:

>cp -rp [location of backup]/zimbra_backup /opt

>mv /opt/zimbra_backup /opt/zimbra


2) Download a dummy copy of Zimbra

Now, we need to know what build/version of zimbra you were running. If you followed the backup instructions above, then the backup folder should be tagged with the version/build you have backed up.

You need to download the full install of the Zimbra version you were running. You may find all Zimbra releases at: Sourceforge.

If you don't know your version number, you can find it by performing the following steps:

cd /opt/zimbra
cat .install_history

Review the output and there should be an entry near the bottom that will show the last upgrade/install you did. It looks something like this:

1203106102: INSTALL SESSION START
1203106124: UPGRADED zimbra-core-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
1203106126: UPGRADED zimbra-ldap-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
1203106134: UPGRADED zimbra-logger-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
1203106150: UPGRADED zimbra-mta-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
1203106154: UPGRADED zimbra-snmp-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
1203106167: UPGRADED zimbra-store-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
1203106171: UPGRADED zimbra-apache-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
1203106173: UPGRADED zimbra-spell-4.5.11_GA_1751.RHEL4-20080128130515.i386.rpm
1203106173: INSTALL SESSION COMPLETE

For non-rpm installations you might see .deb instead of .rpm but this should work on all platforms.


3) Install the dummy copy of Zimbra

Once you have downloaded the tar file, you will need to uncompress it by:

>tar -xvzf [name of file].tgz

This will create a folder in the directory named "zcs", open it and run the install script:

>cd zcs

>./install.sh

WARNING: Do not run the script with the -u option. You will remove all of your backup data & you must run the script as root, NOT ZIMBRA.


If all goes well, you will see the following:

The Zimbra Collaboration Suite appears already to be installed.

It can be upgraded with no effect on existing accounts,

or the current installation can be completely removed prior

to installation for a clean install.

Do you wish to upgrade? [Y]

Choose Y.


The script will remove the existing packages, and install them again. The script will attempt to stop Zimbra Services and "UPGRADE FAILED - exiting". This is okay, simply rerun the script, and it will install normally.

If you experience error 389, -1, connection refused errors, please search the Forums. These errors are covered extensively.


4) Reset permissions

If you are up and running now, you may have one more hurdle to overcome: permissions.

You may need to reset the permissions on the message store by running the following:

>chown -R zimbra:zimbra /opt/zimbra/store

>chown -R zimbra.zimbra /opt/zimbra/index

Also as root run the following:

/opt/zimbra/libexec/zmfixperms




Some scripts can be found here: http://wiki.zimbra.com/index.php?title=Open_Source_Edition_Backup_Procedure

Another option

Zimbra Backup and Restore "hot". [By Richardson Lima http://br.linkedin.com/in/richardsonlima ]


BACKUP


* Script 1 
* This script must be run as root, it runs the script runBackupAll.sh and also sends the entire backup to a second machine.

echo "*******************************************************"
echo "*     Zimbra - Backup all email accounts              *"
echo "*******************************************************"
echo""
#
echo Start time of the backup = $(date +%T)  
before="$(date +%s)"
#
echo ""
ZHOME=/opt/zimbra
ZBACKUP=$ZHOME/backup/mailbox
echo "Generating backup files ..."
su - zimbra -c "/opt/backup/SCRIPT_ZIBRA_BACKUP_ALL_ACCOUNTS/zimbra_backup_allaccounts.sh"
echo "Sending files to backup all email accounts for Machine2 (10.0.0.X - CrossOver Cable on eth1 \o/ ) ..."
rsync -avH $ZBACKUP root@ipaddress:/opt/zimbra_backup_accounts
before2="$(date +%s)"
#
echo The process lasted = $(date +%T)
# Calculating time
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo The complete backup lasted : "$hours hours $minutes minutes $seconds seconds"

* Script 2 
zimbraBackupAllAccounts.sh


ZHOME=/opt/zimbra
ZBACKUP=$ZHOME/backup/mailbox
ZCONFD=$ZHOME/conf
DATE=`date +"%a"`
ZDUMPDIR=$ZBACKUP/$DATE
ZMBOX=/opt/zimbra/bin/zmmailbox
if [ ! -d $ZDUMPDIR ]; then
mkdir -p $ZDUMPDIR
fi
echo " Running zmprov ... "
       for mbox in `zmprov -l gaa`
do
echo " Generating files from backup $mbox ..."
       $ZMBOX -z -m $mbox getRestURL "//?fmt=zip" > $ZDUMPDIR/$mbox.zip
done

RESTORE


* Script 3 
* This script must be run as root, it runs the script runRestoreAll.sh and also sends the entire backup to machine.
zimbra_restore_allaccounts.sh


echo "*******************************************************"
echo "*    Zimbra - Restore all email accounts              *"
echo "*******************************************************"
echo ""
#
echo Start Time Restore = $(date +%T)         
before="$(date +%s)"
#
echo ""
echo "Starting the process restore the backup files ..."
su - zimbra -c "/opt/zimbra_backup_accounts/zimbra_restore_allaccounts.sh"
before2="$(date +%s)"
echo The process lasted = $(date +%T)
# Calculating time
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo "The complete restore lasted : "$hours hours $minutes minutes $seconds seconds"
echo "Process completed successfully!"
* Script 4
zimbra_restore_allaccounts.sh
#!/bin/bash
ZHOME=/opt/zimbra
#!/bin/bash
ZHOME=/opt/zimbra
#ZBACKUP=$ZHOME/backup/mailbox
ZBACKUP=/opt/zimbra_backup_accounts/mailbox
ZCONFD=$ZHOME/conf
DATE=`date +"%a"`
ZDUMPDIR=$ZBACKUP/$DATE
ZMBOX=/opt/zimbra/bin/zmmailbox
if [ ! -d $ZDUMPDIR ]; then
echo "Backups do not exist !"
exit 255;
fi
for mbox in `zmprov -l gaa`
do
echo " Restoring files from backup $mbox ..."
$ZMBOX -z -m $mbox postRestURL "//?fmt=zip&resolve=reset" $ZDUMPDIR/$mbox.zip
done

  

*** Soon I will be sending this improved script!Italic text

Verified Against: unknown and Richardson Lima Date Created: 3/28/2006
Article ID: https://wiki.zimbra.com/index.php?title=Backing_up_and_restoring_Zimbra_(Open_Source_Version) Date Modified: 2015-03-24



Try Zimbra

Try Zimbra Collaboration with a 60-day free trial.
Get it now »

Want to get involved?

You can contribute in the Community, Wiki, Code, or development of Zimlets.
Find out more. »

Looking for a Video?

Visit our YouTube channel to get the latest webinars, technology news, product overviews, and so much more.
Go to the YouTube channel »

Jump to: navigation, search