How to backup and restore your LDAP database
How to backup and restore your LDAP database
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:
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:
1 |
#!/bin/sh |
2 |
LDAPBK=ldap-$( date +%y%m%d-%H%M ).ldif |
3 |
BACKUPDIR=/home/backups |
4 |
<pre>/usr/sbin/slapcat - v -b "dc=yourDC,dc=local" -l $BACKUPDIR/$LDAPBK |
5 |
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:
2. delete old database (make sure you are in right directory to use rm):
2. Restore database from LDIF file:
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
Credit http://supportex.net/2011/02/backup-restore-ldap-database/