LDAP Backup / Restore with slapadd and slapcat

Backup:

#!/bin/sh

DIR=`date +'%Y%m%d-%H%M'`
mkdir -p $DIR
slapcat -n 0 > $DIR/config.ldif
slapcat -n 1 > $DIR/directory1.ldif

Restore:


#!/bin/sh

DIR=$1

if [ ! -d $DIR ]; then
    echo "$DIR is not a directory"
    exit 1
fi

sudo service slapd stop

sudo rm -rf /var/lib/ldap
sudo mkdir -p /var/lib/ldap

sudo rm -rf /etc/ldap/slap.d
sudo mkdir -p /etc/ldap/slap.d

sudo slapadd -F /etc/ldap/slapd.d -n 0 -l $DIR/config.ldif
sudo slapadd -F /etc/ldap/slapd.d -n 1 -l $DIR/directory1.ldif

sudo chown -R openldap:openldap /var/lib/ldap/
sudo chown -R openldap:openldap /etc/ldap/slap.d

sudo service slapd start
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s