wiki.getshifting.com

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

User Tools

Site Tools


tdsldapbackup

Script: Bash: TDS LDAP Backup

Summary: How to backup Tivoli Directory Server with a bash script.
Date: Around 2010
Refactor: 29 April 2025: Checked links and formatting.

Below you'll find a script I've used to backup TDS LDAP data which can be restored using this script into openDS or into Tivoli Directory Server with this script.

#!/bin/bash
# set -x
 
### Script Variables
WHATAMI=`basename $0`
 
### LDAP Variables
DUMPDIR=/var/backup/ldif
APPDIR=/opt/IBM/ldap/V6.0
LDAPSEARCH=/opt/IBM/ldap/V6.0/bin/ldapsearch
MANAGER=cn=manager
PASSWD=<password>
HOSTNAME=`hostname`
LDAPBASE="o=company.local"
LDAPPORT=389
 
### OLD LDAP Variables
#INSTANCE=idsldap
 
### Offsitecopy Variables
GZIP=/usr/bin/gzip
. "/opt/ITS_Tools/Scripts/mail.txt"
. "/opt/ITS_Tools/Scripts/offsitecopy.func"
TOUSER="repluser"
TOHOST="replicationserver.company.local"
TODIR="/srv/syncdata/LDAP"
LDIFFILE=${DUMPDIR}/${HOSTNAME}_${LDAPBASE}_`date +%Y%m%d%H%M`.ldif
BACKUPFILE="$LDIFFILE.gz"
LOGFILE=${DUMPDIR}/logfile_`date +%Y%m%d%H%M`.txt
DOCOPY="0"
 
usageCommand() {
   echo
   echo "Usage $0 COMMAND:"
   echo "--------------------------------------"
   echo "`tput bold``tput smul`$0 ldifbackup`tput sgr0`"
   echo "--------------------------------------"
   echo
}
 
ldifBackup() {
   echo "Creating ldif backup $LDIFFILE .. using $MANAGER"
   $LDAPSEARCH -L -D "$MANAGER" -w "$PASSWD" -h "$HOSTNAME" -p "$LDAPPORT" -b "$LDAPBASE" '(objectclass=*)' > $LDIFFILE
   $GZIP $LDIFFILE
   if [ -f $BACKUPFILE ]; then
      echo "Finished dump, output in $BACKUPFILE"
      if [ "$DOCOPY" == "1" ]; then
         offsitecopy "${BACKUPFILE}" "$TOUSER" "$TOHOST" "$TODIR" "$LOGFILE" "$WHATAMI" "$HOSTNAME" "$MAILTOSUCCESS" "$MAILTOFAIL"
      else
         echo
         echo "Copy to offsite location is not enabled."
         echo "Modify the script under Offsitecopy Variables to enable offsitecopy"
         echo
      fi
   else
      echo
      echo "$BACKUPFILE was not created."
      echo Exiting...
      echo
      exit 1
   fi
}
 
case "$1" in
 
ldifbackup )
   echo "Checking if the LDAP server is running... "
   pid=`ps -ef|grep ibmslapd|grep -v grep|awk '{ print $2 }'`
   if [ -z "$pid" ]; then
      echo
      echo "Ldap server is stopped..."
      echo "Exiting... "
      exit 1
   else
      echo "Ldap server is running..."
      ldifBackup
   fi
;;
 
* )
   usageCommand
   exit 1
;;
 
esac
 
echo
echo "INFO - LDIF backup finished"
echo

As you can see, there is an external reference to offsitecopy and mail.txt. Both are described in Bash: Function: Offsitecopy.

tdsldapbackup.txt · Last modified: by 127.0.0.1