#!/bin/sh # # Program: Backup openldap server to ldif file # # Author: Matty < matty91 at gmail dot com > # # Current Version: 1.0 # # Revision History: # # Version 1.0 # Initial Release # # Last Updated: 01-06-2007 # # Purpose: # This program can be used to dump the contents of an openldap # server to an ldif file. To restore the ldif file, the slapadd # utility can be used: # $ slapadd -v -f slapd.conf -b "dc=prefetch,dc=net" -l ldif # # License: # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Installation: # Copy the shell script to a suitable location PATH=/bin:/usr/bin:/usr/local/bin:/usr/sfw/bin export PATH # Global variables DATE=`date "+%Y%m%d"` BACKUPDIR="/etc/openldap/backups" BACKUPFILE="${BACKUP_DIRECTORY}/ldif.${DATE}" CONFIG="/etc/openldap/slapd.conf" # Parse the options that are passed to the script while getopts c:d: option do case "${option}" in c) CONFIG=${OPTARG} ;; d) BACKUPDIR=${OPTARG} ;; \?) usage exit 1;; esac done if [ ! -d ${BACKUPDIR} ] then echo "The directory ${BACKUPDIR} does not exist" exit 1 fi if [ -f ${CONFIG} ] then slapcat -f ${CONFIG} > ${BACKUPFILE} chmod 600 ${BACKUPFILE} else echo "Configuration file ${CONFIG} does not exist" exit 1 fi