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 bdbhdb 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:
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/

Server under DDOS attack – How to find out IPs?

My server is under DDOS attacks and I want to block the IP that is doing it, what logs should I be looking for to determine the attacker’s IP?

tail -n 10000 yourweblog.log|cut -f 1 -d ‘ ‘|sort|uniq -c|sort -nr|more


netstat -n|grep :80|cut -c 45-|cut -f 1 -d ‘:’|sort|uniq -c|sort -nr|more

cut -f 2 -d ‘”‘ yourweblog.log|cut -f 2 -d ‘ ‘|sort|uniq -c|sort -nr|more

cut -f 4 -d ‘”‘ yourweblog.log|sort|uniq -c|sort -nr|more


Check your Process and Connection Counts

ps auxw | grep httpd | wc -l

netstat -nap | grep “:80 ” | wc -l

netstat -ntu | grep “:80” | awk ‘{print $5}’| cut -d: -f1 | sort | uniq -c | sort -n |
grep -v 127.0.0.1 | awk ‘{if ($1 > 45) print $2;}’

Analyze the Requests

cat access_log | awk -F “”” ‘{printf “%sn”, $2}’ | sed -e ‘s/GET //’ | awk -F ” ” ‘{printf “%sn” ,$1}’ | sort | uniq -c | sort -n | awk ‘{if ($1 > 45) print $2;}’ | more

iptables -A INPUT -s 1.2.3.4 -j DROP

Credit : http://serverfault.com/questions/152139/server-under-ddos-attack-how-to-find-out-ips