2 # openldap backup handler script for backupninja
5 getconf backupdir /var/backups/ldap
6 getconf conf /etc/ldap/slapd.conf
11 getconf method ldapsearch
17 [ -f $conf ] || fatal "slapd config file ($conf) not found"
18 [ -d $backupdir ] || mkdir -p $backupdir
19 [ -d $backupdir ] || fatal "Backup directory '$backupdir'"
21 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'`)
25 if [ "$ldif" == "yes" ]; then
27 [ -d $dumpdir ] || mkdir -p $dumpdir
29 if [ "$databases" == 'all' ]; then
30 dbcount=`grep '^database' $conf | wc -l`
31 let "dbcount = dbcount - 1"
32 databases=`seq 0 $dbcount`;
35 for db in $databases; do
36 if [ `expr index "$dbnum" "="` == "0" ]; then
37 # db is a number, get the suffix.
38 dbsuffix=${dbsuffixes[$db]/*:/}
42 # some databases don't have suffix (like monitor), skip these
43 if [ "$dbsuffix" == "" ]; then
47 if [ "$method" == "slapcat" ]; then
48 execstr="$SLAPCAT -f $conf -b $dbsuffix"
49 if [ "$restart" == "yes" ]; then
50 debug "Shutting down ldap server..."
51 /etc/init.d/slapd stop
55 execstr="$LDAPSEARCH -x -L -b ""$dbsuffix"" -D ""$binddn"" -y $passwordfile"
56 [ -f "$passwordfile" ] || fatal "Password file $passwordfile not found"
57 if [ "$restart" == "yes" ]; then
58 debug "Shutting down ldap server..."
59 /etc/init.d/slapd stop
65 touch $dumpdir/$dbsuffix.ldif
66 if [ ! -f $dumpdir/$dbsuffix.ldif ]; then
67 fatal "Couldn't create ldif dump file: $dumpdir/$dbsuffix.ldif"
70 output=`$execstr > $dumpdir/$dbsuffix.ldif`
72 if [ "$code" == "0" ]; then
74 info "Successfully finished ldif export of $dbsuffix"
75 if [ "$restart" == "yes" ]; then
76 debug "Starting ldap server..."
77 /etc/init.d/slapd start
81 warning "Failed ldif export of $dbsuffix"
83 if [ "$compress" == "yes" ]; then
84 output=`$GZIP -f "$dumpdir/$dbsuffix.ldif" 2>&1`