Moorfleeter Deich 216, 22113 Hamburg
+49 1774661716info@bastcom.deMon–Fri: 09:00–18:00

Blog

ITWeb Knowledge

Tech news, AI and practical knowledge – around WordPress, Joomla, hosting and web development.

How to Backup and Restore OpenLDAP Database

← Back to the blog

Introduction

Backing up and restoring to 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.

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. Restores

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.