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

How to Backup and Restore OpenLDAP Database

Introduction

Backing up and restoring an LDAP database can be performed using database-specific tools. However, a more flexible approach is to export and import the LDAP directory tree in LDIF format. This method ensures database independence and simplifies the migration process.

1. Backup

The following command exports the LDAP directory tree and saves it in an LDIF file named backup.ldif:

#!/bin/sh

slapcat -v -l backup.ldif

This file contains all LDAP entries and can be used for later restoration.

2. Restore

The restoration process replaces the current LDAP database with the exported backup:

#!/bin/sh

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

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

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

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

# Restart the slapd daemon
/etc/init.d/slapd start

This procedure ensures that the LDAP directory is fully restored while maintaining database integrity.