blob: 4046f8cddca9f889f160928b30fbd49ea8aa6fc5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/bin/bash
#
# Backup LDAP directories
#
# This script can be put in cron to create backups.
#
# Author: Matthijs Mohlmann <matthijs@cacholong.nl>
# Date: Sat, 15 Jul 2006 21:13:14 +0200
# License: GPLv2
# Make sure the backups are secured.
umask 077
BACKUPDIR="/var/backups/slapd"
DEFAULTS="/etc/default/slapd"
# Check if there is a directory slapd, otherwise create it.
if [ ! -d "$BACKUPDIR" ]; then
mkdir -p -m 0700 "$BACKUPDIR"
fi
# Load default settings.
if [ -e "$DEFAULTS" ]; then
. "$DEFAULTS"
fi
# Specify a slapd.conf if not specified.
if [ -z "$SLAPD_CONF" ]; then
SLAPD_CONF="/etc/ldap/slapd.conf"
fi
# Set IFS to end of line.
ORIGIFS=$IFS
IFS=`echo -en "\n\b"`
# Backup recursive through all configfiles all suffix's in the form:
# suffix.ldif in /var/backups/slapd
function backupDirectories() {
local conf=$1
local directory=""
local include=""
suffix=`grep "^suffix" $conf | sed -e "s/\(^suffix\s\+\|\"\|\'\)//g"`
for directory in "$suffix"; do
if [ ! -z "$suffix" ]; then
slapcat -l "$BACKUPDIR/$suffix.ldif" -b "$suffix"
fi
done
includes=`grep "^include" $conf | awk '{print $2}'`
for include in $includes; do
backupDirectories "$include"
done
}
backupDirectories "$SLAPD_CONF"
# Put IFS back.
IFS=$ORIGIFS
exit 0
|