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

opendsldifexport

OpenDS LDIF Export

This script will create a ldif export from a running OpenDS installation.

#!/bin/bash
# set -x
# Created by s.hooft, 22-03-2011, sjoerd_warmetal.nl

### Script Variables
WHATAMI=`basename $0`

### LDAP Variables
DUMPDIR=/var/backup/ldif
MANAGER=cn=manager
PASSWD=xxxxxxxx
HOSTNAME=`hostname`
HOSTNAME_SHORT=`hostname -s`
LDAPBASE="o=company.local"

### Offsitecopy Variables
GZIP=/usr/bin/gzip
. "/opt/scripts/mail.txt"
. "/opt/scripts/offsitecopy.func"
TOUSER="repluser"
TOHOST="syncsrv.company.local"
TODIR="/srv/syncdata/LDAP"
LDIFFILE=${DUMPDIR}/${HOSTNAME_SHORT}-LDAP_`date +%Y%m%d%H%M`.ldif
BACKUPFILE="$LDIFFILE.gz"
LOGFILE=${DUMPDIR}/ldapbackup.log
DOCOPY="1"

### Create new logfile
echo "Creating ldif backup $LDIFFILE using $MANAGER on $LDAPBASE" > $LOGFILE

mailFunction() {
   if [ "$1" == "LDIF" ]; then
      echo "LDIF backup was not created succesfully, consult $LOGFILE on ${HOSTNAME}" | mail -s "Failed $1 Backup" $MAILTOFAIL
   fi
   if [ "$1" == "GZIP" ]; then
      echo "Tar or zip was not created succesfully, consult $LOGFILE on ${HOSTNAME}" | mail -s "Failed $1 Backup" $MAILTOFAIL
   fi
   exit
}

backupFunction () {
   /opt/OpenDS-2.2.0/bin/export-ldif --bindDN "$MANAGER" --bindPassword "$PASSWD" --backendID userRoot --trustAll --excludeAttribute entryUUID --ldifFile $LDIFFILE >> $LOGFILE
   LDIFRESULT=$?
   if [ ! "$LDIFRESULT" == "0" ]; then
      mailFunction LDIF
   fi
   $GZIP $LDIFFILE >> $LOGFILE
   GZIPRESULT=$?
   if [ ! "$GZIPRESULT" == "0" ]; then
      mailFunction GZIP
   fi
   copyFunction
}

copyFunction() {
   if [ "$DOCOPY" == "1" ]; then
      offsitecopy "${BACKUPFILE}" "$TOUSER" "$TOHOST" "$TODIR" "$LOGFILE" "$WHATAMI" "$HOSTNAME" "$MAILTOSUCCESS" "$MAILTOFAIL"
   else
      echo >> $LOGFILE
      echo "Copy to offsite location is not enabled." >> $LOGFILE
      echo "Modify the script under Offsitecopy Variables to enable offsitecopy" >> $LOGFILE
      echo >> $LOGFILE
   fi
}

backupFunction

exit

The offsitecopy.func and mail.txt can be found here.

You could leave a comment if you were logged in.
opendsldifexport.txt · Last modified: 2021/09/24 00:25 (external edit)