Quote:
Originally Posted by mmarodin This is a per-user full backup script (based on mubley's code, 2005), for Zimbra 5.x. Zimbra DB and LDAP are also included.
I've tested it on 5.0.12 version.
I don't want to use ... Code: /opt/zimbra/bin/zmmailbox -z -m user@domain.com getRestURL “//?fmt=tgz” > /tmp/account.tgz ... because with this backup job I could not restore single messages, but only full mailbox.
I hope it could be usefull for you! Code: #!/bin/sh
#--------
# Backup Zimbra Open Source 5.x
# by mm@rodin - 20090206
# Modify the following variables to suit your installation
export time=`date +%y%m%d`
export backup_dir=/opt/backup
export zimbra_dir=/opt/zimbra
export index_dir=$zimbra_dir/index
export store_dir=$zimbra_dir/store
# We need mysqldump. If it doesn't exist,
# copy mysql and modify it to call mysqldump.
if [ ! -e $zimbra_dir/bin/mysqldump ]; then
cp $zimbra_dir/bin/mysql $zimbra_dir/bin/mysqldump
sed -i 's|/bin/mysql |/bin/mysqldump |g' $zimbra_dir/bin/mysqldump
fi
# Create the backup directory
mkdir -p $backup_dir
# Get a list of all accounts and execute
# the contents of the for-loop for each account.
for i in `$zimbra_dir/bin/zmprov gaa` ; do
# Beginning of for-loop
# Use email address to get zimbra_id
zimbraId=`$zimbra_dir/bin/zmprov ga $i |grep zimbraId |sed 's|zimbraId: ||g'`
set $zimbraId
# Use mysql to get number id
zimbra_nr=`$zimbra_dir/bin/mysql -e "use zimbra; select id from mailbox where account_id = '$1'"`
zimbra_nr=`echo $zimbra_nr | sed 's|id ||g'`
# Check to make sure we got a valid number id
if [ "$zimbra_nr" = "" ]; then
echo $i has no mailbox.
else
# Set zimbraAccountStatus to "maintenance"
$zimbra_dir/bin/zmprov ma $i zimbraAccountStatus maintenance
# Marking user backup
if [ ! -e $backup_dir/info-$zimbra_nr.txt ]; then
echo "Zimbra ID: $1" > $backup_dir/info-$zimbra_nr.txt
echo "Mail address: $i" >> $backup_dir/info-$zimbra_nr.txt
fi
# Backup index and store files
tar -czf $backup_dir/$time-$zimbra_nr-data.tgz $zimbra_dir/index/0/$zimbra_nr $zimbra_dir/store/0/$zimbra_nr
# Backup Mysql db
$zimbra_dir/bin/mysqldump mboxgroup$zimbra_nr > $backup_dir/$time-$zimbra_nr.dump
tar -czf $backup_dir/$time-$zimbra_nr.dump.tgz $backup_dir/$time-$zimbra_nr.dump
rm -f $backup_dir/$time-$zimbra_nr.dump
# Set zimbraAccountStatus to "active"
$zimbra_dir/bin/zmprov ma $i zimbraAccountStatus active
# End of if statement
fi
# End of for-loop
done
# Backup Zimbra master database and LDAP accounts database
# First, set all accounts to maintenance.
for i in `$zimbra_dir/bin/zmprov gaa` ; do
$zimbra_dir/bin/zmprov ma $i zimbraAccountStatus maintenance
done
$zimbra_dir/bin/mysqldump zimbra > $backup_dir/$time-zimbra.dump
tar -czf $backup_dir/$time-zimbra.dump.tgz $backup_dir/$time-zimbra.dump
rm -f $backup_dir/$time-zimbra.dump
$zimbra_dir/bin/zmslapcat > $backup_dir/$time-zimbra.ldap
tar -czf $backup_dir/$time-zimbra.ldap.tgz $backup_dir/$time-zimbra.ldap
rm -f $backup_dir/$time-zimbra.ldap
# Setting all accounts to active mode.
for i in `$zimbra_dir/bin/zmprov gaa` ; do
$zimbra_dir/bin/zmprov ma $i zimbraAccountStatus active
done
# Backup complete |
Hi Folks,
i know this thread is pretty old but i would like to tell you the needed corrections to be done to get it running because it hasnt been mentioned until now (i think

). We are testing zcs 6.04 FOSS on a 64bit Fedora11. As mentioned in some older posts the above script doesnt work 100% with newer releases of zcs. I have corrected the code and i think it works now. To get it running i had to change line 26 from:
"for i in `$zimbra_dir/bin/zmprov gaa` ; do"
to:
"for i in `$zimbra_dir/bin/zmprov -l gaa` ; do"
this has to be done 3 times, also in line 71 and line 84.
Then as mentioned by weigenmann on page 18 i changed line 76 (ignore the quotas):
from
"$zimbra_dir/bin/zmslapcat > $backup_dir/$time-zimbra.ldap"
to
"$zimbra_dir/libexec/zmslapcat > $backup_dir/$time-zimbra.ldap"
but then the generated file like weigenmann also realised only had following:
USAGE: zmslapcat <DIR>
I just removed the ">" (witout quotas) from the above line and that did the trick. But now you have to change the rm -f in line 77 to rm -rf because the script temporarily generates a folder now. Now when i unpack the tgz the file contains all the Infos from the ldap.
I am no scriptingguru but i think these small changes did it for us. Still one question keeps staying unanswered to me. Mmarodin mentioned that it should be possible to do message level restore could someone tell me how to do that? Any help is appreciated.
Best Regards
Needles