From bf820512490da586509c787b9c4c73e0fb2688ac Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 24 Feb 2021 20:12:03 +0100 Subject: [PATCH] Add restore_lsexample script --- lsexample/restore_lsexample | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 lsexample/restore_lsexample diff --git a/lsexample/restore_lsexample b/lsexample/restore_lsexample new file mode 100755 index 00000000..a4806a41 --- /dev/null +++ b/lsexample/restore_lsexample @@ -0,0 +1,42 @@ +#!/bin/bash + +# +# Script to restore LSexample from source +# +# Installation: +# ln -s /path/to/ldapsaisie/src/lsexample/restore_lsexample /usr/local/sbin/ +# + +# Configuration +SRC_DIR="$( realpath "$( dirname $0 )/../" )" +SLAPD_CONF_DIR=/etc/ldap/slapd.d +SLAPD_DB_DIR=/var/lib/ldap +SLAPD_USER=openldap +SLAPD_GROUP=openldap + +# Deducted configuration +LDIF="$SRC_DIR/lsexample/lsexample.ldif" +SCHEMA_LDIF="$SRC_DIR/lsexample/schema/cn={10}ls.ldif" +SCHEMA_DEST="$SLAPD_CONF_DIR/cn=config/cn=schema/" + +# +# Start restoration +# + +# Stop slapd +/usr/sbin/service slapd stop > /dev/null + +# Purge old DB data +rm -fr $SLAPD_DB_DIR/* + +# Restore schema file +cp -f "$SCHEMA_LDIF" "$SCHEMA_DEST" + +# Restore DB data from LDIF file +/usr/sbin/slapadd -l $LDIF -q + +# Fix rights on restored data +chown $SLAPD_USER:$SLAPD_GROUP -R $SLAPD_DB_DIR $SCHEMA_DEST + +# Start slapd +/usr/sbin/service slapd start > /dev/null