Wednesday, June 1, 2011

How to Backup and Restore OpenLDAP Database

Instead of backup / restore of actual ldap database (hdb, etc) we will export/import ldap directory tree into ldif format that ultimately let us do the same, however without any particular database implementation specifics.


The backup will be stored in backup.ldif text file.

slapcat -v -l ldap.diff


The restore will go through replacing current database from a one we have in ldif backup.

# Stop slapd daemon
/etc/init.d/slapd stop

# Remove current database
rm -rf /var/lib/ldap/*

# Import directory tree from backup
slapadd -l backup.ldif

# Fix permissions
chown -R openldap:openldap /var/lib/ldap/*

# Start slapd daemon
/etc/init.d/slapd start


  1. great, very useful.

  2. If it helps anyone, i had to stop slapd first then only i was able to run slapcat.

    1. Just in case... I was able backup without a need to stop slapd. Anyway, thank you for sharing your experience.

  3. if specific non-standard schemas are used, use

    slapadd -l backup.ldif -f /etc/ldap/slapd.conf

    to make sure the schemas are loaded when importing into the database.

  4. Simply, excellent! Thank you.
    And I neither need to stop slapd to do a backup.

  5. Hey,

    I've tried the command mentioned , but I am getting error
    root@ldap1:~# slapcat -v -l ldap.diff
    53c77bc6 str2entry: invalid value for attributeType objectClass #1 (syntax
    slapcat: bad configuration file!

    Please help

  6. Never Mind worked , But We have to provide the config as well.

    slapcat -v -l ldap.diff -f /etc/ldap/slapd.conf

    Need to provide the configuration as well when running the slapcat.

    And yeah , stopping slapd didnt helped.