Blog

How to backup and restore your LDAP database

On 07.02.2011, in supportex.net-blog, by Oleksii Tykhonov
4

LDAP is Lightweight Directory Access Protocol. It is a way to communicate with directory services. And for many years it has proved its reliability to organize and keep various type of information, for instance, user accounts. It’s useful if you want to provide one credentials for accessing to different resources – servers, web pages, etc.
OpenLDAP is open source implementation of the LDAP.
Once LDAP server is set and running you need to take care about backups.
If your LDAP backend is one of bdb, hdb or null you can use slapcat.  To check it see /etc/ldap/slapd.conf.
Here is an example:

debian:~# /usr/sbin/slapcat -v -l /home/backup/ldap.diff

Full backup script:

#!/bin/sh
LDAPBK=ldap-$( date +%y%m%d-%H%M ).ldif
BACKUPDIR=/home/backups
<pre>/usr/sbin/slapcat -v -b "dc=yourDC,dc=local" -l $BACKUPDIR/$LDAPBK
gzip -9 $BACKUPDIR/$LDAPBK

 

You should just change LDAP suffix from “dc=yourDC,dc=local” to your actual one.

To restore you should perform the following steps.

1.  stop slapd daemon:
debian:~# /etc/init.d/slapd stop
2. delete old database (make sure you are in right directory to use rm):
debian:~# cd /var/lib/ldap
rm -rf *

2. Restore database from LDIF file:
debian:~# /usr/sbin/slapadd -l backup.ldif

4. run slapd daemon:

debian:~# /etc/init.d/slapd start

Didn't find the answer to your question? Ask it our administrators to reply we will publish on website.

Tagged with:
 

4 Responses to How to backup and restore your LDAP database

  1. Fieropunk says:

    What about long lines wrapping? How do I stop it from wrapping?

  2. Rickm says:

    I’m looking for the wrapping issue solution too.

  3. Rickm says:

    and I just found the solution: -o ldif-wrap=

    slapcat -o ldif-wrap=80 -l dump.ldif

  4. [...] You can use the slapcat command to take backup of the ldap server. reference [...]

Leave a Reply