2 # openldap backup handler script for backupninja
5 getconf backupdir /var/backups/ldap
6 getconf conf /etc/ldap/slapd.conf
12 # hot copy is not yet supported
16 [ -f $conf ] || fatal "slapd config file ($conf) not found"
17 [ -d $backupdir ] || mkdir -p $backupdir
18 [ -d $backupdir ] || fatal "Backup directory '$backupdir'"
20 dbsuffixes=(`awk 'BEGIN {OFS=":"} /[:space:]*^database[:space:]*\w*/ {db=$2}; /^[:space:]*suffix[:space:]*\w*/ {if (db=="bdb"||db=="ldbm") print db,$2}' $conf|sed -e 's/[" ]//g'`)
24 if [ "$ldif" == "yes" ]; then
26 [ -d $dumpdir ] || mkdir -p $dumpdir
28 if [ "$databases" == 'all' ]; then
29 dbcount=`grep '^database' $conf | wc -l`
30 let "dbcount = dbcount - 1"
31 databases=`seq 0 $dbcount`;
34 for db in $databases; do
35 if [ `expr index "$dbnum" "="` == "0" ]; then
36 # db is a number, get the suffix.
37 dbsuffix=${dbsuffixes[$db]/*:/}
41 # some databases don't have suffix (like monitor), skip these
42 if [ "$dbsuffix" == "" ]; then
45 touch $dumpdir/$dbsuffix.ldif
46 if [ ! -f $dumpdir/$dbsuffix.ldif ]; then
47 fatal "Couldn't create ldif dump file: $dumpdir/$dbsuffix.ldif"
49 execstr="$SLAPCAT -f $conf -b $dbsuffix -l $dumpdir/$dbsuffix.ldif"
54 if [ "$code" == "0" ]; then
56 debug 1 "Successfully finished ldif export of $dbsuffix"
59 debug 2 "Failed ldif export of $dbsuffix"
61 if [ "$compress" == "yes" ]; then
62 output=`$GZIP -f "$dumpdir/$dbsuffix.ldif" 2>&1`