Hi all !
I am using on of the scripts found in the wiki to backup my Zimbra server.
I have two servers (one in production and one pn my LAN), both are running Centos 5.4 and Zimbra 6.0.5.
I used the method described in
Open Source Edition Backup Procedure : 1.2 More elaborated script, using LVM and rsync
I just modified the rsync options, because rsync -aAK complained about ACL errors (I don't understand why this "A" option was there, so I removed it and used -aHK).
The process is :
- At 01:00, on production server :
- Stop zimbra
- Create Snapshot LV of /opt
- Start zimbra
- rsync -aHK /opt-snapshot/zimbra to /opt.bak/zimbra.01h00
- Remove Snapshot LV (process takes less than 10 minutes)
- At 02:00, on backup server :
When I checked my local backup today, it was stopped and could not start :
Code:
Starting ldap...Done.
Failed.
Failed to start slapd. Attempting debug start to determine error.
hdb_db_open: database "": db_open(/opt/zimbra/data/ldap/hdb/db/id2entry.bdb) failed: Invalid argument (22).
backend_startup_one (type=hdb, suffix=""): bi_db_open failed! (22)
bdb_db_close: database "": alock_close failed
So I guess my backup is NOT consistent, even though I stopped zimbra before creating the snapshot.
Any idea of what went wrong here ?
As a side note, here is the email I received from the latest cron job (indicating that everything ran fine apparently) :
Code:
2010-03-08 01:00:01 zimbra backup: backup started
2010-03-08 01:00:01 zimbra backup: stopping the Zimbra services, this may take some time
2010-03-08 01:00:32 zimbra backup: creating a LV called LogVolOptSnapshot
Logical volume "LogVolOptSnapshot" created
2010-03-08 01:00:33 zimbra backup: starting the Zimbra services in the background.....
2010-03-08 01:00:33 zimbra backup: creating mountpoint for the LV
2010-03-08 01:00:33 zimbra backup: mounting the snapshot LogVolOptSnapshot
2010-03-08 01:00:33 zimbra backup: rsyncing the snapshot to the backup directory
2010-03-08 01:01:28 zimbra backup: unmounting the snapshot
2010-03-08 01:01:28 zimbra backup: pausing 1s and syncing before removing the snapshot from LVM
2010-03-08 01:01:30 zimbra backup: removing the snapshot
Logical volume "LogVolOptSnapshot" successfully removed
2010-03-08 01:01:31 zimbra backup: backup ended
2010-03-08 01:03:59 zimbra backup: services background startup completed
I post the complete scripts below :
Backup script on production server :
Code:
#!/bin/bash
#
# Script to backup a Zimbra installation (open source version)
# by installing the Zimbra on a separate LVM Logical Volume,
# taking a snapshot of that partition after stopping Zimbra,
# restarting Zimbra services, then rsyncing the snapshot to a
# separate backup point.
# This script was originally based on a script found on the Zimbra wiki
# http://wiki.zimbra.com/index.php?title=Open_Source_Edition_Backup_Procedure
# and totally rewritten since then.
# Copyright (C) 2007 Serge van Ginderachter <svg@ginsys.be>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or download it from http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
####################################################################################
# Read config
source /root/zmbackup/zmbackup_01h00.config
##########################################
# Do not change anything beyond this point
##########################################
pause() {
if [ -n "$debug" ]; then
echo "Press Enter to execute this step..";
read input;
fi
}
say() {
MESSAGE_PREFIX="zimbra backup:"
MESSAGE="$1"
TIMESTAMP=$(date +"%F %T")
echo -e "$TIMESTAMP $MESSAGE_PREFIX $MESSAGE"
logger -t $log_tag -p $log_facility.$log_level "$MESSAGE"
logger -t $log_tag -p $log_facility_mail.$log_level "$MESSAGE"
pause
}
error () {
MESSAGE_PREFIX="zimbra backup:"
MESSAGE="$1"
TIMESTAMP=$(date +"%F %T")
echo -e $TIMESTAMP $MESSAGE >&2
logger -t $log_tag -p $log_facility.$log_level_err "$MESSAGE"
logger -t $log_tag -p $log_facility_mail.$log_level_err "$MESSAGE"
echo $TIMESTAMP $MESSAGE | mail -s "Zimbra Backup - Erreur" arnaud.lesauvage@codata.eu
exit
}
# load kernel module to enable LVM snapshots
/sbin/modprobe dm-snapshot || error "Error loading dm-snapshot module"
# Output date
say "backup started"
# Stop the Zimbra services
say "stopping the Zimbra services, this may take some time"
/etc/init.d/zimbra stop || error "error stopping Zimbra"
[ "$(ps -u zimbra -o "pid=")" ] && kill -9 $(ps -u zimbra -o "pid=") #added as a workaround to zimbra bug 18653
# Create a logical volume called ZimbraBackup
say "creating a LV called $zm_snapshot"
$LVCREATE -L $zm_snapshot_size -s -n $zm_snapshot /dev/$zm_vg/$zm_lv || error "error creating snapshot, exiting"
# Start the Zimbra services
say "starting the Zimbra services in the background....."
(/etc/init.d/zimbra start && say "services background startup completed") || error "services background startup FAILED" &
# Create a mountpoint to mount the logical volume to
say "creating mountpoint for the LV"
mkdir -p $zm_snapshot_path || error "error creating snapshot mount point $zm_snapshot_path"
# Mount the logical volume snapshot to the mountpoint
say "mounting the snapshot $zm_snapshot"
mount /dev/$zm_vg/$zm_snapshot $zm_snapshot_path
# Create the current backup
say "rsyncing the snapshot to the backup directory $backup_dir"
rsync -aHK$V --delete --inplace $zm_snapshot_path/$zm_path/ $zm_backup_path || say "error during rsync but continuing the backup script"
# Unmount $zm_snapshot from $zm_snapshot_mnt
say "unmounting the snapshot"
umount $zm_snapshot_path || error "error unmounting snapshot"
# Delete the snapshot mount dir
rmdir $zm_snapshot_path
# Remove the snapshot volume
# https://bugs.launchpad.net/ubuntu/+source/linux-source-2.6.15/+bug/71567
say "pausing 1s and syncing before removing the snapshot from LVM"
sleep 1 ; sync
say "removing the snapshot"
$LVREMOVE --force /dev/$zm_vg/$zm_snapshot || say "error removing the snapshot"
# Done!
say "backup ended"
date >$zm_backup_path/lastsync Backup Script configuration file (/root/zmbackup/zmbackup_01h00.config) :
Code:
#!/bin/bash
#
# Copyright (C) 2007 Serge van Ginderachter <svg@ginsys.be>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or download it from http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#### Modify the following variables according to your installation
# backup_dir - directory to backup to
zm_backup_path=/opt.bak/zimbra.01h00/
# zm_lv - the Logical Volume that contains /opt/zimbra - /opt mount point expected
zm_lv=LogVolOpt
# vol_group - the Volume Group that contains $zm_lv
zm_vg=VolGroupOpt
# zimbra_path - the path beneath the Logical Volume $zm_lv that needs to be synced
zm_path=zimbra
# zm_lv_fs - the file system type (ext3, xfs, ...) in /opt/zimbra
zm_lv_fs=ext3
# lvcreate lvremove - path and command for the lvm logical volume creation and deletion command
LVCREATE=/usr/sbin/lvcreate
LVREMOVE=/usr/sbin/lvremove
#### Modify the following variables according to your taste and needs
# zmsnapshot - the snapshot volume name for $zm_lv
zm_snapshot=LogVolOptSnapshot
# zmsnapshot_size - size avalable for growing the snapshot
zm_snapshot_size=20GB
# zm_snapshot_mnt - zimbra snapshot mount point
zm_snapshot_path=/tmp/opt.snapshot
# rsync verbose set to "v"
# V=v
V=
# pause at each step if $debug is set to a non-zero string
debug=
#### Following parameters probably shouldn't need to be changed
log_facility=daemon
log_facility_mail=mail
log_level=notice
log_level_err=error
log_tag="$0"
Local script to sync backup server :
Code:
#!/bin/bash
/etc/init.d/zimbra stop
[ "$(ps -u zimbra -o "pid=")" ] && kill -9 $(ps -u zimbra -o "pid=")
rsync -avzHK --delete -e "ssh -i <my_private_key>" root@<production_server_ip_address>:/opt.bak/zimbra.01h00/ /opt/zimbra/
/etc/init.d/zimbra start
Any help would be greatly appreciated !
Thanks a lot !