User Tools

Site Tools


application_specific_backups:openldap

Differences

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

Link to this comparison view

application_specific_backups:openldap [2008/09/15 22:39]
olaf created
application_specific_backups:openldap [2011/07/05 13:11] (current)
emteedee support for OpenLDAP 2.3 style configuration directory
Line 12: Line 12:
  
 SLAPD_CONF=/​etc/​ldap/​slapd.conf SLAPD_CONF=/​etc/​ldap/​slapd.conf
 +SLAPD_CONF_DIR=/​etc/​ldap/​slapd.d
  
 # where to put files # where to put files
-BACKUP_PATH="/​usr/​local/​backup/​ldap_dumps"​+DEFAULT_BACKUP_PATH="/​usr/​local/​backup/​ldap_dumps"​ 
 + 
 +BACKUP_PATH=${1:​-$DEFAULT_BACKUP_PATH}
  
 # set more secure umask # set more secure umask
 umask 0027 umask 0027
  
-if [ ! -"${SLAPD_CONF}" ]; then +if [ ! -"${BACKUP_PATH}/" ]; then 
-    echo "​Error:​ \"${SLAPD_CONF}\" ​cannot be read." >&2+    echo "​Error:​ \"${BACKUP_PATH}\" ​not found or not a directory." >&2
     exit 1     exit 1
 fi  fi 
Line 33: Line 36:
  
 echo "​searching for suffixes to dump" echo "​searching for suffixes to dump"
-# open slapd conf file and read line by line +if [ -r "​${SLAPD_CONF}"​ ]; then 
-dbNum=0 +    ​# open slapd conf file and read line by line 
-exec 3<​${SLAPD_CONF} +    dbNum=0 
-while read line <&3; do +    exec 3<​${SLAPD_CONF} 
-    # search for database declaration +    while read line <&3; do 
-    if echo $line | grep -e '​^database'​ > /dev/null; then +        # search for database declaration 
-        (( dbNum++ )) +        if echo $line | grep -e '​^database'​ > /dev/null; then 
-        database=`echo $line | awk '​{print $2}'​` +            (( dbNum++ )) 
-        # lets see if it's a bdb/hdb database (I don't care about anything else...) +            database=`echo $line | awk '​{print $2}'​` 
-        if [ "​$database"​ == "​bdb"​ ] || [ "​$database"​ == "​hdb"​];​ then+            # lets see if it's a bdb/hdb database (I don't care about anything else...) 
 +            if [ "​$database"​ == "​bdb"​ ] || [ "​$database"​ == "​hdb"​ ]; then
  
-            ​# searching for suffix now +                ​# searching for suffix now 
-            while [ -z $suffix ]; do +                while [ -z $suffix ]; do 
-                if read line <&3; then +                    if read line <&3; then 
-                    if echo $line | grep -e '​^suffix'​ > /dev/null; then +                        if echo $line | grep -e '​^suffix'​ > /dev/null; then 
-                        # found suffix, now we can dump it somewhere +                            # found suffix, now we can dump this suffix ​somewhere 
-                        suffix=`echo $line | awk '​{print $2}'​` +                            suffix=`echo $line | awk '​{print $2}'​` 
-                        dumpSuffix $suffix $dbNum+                            dumpSuffix $suffix $dbNum 
 +                        fi
                     fi                     fi
-                ​fi +                done 
-            ​done +                suffix=""​ 
-            suffix=""​+            fi
         fi         fi
-    ​fi +    done 
-done +    exec 3>&​- ​      # close file descriptor 
-exec 3>&​- ​      # close file descriptor+elif [ -d ${SLAPD_CONF_DIR} ]; then 
 +    dbNum=0 
 +    for conf in ${SLAPD_CONF_DIR}/​cn\=config/​olcDatabase*;​ do 
 +        # only BDB/HDB databases 
 +        if grep -e '​^objectClass:​ \(olcBdbConfig\|olcHdbConfig\)$'​ $conf > /dev/null; then 
 +            (( dbNum++ )) 
 +            suffix=`grep -e '​olcSuffix:​ ' $conf | awk '​{print $2}'​` 
 +            dumpSuffix $suffix $dbNum 
 +        fi 
 +    done 
 +else 
 +    echo "ERROR - configuration not found."​ >&​2 
 +    exit 1 
 +fi
  
 exit 0  exit 0 
 </​file>​ </​file>​
  
application_specific_backups/openldap.1221514758.txt.gz · Last modified: 2008/09/15 22:39 by olaf