Zimbra save all account and profile information on the LDAP database. Zimbra has no function for only import and export it’s account, although they have bundled Zimbra to Zimbra migration command. The Zimbra to Zimbra migration command export all mailbox and account while I only need a list of account with some primary fields like password, first name, full name, etc, especially for testing purpose only.
I decided to create a simple script that look for related information on Zimbra LDAP with the following algorithm :
- Check Zimbra version, because Zimbra 5 and Zimbra 6 has different method for accessing LDAP and also these are a few changes on Zimbra CLI. Zimbra 6 need paramater for command while Zimbra 5 doesn’t need it, e.g, on Zimbra 5, running zmprov gaa will list all Zimbra account but on Zimbra 6 we must use zmprov -l gaa to display same result.
- Export all account profile to temporary parameter and loop for all account
- Skip all system account : admin, ham, spam, galsync and wiki. All these system account doesn’t need to be exported because Zimbra will create all system account on installation process.
- Get all account identity/fields from Zimbra LDAP by using LDAPsearch command
- Create a text file with zmp extension. This file will contains zmprov ca command with proper parameter from step 4
- Create ldif file for updating Zimbra LDAP password, because Zimbra LDAP using SSHA encryption and the better method for updating Zimbra LDAP password is using ldapmodify command.
- Finish
Algorithm for Import Account
- Check whether user are already on Zimbra user environment or not
- Check is there existing zmp and ldif file (the result from export script)
- Import zmp file
- Run ldapmodify command to change Zimbra LDAP password by using ldif data
- Finish
Please remember that you must running export script by using root privilege but the import account must be run within Zimbra user environment (su – zimbra).
Look at following example to run Zimbra Account export script :
[code language=’cpp’]
su
cd /srv
wget -c http://vavai.com/wp-content/uploads/exim-acc-zcs.tar.gz
tar -zxvf exim-acc-zcs.tar.gz
cd exim-acc-zcs
./export-acc-zcs.sh
[/code]
The above command will produce zcs-acc-add.zmp and zcs-acc-mod.ldif file. Copy all four file (the last two are script file) onto some folder on target server and run the following command to import the account and it’s profile :
[code language=’cpp’]
su
su – zimbra
cd /home/vavai
./import-acc-zcs.sh
[/code]
Script has been sucessfully tested on Zimbra 6.0.5, 6.0.6 dan 6.0.7 on SUSE Linux Enterprise Server 11 and openSUSE 11.
Download Zimbra Account Export-Import Script by click on the download icon belows :
Script for export :
[code language=’cpp’]
#!/bin/sh
#Hapus Layar
clear
echo -e “###################################################################################”
echo -e “# Zimbra export-acc-zcs.sh ver 0.0.2 #”
echo -e “# Skrip untuk export account Zimbra berikut profile dan password #”
echo -e “# Masim ‘Vavai’ Sugianto – vavai@vavai.com – http://www.vavai.com #”
echo -e “# Untuk saran dan pertanyaan silakan menggunakan Milis Komunitas Zimbra Indonesia #”
echo -e “# Link Komunitas : http://www.zimbra.web.id – http://www.opensuse.or.id #”
echo -e “###################################################################################”
# /* Variable untuk bold */
ibold=”