summaryrefslogtreecommitdiffstats
path: root/roles/common-LDAP/files/usr/local/sbin/slapcat-all.sh
blob: cd5abd9b0c66eb5691bdf053df23b941d4467e47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh

# Usage: slapcat-all.sh DIR
# Save all LDAP databases in DIR: DIR/0.ldif, DIR/1.ldif, ...

set -ue
PATH=/usr/sbin:/sbin:/usr/bin:/bin

target="$1"
umask 0077

prefix=slapcat-
slapcat -n0 -l"$target/${prefix}0.ldif"
n=$(grep -Ec '^dn:\s+olcDatabase={[1-9][0-9]*}' "$target/${prefix}0.ldif")

while [ $n -gt 0 ]; do
    # the Monitor backend can't be slapcat(8)'ed
    grep -qE "^dn:\s+olcDatabase=\{$n\}monitor,cn=config$" "$target/${prefix}0.ldif" || slapcat -n$n -l"$target/${prefix}$n.ldif"
    n=$(( $n - 1 ))
done