[SOLVED] Yet Another Backup Script for Community Version

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
xenonsky
Posts: 8
Joined: Sat Sep 13, 2014 3:04 am

[SOLVED] Yet Another Backup Script for Community Version

Post by xenonsky »

That's exactly what I've done on my CentOS 6.x is to put sendmail on it and disable the service on startup.
len.1235
Posts: 2
Joined: Sat Sep 13, 2014 3:11 am

[SOLVED] Yet Another Backup Script for Community Version

Post by len.1235 »

Regarding Zimbra versions 8.0.2 and newer, here's a summary some of the information from around the forum regarding the changed backup requirement. I've included some specific command examples as well.
The file /opt/zimbra/data/ldap/mdb/db/data.mdb is thinly provisioned (also called sparsely filled) as of version 8.0.2 - This means that the file will expand to approximately 80 GB if copied using standard commands such as cp. If you tar the file with compression, you won't find out about the issue until you attempt to restore (the file will expand to the full 80 GB upon decompression).
You can verify the size characteristics of data.mdb with the following commands:
ls -lha /opt/zimbra/data/ldap/mdb/db/

Result: Fully provisioned size of the file.
du -sh /opt/zimbra/data/ldap/mdb/db/data.mdb

Result: Actual size of the file.
df -h

Result: Actual disk usage.
As indicated earlier in this thread, you must modify the standard Open Source backup procedure as follows:
1.) Copy the /opt/zimbra directory while excluding data.mdb

2.) Perform a special copy operation for data.mdb
For item 1, you can make use of an exclude flag. For item 2, you can use mdb_copy or zmslapcat. I've listed some example commands that will hopefully assist your understanding of how your backup script may change.
Notes: The following bash script commands are for example purposes only.

They were tested on Ubuntu 10.04 LTS. You can see both the mdb_copy as well

as the zmslapcat methods used here. You only need one of them. The zmslapcat

method may throw a checksum error. This is considered a poorly worded warning

message and should not affect your export.
zimbra_root_dir=/opt/zimbra #zimbra root directory path

backup_tmp_dir=/your/local/storage #Local Storage - Preferably not /tmp
mkdir $backup_tmp_dir

mkdir $backup_tmp_dir/ldap-backup

chgrp -R zimbra $backup_tmp_dir

chmod -R 775 $backup_tmp_dir
echo "Stopping zimbra at" $(date +"%Y-%m-%d %r")
service zimbra stop #stop the zimbra server
$($zimbra_root_dir/openldap/bin/mdb_copy $zimbra_root_dir/data/ldap/mdb/db $backup_tmp_dir/ldap-backup)

sudo -u zimbra $zimbra_root_dir/libexec/zmslapcat $backup_tmp_dir
$(tar --exclude=/opt/zimbra/data/ldap/mdb/db/* -cpzf $backup_tmp_dir/$backup_tar_filename $zimbra_root_dir)
service zimbra start #start the zimbra server
You must also modify the standard Open Source restore procedure as follows:
1.) Perform a separate restore step for data.mdb
Here are some example commands for both the mdb_copy and zmslapcat methods.
Notes: Here are some example commands that work in the bash shell on

Ubuntu 10.04 LTS. These commands would be used after you have successfully

restored all of the other zimbra files from backup. You only need to use one set

OR the other, NOT BOTH.
#Command Set 1: restoring ldap from a previous mdb_copy backup

#Zimbra should be stopped. You must change "/your/local/storage".

#Once you've copied data.mdb with mdb_copy, you are free to move it around

#using standard copy commands without it expanding to its fully provisioned size

#up until the point that Zimbra accesses the file again.
sudo cp /your/local/storage/ldap-backup/data.mdb /opt/zimbra/data/ldap/mdb/db

sudo chown zimbra:zimbra /opt/zimbra/data/ldap/mdb/db/data.mdb

sudo chmod 600 /opt/zimbra/data/ldap/mdb/db/data.mdb
#Command Set 2: restoring ldap from a previous zmslapcat backup

#Zimbra should be stopped. You must change "/your/local/storage".

#The zimbra user will need permission to operate in the directory that the

#ldap files are stored in from the backup process.

#You must change "mail.yourserver.com" to the name of your mailserver.

#You may see a checksum error during this method - this is considered a poorly

#worded warning and should not affect your import.
sudo chgrp zimbra /your/local/storage

sudo chmod 775 /your/local/storage

cd /your/local/storage

su zimbra

scp zimbra@mail.yourserver.com:/your/local/storage/ldap.bak /your/local/storage/ldap-provider.ldif

/opt/zimbra/libexec/zmslapadd /your/local/storage/ldap-provider.ldif
Brotherbbad
Posts: 15
Joined: Sat Sep 13, 2014 2:21 am

[SOLVED] Yet Another Backup Script for Community Version

Post by Brotherbbad »

Hi All,
After about a solid year of Running the backup script with a hitch, last night it failed with Zimbra user should never be root! I restarted zimbra (sudo su zimbra && zmcontrol restart) and checked the zimbra user... I'm still root. Can someone shed some light on what could have happened... please remember, I know just enough to be very dangerous... I'm still a noob.
Thank you all!
lenjet
Posts: 2
Joined: Sat Sep 13, 2014 3:23 am

[SOLVED] Yet Another Backup Script for Community Version

Post by lenjet »

It seems that Zimbra have done something to the 8.0.5 version, specifically to the data.mdb file as now rsync --exclude command doesn't seem to work and where before I had no issues it seems to be including this file in the hot sync backup meaning I am running out of space on my 60gb SSD
dghost
Posts: 1
Joined: Sat Sep 13, 2014 3:26 am

[SOLVED] Yet Another Backup Script for Community Version

Post by dghost »

rsync need -S option to handle this file efficiently
blason
Outstanding Member
Outstanding Member
Posts: 265
Joined: Sat Sep 13, 2014 2:13 am

[SOLVED] Yet Another Backup Script for Community Version

Post by blason »

see mdb_copy to copy .mdb files
JPascal
Posts: 11
Joined: Sat Sep 13, 2014 12:59 am

[SOLVED] Yet Another Backup Script for Community Version

Post by JPascal »

I had something very strange recently on my 7.2.5 server: my zimbra crontab disappeared regularly.
What happened is that when this script stops Zimbra, if there is an error, the script is stopped.
And before stopping Zimbra, the script disables zimbra cron. So if like me you have an errror message when stopping Zimbra, then you have no backup, and your cron file is gone.
I thought this experience could be useful to someone.
Cheers,
JPascal.
blason
Outstanding Member
Outstanding Member
Posts: 265
Joined: Sat Sep 13, 2014 2:13 am

[SOLVED] Yet Another Backup Script for Community Version

Post by blason »

Run
crontab -u zimbra /tmp/crontab.zimbra
JPascal
Posts: 11
Joined: Sat Sep 13, 2014 12:59 am

[SOLVED] Yet Another Backup Script for Community Version

Post by JPascal »

Thanks Blason.
Actually the crontab file is saved by the backup script in /opt/zimbra as crontab.org
So you can also try: crontab -u zimbra /opt/zimbra/crontab.org
Mr.Twister
Posts: 10
Joined: Sat Sep 13, 2014 2:55 am
Location: Moskow, Russia
ZCS/ZD Version: 8.7.11_GA_1854

[SOLVED] Yet Another Backup Script for Community Version

Post by Mr.Twister »

HELLO!
I USE THIS SCRIPT ABOUT 1 YEAR AND MEET WITH SOME TROUBLES.

I FIXED IT SO YOU CAN LOOK AT IT.
FIXED:

1. RESTORING ZIMBRA'S CRONTAB IN CASE OF ERRORS (IN SOME CASES SCRIPT DID NOT RESTORE IT)

2. MANAGE COLLECTING WEEK BACKUPS IN TO_MEDIA_DIR - YOU CAN SWITCH IT ON OR OFF

3. ADDED EXCLUSION OF MDB FILES IN RSYNC OPTION AND COPYING OF MDB FILES USING MDB_COPY
TO DO:

1. CREATE BACKUPS OF ZIMBRA FROM SNAPSHOT OF LVM VOLUME WITH ZIMBRA - IT DO NOT NEED HOT AN COLD RSYNC PASSES - LESSER ZIMBRA'S DOWNTIME

2. USING OF EXTERNAL CONF FILE TO SIMPLY REPLACE SCRIPT TO NEWER VERSION WITHOUT NEED TO EDIT SETTINGS IN IT
PLEASE LET ME KNOW IF YOU FIND SOMETHING WRONG.

zmbak_v.0.8.1.sh.txt
Post Reply