SHIFT

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

User Tools

Site Tools


tdsldapbackup
Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tdsldapbackup [2013/04/30 15:15] (current)
sjoerd created
Line 1: Line 1:
 += Script: Bash: TDS LDAP Backup
 +Below you'll find a script I've used to backup TDS LDAP data which can be restored using this [[opendsrestore|script]] into [[opendsinstall|openDS]] or into [[tdsinstall|Tivoli Directory Server]] with this [[tdsldaprestore|script]].
  
 +<code bash>
 +#!/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
 +</​code>​
 +
 +As you can see, there is an external reference to offsitecopy and mail.txt. Both are described in [[offsitecopy]]. ​
 +
 +{{tag>​scripts ldap backup}}
tdsldapbackup.txt ยท Last modified: 2013/04/30 15:15 by sjoerd