Saturday 11 October 2014

Migrating an existing LDAP database to a new computer.

I recently migrated the LDAP database from a old server to a new, fresh, powerful engine running on CentOS.
The hardest part of the migration was, without any doubt, the LDAP part. There’s nearly no documentation so here’s a little howto.

Open file slapd.conf located under /etc/openldap/slapd.conf. In debian based systems, this file is located under /etc/ldap/slapd.conf.

There are two ways of copying LDAP data. We will check out by ldapsearch/ldapadd command.

By using ldapsearch/ldapadd command, we do not need to stop slapd daemon on server. So we can extract and migrate data with zero downtime.


i) In slapd.conf file, there are schema defined for ldap. Check for searchbase records.
e.g. dc=example, dc=com.

Note: Multiple records may be present in slapd.conf like "dc=example, dc=com", "dc=test, dc=int" etc.
Choose the data from which node you want to migrate. We are using data under node "dc=example, dc=com" in following example.

ii) Type command 
ldapsearch -xLLL -s sub -b "dc=example,dc=com" -D "<admin id>" -w "<password>" > ldapfile.ldif

Note:  Admin id (root dn) and password is mentioned in slapd.conf file.

iii) To import ldap data extracted in above file. Use following command on new server.
ldapadd -x -D "<admin dn>" -w "<password>" -f <path for ldif file>.ldif

No comments:

Post a Comment