SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Recently Changed Pages:

View All Pages


View All Tags


LinkedIn




WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Pages with comments

View All Comments

tdsldaprestore

Script: Bash: TDS LDAP Restore

Below you'll find a script I've used to restore LDAP data which was backup with this script: Script: Bash: TDS LDAP Backup.

#!/bin/bash
#set -x
 
### Export HOME and APP Settings
export LDAP_INSTANCE=idsfop
export LDAP_HOME=/opt/IBM/ldap/V6.0
export LDAPSEARCH="${LDAP_HOME}/bin/ldapsearch"
export APPDIR=$LDAP_HOME
 
### Read LDAP Restore Instance Settings
LDAPUSER1="cn=Directory Manager"
LDAPBASE1="o=organization.nl"
 
echo
echo "Please provide Directory Admin DN [$LDAPUSER1]:"
read LDAPUSER
echo
echo "Directory Admin password:"
read LDAPPASS
echo
echo "Please provide application base DN [$LDAPBASE1]:"
read LDAPBASE
echo
echo "Please provide password of db2 user account (UNIX):"
read DB2PASS
 
### If LDAPUSER is empty then use default setting
if [ -z "$LDAPUSER" ]; then
   LDAPUSER="$LDAPUSER1"
   echo "LDAP user being used = $LDAPUSER1"
fi
 
### If LDAPBASE is empty then use default setting
if [ -z "$LDAPBASE" ]; then
   LDAPBASE="$LDAPBASE1"
   echo "LDAP base being used = $LDAPBASE1"
fi
 
### Get live DB2 Settings
getConfigValueFromLdap() {
   $LDAPSEARCH -D "$LDAPUSER" -w $LDAPPASS -h localhost -s base -b "cn=Directory,cn=RDBM Backends,cn=IBM Directory,cn=Schemas,cn=Configuration" '(objectclass=*)' $1 | grep $1 | awk -F= '{ print $2 }'
}
 
echo
DB2USER=`getConfigValueFromLdap ibm-slapdDbUserID`
echo "DB2 User being used = $DB2USER"
DB2INSTANCE=`getConfigValueFromLdap ibm-slapdDbInstance`
echo "DB2 Instance being used = $DB2INSTANCE"
LDAPDB=`getConfigValueFromLdap ibm-slapdDbName`
echo "LDAP DB being used = $LDAPDB"
DBLOCATION=`getConfigValueFromLdap ibm-slapdDbLocation`
echo "DB Location = $DBLOCATION"
 
### Check for empty variables
if [ -z "$DB2USER" -o -z "$DB2INSTANCE" -o -z "$LDAPDB" -o -z "$DBLOCATION" ]; then
   echo
   echo "`tput bold``tput smul`ERROR - Could not retreive configuration setting from LDAP, ABORTING!`tput sgr0`"
   echo
   echo "Possible causes: "
   echo " - incorrect credentials (Directory Admin)"
   echo " - incorrect application DN provided"
   echo " - Directory server not running or reachable"
   echo
   exit 1
fi
 
restoreLdap() {
   echo "INFO - Stopping LDAP"
   echo ${APPDIR}/sbin/idsslapd -I $LDAP_INSTANCE -k
 
   echo "INFO -Removing suffix $LDAPBASE"
   echo ${APPDIR}/sbin/idsucfgsuf -I $LDAP_INSTANCE -n -s $LDAPBASE
 
   echo "INFO - Dropping instance  $LDAP_INSTANCE"
   echo ${APPDIR}/sbin/idsucfgdb -I $LDAP_INSTANCE -n -r
 
   echo "INFO - Creating instance  $LDAP_INSTANCE"
   echo ${APPDIR}/sbin/idscfgdb -I $LDAP_INSTANCE -n -a $DB2USER -l $DBLOCATION -t $LDAPDB -w $DB2PASS
 
   echo "INFO -Adding suffix $LDAPBASE"
   echo ${APPDIR}/sbin/idscfgsuf -I $LDAP_INSTANCE -n -s $LDAPBASE
 
   echo "INFO - Importing LDAP data..."
   echo ${APPDIR}/sbin/bulkload -I $LDAP_INSTANCE -i $LDIFFILE -a parse_and_load
 
   echo "INFO - Starting LDAP"
   echo ${APPDIR}/sbin/idsslapd -I $LDAP_INSTANCE
}
 
usageCommand() {
   echo
   echo "Usage $0 COMMAND:"
   echo "--------------------------------------"
   echo "`tput bold``tput smul`$0 restore "restorefile"`tput sgr0`"
   echo "--------------------------------------"
   echo
}
 
case "$1" in
 
restore )
   if [ ! -z "$2" ]; then
      if [ -f "$2" ]; then
         LDIFFILE=$2
         echo "LDAP file being used = $LDIFFILE"
         restoreLdap
      else
         echo
         echo "The restorefile provided does not exist"
         echo "Please provide the full path to the restore file"
         echo
         usageCommand
         exit 1
      fi
   else
      echo 
      echo "Please provide the full path to the restore file"
      echo
      usageCommand
      exit 1
   fi
;;
 
* )
   usageCommand
   exit 1
;;
 
esac
 
echo
echo "INFO - LDAP restore finished"
echo
You could leave a comment if you were logged in.
tdsldaprestore.txt · Last modified: 2021/09/24 00:25 (external edit)