Wednesday, November 24, 2010

LDAP Skills

Skill 1
---------------------------------------------------------------------
What is "log.XXXXXXXXXX" in the BDB backend directory?
Logs of current transactions need to be stored into files so that the database can be recovered in the event of an application crash. Administrator can change the size limit of a single log file (by default 10MB), and have old log files removed automatically, by setting up DB environment (see below). The reason Berkeley DB never deletes any log files by default is that the administrator may wish to backup the log files before removal to make database recovery possible even after a catastrophic failure, such as file system corruption.

The slapd_db_archive tool knows what log files are used in current transactions, and what are not. Administrators can move unused log files to a backup media, and delete them. To have them removed automatically, place set_flags DB_LOG_AUTOREMOVE directive in DB_CONFIG. Note that if the log files are removed automatically, recovery after a catastrophic failure is likely to be impossible.

The files with names __db.001, __db.002, etc are just shared memory regions (or whatever). These ARE NOT `logs', they must be left alone. Don't be afraid of them, they do not grow like logs do.

The "alock" is an autorecovery mechanism introduced in the OpenLDAP 2.3 release to assist with autorecovery. Given more information on the error messages coming from alock would be useful, since it is supposed to help you recover from hard reboots gracefully.

For recovered the BDB database.

How can we clear all the redundant log file?
slapd_db_archive -a: Identify BDB logs which is not in use, and can be safely deleted
slapd_db_archive -l: List all the log files in BDB
slapd_db_archive -d: Remove all the unused logs files
-----------------------------------------------------------------

Skill 2
------------------
How to recover OpenLDAP database?
we can repair the OpenLDAP database by the following command:
/usr/sbin/slapd_db_recover -v -h /var/lib/ldap
after recovery, make sure to chown the files back to ldap:ldap or else it will still be busted.

------------------
How to backup OpenLDAP database in form of LDIF to remote Server:
---------------------------------------------
1. Backup-Script(ldap.sh):
***************************
#! /bin/sh
cd /root
rm -f /var/ldap_backup.ldif
/usr/sbin/slapcat > /var/ldap_backup.ldif
mount -t cifs -o username=ldap,password=ldap123 //192.168.2.200/ldapbackup /var/backup
cp -rf /var/ldap_backup.ldif /var/backup/
umount /var/backup
***************************
2. How to run a sh script on linux OS:
# sh script file
---------------------------------------------
3. Add a cron job:
# crontab -l
# crontab -e
30 3 * * * sh /var/ldap.sh
----------------------------------------



Reference Site
1. http://www.zytrax.com/books/ldap/ch6/bdb.html