20121120 backup script using ldif export - plembo/onemoretech GitHub Wiki

title: backup script using ldif-export link: https://onemoretech.wordpress.com/2012/11/20/backup-script-using-ldif-export/ author: lembobro description: post_id: 5918 created: 2012/11/20 17:48:24 created_gmt: 2012/11/20 21:48:24 comment_status: closed post_name: backup-script-using-ldif-export status: publish post_type: post

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 {} \;

Copyright 2004-2019 Phil Lembo