backup script using ldif-export

Simple shell script using OpenDJ ldif-export utility. Revised.

Includes crude old files management (delete everything over 30 days old). In real life you’ll probably want to archive and then delete later. Notice that this script assumes some of my own “best practices”, like having an environment setting script handy that sets the $DSHOME variable to the directory instance root, and the use of an “opendj” system user. See Installing OpenDJ for more. Revised version includes key config files.

#!/bin/bash
# Script to backup OpenDJ directory, "opendjbak.sh".
HOME=/home/opendj
DSHOME=/opt/opendj/ds-user1
TIMESTAMP=`date +%Y%m%d%H%M%S`
BAKDIR=/data/backup/ldap
FILENAME=ds-user1.${TIMESTAMP}.ldif
MAINCFG=${DSHOME}/config/config.ldif
JAVACFG=${DSHOME}/config/java.properties

. ${HOME}/ds-user1.env

echo "Backup LDAP directory at ${TIMESTAMP}"

${DSHOME}/bin/export-ldif \
-b 'dc=example,dc=com' \
-n userRoot \
-l ${BAKDIR}/${FILENAME} \
-t 0 \
-p 5444 \
-j ${HOME}/etc/pwd.txt \
-X

cp ${MAINCFG} ${BAKDIR}/
cp ${JAVACFG} ${BAKDIR}/

cd ${BAKDIR}
find . -type f -name "*.ldif" -mtime +30 -exec rm -f {} \;