[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: Deleting all Data



May be some simple scriptings could help.

Eg: delete all entries under People branch:

1) Find out who they are, export them to People.ldif, script is
db2ldif_People.sh

# db2ldif_People.sh
#
# Execute these for iPlanet Directory Server
if [ -n "`ps -ef | grep 'ns-slapd' | grep -v grep`" ]
then
   YYYY=`date +'%Y'`
   cd /usr/iplanet/ds5/slapd-`hostname`/ldif
   rm -f $YYYY*.ldif
   ../db2ldif -n UserRoot -s "ou=People,dc=example,dc=com"
   cp $YYYY*.ldif /home/ldap/People.ldif
fi

# Execute these for OpenLDAP Server
if [ -n "`ps -ef | grep 'slapd' | grep -v grep`" ]
then
   # For RedHat
   BINDIR=/usr/bin
   # For Others
   #BINDIR=/usr/local/bin
   $BINDIR/ldapsearch -x -LLL -b "ou=People,dc=example,dc=com" \
              -D "cn=Manager,dc=example,dc=com" \
              -w `cat /etc/ldap.secret` \
              "objectclass=*" >/home/ldap/People.ldif
fi
chmod 600 /home/ldap/People.ldif

2) Delete them via ldapdelete, script is openldap_delete_Peoples.sh

#! /bin/sh
# openldap_delete_Peoples.sh
# Destructive script
# Never do deletion at LDAP Master Server
# Do deletion only at LDAP Slave Server
[ "`uname -n`" = "ldap1" ] && exit

# Un-Comment for RedHat
BINDIR=/usr/bin
# Un-Comment for others
#BINDIR=/usr/local/bin

grep "^dn:" People.ldif | sed 's/^dn: //' >openldap_delete_Peoples.ldif
if [ -f mgr.pwd ]
then
   $BINDIR/ldapdelete -c -x -D "cn=Manager,dc=example,dc=com" -w `cat
mgr.pwd` -f openldap_delete_Peoples.ldif
else
   echo "mgr.pwd not found"
   echo "Please enter LDAP password for cn=Manager,dc=example,dc=com..."
   $BINDIR/ldapdelete -c -x -D "cn=Manager,dc=example,dc=com" -W -f
openldap_delete_Peoples.ldif
fi 

===
I have this need also as I don't use slurpd for LDAP data replication
and instead use scripts to delete all Peoples/groups and then re-add
them back. I do know this does not give the best performance, just for
small BDB.
Rgds
Gary

-----Original Message-----
From: owner-openldap-software@OpenLDAP.org
[mailto:owner-openldap-software@OpenLDAP.org] On Behalf Of Sadik Kumlali
Sent: Friday, October 15, 2004 4:10 PM
To: openldap-software@OpenLDAP.org
Subject: RE: Deleting all Data


/etc/init.d/ldap stop


# /var/lib/ldap/example.com: 'directory' definition in 'slapd.conf' 
# that gives the path of folder in which database files reside rm -rf
/var/lib/ldap/example.com

/etc/init.d/ldap start

That's all!

-----Original Message-----
From: owner-openldap-software@OpenLDAP.org
[mailto:owner-openldap-software@OpenLDAP.org] On Behalf Of Quanah
Gibson-Mount
Sent: Friday, October 15, 2004 10:32 AM
To: Edward de Jongh; openldap-software@OpenLDAP.org
Subject: Re: Deleting all Data



--On Friday, October 15, 2004 9:17 AM +0200 Edward de Jongh 
<Edwardd@discovery.co.za> wrote:

> Hi guys I am currently testing a system of mine and part of this
testing
> involves populating an LDAP implementation. What I need to know is,
can
> one delete all BDB entries at once via the slap commands.
>
> I know we can delete singular entries, but not sure about all entries
at
> once.

Why not just erase the database?  It would be faster.

--Quanah

--
Quanah Gibson-Mount
Principal Software Developer
ITSS/Shared Services
Stanford University
GnuPG Public Key: http://www.stanford.edu/~quanah/pgp.html