By Srikanth Konjarla on Sep 19, 2008
I usually get a task to review a LDIF file. I get a LDIF file and i have to "see" the data for whatever task I have to accomplish.
For example, I have to split a "sub tree" under a particular root suffix into a separate database for say replication reasons. I know that, I have to separate the entries of a branch, create a new database and import only those entries pertaining the branch.
Another example would be to just separate a particular branch for review purposes. Perhaps, I can run "ldapsearch" on the live server and obtain data. There are two issues that I usually come across, one is that I may not get access to the server in the first place, secondly, I may not get "all" the data. So, I generally request for a LDIF export of the root suffix so that I can work "offline" on the LDIF.
To address this most common challenge I wrote myself a tool called "ldifpart", written in perl. It would read the LDIF and provides with different levels in the hierarchy, then it can include/exclude to print only entries under a particular sub-tree. This will let me "split" the LDIF at any level of the tree.
Let us look at an example. I wanted to just print the DNs of entries at different levels
$ ldifpart -d example_ldifpart.ldif
Now, suppose i want to branch out "ou=Groups" container to another database then i would need a LDIF that contains only entries under "ou=Groups" including.
$ ldifpart -b "ou=groups,o=corp"
Finally, the script normalizes the "DN" in the LDIF and unwraps the attributes that spawn across multiple lines. While this does not violate any LDIF standards some might perceive this as a "side effect". So, be warned. Enjoy.