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 ldap.diff
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
great, very useful.
ReplyDeleteIf it helps anyone, i had to stop slapd first then only i was able to run slapcat.
ReplyDeleteJust in case... I was able backup without a need to stop slapd. Anyway, thank you for sharing your experience.
Deleteif specific non-standard schemas are used, use
ReplyDeleteslapadd -l backup.ldif -f /etc/ldap/slapd.conf
to make sure the schemas are loaded when importing into the database.
Simply, excellent! Thank you.
ReplyDeleteAnd I neither need to stop slapd to do a backup.
Hey,
ReplyDeleteI'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 1.3.6.1.4.1.1466.115.121.1.38)
slapcat: bad configuration file!
Please help
Never Mind worked , But We have to provide the config as well.
ReplyDeleteslapcat -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.
Nice !!
ReplyDeleteperfect!!!!!
ReplyDelete