sobota, 14 czerwca 2014

OpenLDAP backup and restore

I'm going to change some schema and data in my ldap ;)

But 1st thing is how to restore ldap from ldiff file when something will go bad ...

1st is backup
2nd is store backup on other host/disk/whatever, it can be printed each time ;)
3rd is how to restore it when disaster come true ...

1st) backup like this? hm ... put it to cron ;)

[root@samba64 tmp]# slapcat  -o ldif-wrap=no > slapcat-o-ldif-wrap-n.ldiff


2nd) when file is created send it somewhere ;)

3rd) restore from ldiff file, please remember about correct schema files,
if there is something 'strange' (my setup has some tweaks for Postfix) then also backup schema files :P just in case :P ;-) 

how to restore it?

- shut down ldap server,
- remove broken files, in my case just clean directory /var/lib/openldap-data or rename it,
-  change directory to /var/lib/openldap-data,
- do command: slapadd -v -l ~/LDAP/slapcat-o-ldif-wrap-n.ldiff,
- chown slapd:slapd files in /var/lib/openldap-data (beware, it is my PLD Linux ;) ),
- start ldap,
- check it. something like this:

ldapsearch  -b "ou=Users,dc=XXXX,dc=pl" -D "cn=Manager,dc=XXXX,dc=pl" \
        -w MyPassword -x -v \
        -h 127.0.0.1\
        '(&(objectClass=PostfixUser)(accountStatus=active))' mail

Uff done ...

Restore procedure looks like "IT WORKS!"

:-)

Next step is add and change some data in my secret schema ;) then do some tricks with ldiff file ...