How to migrate LDAP (database,schema,configuration) to other machine
Solution 1
The solution :
So here's what I did to make this works.
- Stop Slapd on main server
Slapcat databases from the main server (There are 2 database that needs to be exported. I use the "-n" tag
slapcat -n 0 -l (config file location)
This one will export all schema and cn=config and
slapcat -n 1 -l <database backup ldif path>
This on will export all user data that you keep in LDAP.
- SCP the 2 ldif file to the new server (make sure you installed LDAP on the server and make sure the configuration are almost identical to make this easier)
- stop slapd on the new server.
delete the content of folder
/etc/ldap/slapd.d
use slapadd to import the configuration to the new server
slapadd -n 0 -l (config ldif location)
-n 0 is for adding configuration back to LDAP
slapadd -n 1 -l (database ldif location)
-n 1 is for adding database back to LDAP
*EDIT: Somehow those command won't work on my 2nd 3rd .... and so on try. So The proper command That I've verfied that it works are
slapadd -n 0 -F /etc/ldap/slapd.d -l <config backup ldif path>
and
slapadd -n 1 -l <data backup ldif path>
- change the permission in the /etc/ldap/slapd.d folder (chown and chmod). I chown it to openldap and chmod it to 755
Also Change permission in the /var/lib/ldap folder (chown and chmod) to openldap
if you have certificate for TLS connection. Copy the certificates and keys from old server to new server to the same exact location. change the permission on the places.
- start slapd.
and it should be good to go.
Hopes this helps other people
Solution 2
Export both trees (cn=config
and your regular data) into LDIF, import them back on the new server (cn=config
first). Done.
Also, cn=config
is essentially just a collection of LDIF files and it might be possible to just copy this collection to the same relative location on the new server (while slapd
is not running).
Related videos on Youtube
J_LDAP
Updated on September 18, 2022Comments
-
J_LDAP over 1 year
I'm using openldap 2.4.40, and i need to migrate my existing ldap database, configuration, and schema (basically everything ldap server related) to a new machine.
the problem is, I use cn=config configuration not the old slapd.conf file anymore.
The documentation provided by openldap and other 3rd party websites only helps for migrating slapd.conf LDAP server, not LDAP server with the newer cn=config configuration file.
and also I have new schema (attributetype and objectclass), is there a way to migrate these to a new machine as easily as possible?
I need other way than reconfiguring and adding my schema manually one by one to the new machine.
This will be done with the intention of turning off the old machine most likely.
TL;DR Is there any way to conveniently migrate LDAP database, schema, configuration from 1 LDAP Server to a new LDAP Server with the intention of turning off the old machine
Thank you.
*Posted the answer below
- Julio
-
FooBee almost 8 yearsYou really should post your solution as an answer and not an edit to your question.
-
-
FooBee over 8 yearsThe schemas should be defined in
cn=schema,cn=config
(or something like that) and will be contained in the LDIF file. -
J_LDAP over 8 yearsOk thanks fot the answer. I'll give it a try later. Thank you so much.
-
sheldonkreger over 7 yearsI had issues with permissions on the database files in /var/lib/ldap which needed to be switched to owner ldap. Other than that, this was very smooth.
-
J_LDAP over 7 yearsglad it works well for you
-
hanzo2001 over 6 yearsthis needs more upvotes. I've been hunting down and testing for 2 weeks for my setup to work. THANK YOU
-
Fabiano Tarlao over 5 yearsIn my case only the schema worked as expected, the data has not be copied. In fact dataset /var/lib/ldap on destination does not contain any string regarding users... it seems nothing has happened. I had to manually copy the database in /var/lib/ldap from source to destination machine; I followed serverfault.com/questions/227813/openldap-replication-problem/…
-
mike almost 3 yearsIf You execute slapcat -n 0 -l (config file location) then Your current config file on server will be overwritten with that dump. This should be fixed. Also in my case it is not working at all i got an "error: slapcat: could not open database" only slapcat -n 1 is working but I need all schema config etc. My source LDAP server is very old Debian 4 ( etch ).
-
mike almost 3 yearsCould You show how to do it all in steps? I tried slapcat -n 0 from earlier answer but is not working with error: "slapcat: could not open database" with switch -n 1 it's dumping but I need whole copy of OpenLDAP slapd not just database. In my case source it's very old Debian 4 ( etch ) maybe it's important for that method.