You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@directory.apache.org by Mihamina RKTMB <mi...@rktmb.org> on 2014/02/01 18:42:55 UTC

[Studio] command line equivalent of import

Hi,

For several reasons, we have to often re-import our directory (OpenLDAP).

This is because we encoutered a bug that a reimport solves. We're stuck 
on this for the moment.

Reimporting is done with Apache directory Studio by
- exporting the tree to ldif
- importing the exported ldif (overwriting existing entries)

As far as I do it, I woul like to make it through command line, on the 
primary directory itself (not from remote).

The exported ldif is quite the same as a "ldapsearch" bare result. No 
problem there.

The problem is how to script the importing part.
- just "ldapmodify -f exported.ldif" lead to errors because of already 
existing entries
- spliting the export to per-dn files would be possible, but still need 
to insert the "changetype" + "replace" statements in ldif.

So,
Would you know a scripted way to import as Studio would?

Re: [Studio] command line equivalent of import

Posted by Stefan Seelmann <ma...@stefan-seelmann.de>.
On 02/01/2014 06:42 PM, Mihamina RKTMB wrote:
> Reimporting is done with Apache directory Studio by
> - exporting the tree to ldif
> - importing the exported ldif (overwriting existing entries)
> 
> Would you know a scripted way to import as Studio would?

What Studio does is:
1) try to add the entry
2) if that fails with error 68: use changetype:modify and replace each
attribute with all its values defined in the LDIF.

This approach often works but is not a perfect "replace" mechanism. If
an attribute exists within the LDAP server but the same attribute is not
contained in the LDIF then the attribute will not be deleted but remains
unchanged.

So with a script language of your choice you can change the LDIF as
follows (check if you have wrapped lines):

    dn: cn=fbar,ou=users,dc=example.dc=com
    objectClass: person
    objectClass: top
    cn: fbar
    ...

to

    dn: cn=fbar,ou=users,dc=example.dc=com
    changetype: modify
    replace: objectClass
    objectClass: person
    objectClass: top
    -
    replace: cn
    cn: fbar
    -
    ....



Another thing you may do with a bit sed magic: replace the "dn: " lines
(check if you have wrapped lines) with a changetype:delete and a
changetype:add instruction. For Example:

    dn: cn=fbar,ou=users,dc=example.dc=com
    objectClass: person
    ...

becomes

    dn: cn=fbar,ou=users,dc=example.dc=com
    changetype: delete

    dn: cn=fbar,ou=users,dc=example.dc=com
    changetype: add
    objectClass: person
    ...

Note that this will delete each entry first, operational attibutes
(createTimestamp, entryUUID) will change!


Kind Regards,
Stefan


Re: [Studio] command line equivalent of import

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 2/2/14 4:58 PM, Mihamina RKTMB a écrit :
> On 02/02/2014 10:11 AM, Emmanuel Lécharny wrote:
>> What is your bug ? Which version of OpenLDAP are you using ?
>
> The bug is a bit long to describe rigth now as it involves "dynamic
> groups" & Apache HTTPd.

Have you posted a description of your problem on the OpenLDAP mailing
list ? This is extremely doubtful that OpenLDAP has a bug that forces
you to reimport your data, but without a clear description of your
problem, it's hard to tell...


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: [Studio] command line equivalent of import

Posted by Mihamina RKTMB <mi...@rktmb.org>.
On 02/02/2014 10:11 AM, Emmanuel Lécharny wrote:
> What is your bug ? Which version of OpenLDAP are you using ?

The bug is a bit long to describe rigth now as it involves "dynamic 
groups" & Apache HTTPd.

This list is not the right one for that.

Regards.

Re: [Studio] command line equivalent of import

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 2/1/14 6:42 PM, Mihamina RKTMB a écrit :
> Hi,
>
> For several reasons, we have to often re-import our directory (OpenLDAP).
>
> This is because we encoutered a bug that a reimport solves. We're
> stuck on this for the moment.

What is your bug ? Which version of OpenLDAP are you using ?

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: [Studio] command line equivalent of import

Posted by Mihamina RKTMB <mi...@rktmb.org>.
On 02/01/2014 08:59 PM, Jim Willeke wrote:
> Most ldapseach command line tools have a
> -c     Continuous  operation  mode.  Errors are reported, but ldapsearch
> will continue with searches.    The default is to exit after reporting an
> error.  Only useful in conjunction with -f.

Thanks,

That is about export. As stated in the original post, I already got the 
command line equivalent.


For importing by overwriting, I think I have to tweak the exported ldif.
Would you know how can I do it command line?
- Looping on each dn ok easy to write.
-- Looping on each attribute in order to specify the replace operation 
is more complicated because of some multi-line values...



Re: [Studio] command line equivalent of import

Posted by Jim Willeke <ji...@willeke.com>.
Most ldapseach command line tools have a
-c     Continuous  operation  mode.  Errors are reported, but ldapsearch
will continue with searches.    The default is to exit after reporting an
error.  Only useful in conjunction with -f.




--
-jim
Jim Willeke


On Sat, Feb 1, 2014 at 12:42 PM, Mihamina RKTMB <mi...@rktmb.org> wrote:

> Hi,
>
> For several reasons, we have to often re-import our directory (OpenLDAP).
>
> This is because we encoutered a bug that a reimport solves. We're stuck on
> this for the moment.
>
> Reimporting is done with Apache directory Studio by
> - exporting the tree to ldif
> - importing the exported ldif (overwriting existing entries)
>
> As far as I do it, I woul like to make it through command line, on the
> primary directory itself (not from remote).
>
> The exported ldif is quite the same as a "ldapsearch" bare result. No
> problem there.
>
> The problem is how to script the importing part.
> - just "ldapmodify -f exported.ldif" lead to errors because of already
> existing entries
> - spliting the export to per-dn files would be possible, but still need to
> insert the "changetype" + "replace" statements in ldif.
>
> So,
> Would you know a scripted way to import as Studio would?
>