Moorfleeter Deich 216, 22113 Hamburg +49 1774661716 info@bastcom.de Mo. - Fr.: 09:00 - 18:00

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. 

 

Backup

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

#!/bin/sh

slapcat -v -l backup.ldif

Restore

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

#!/bin/sh

# 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