initial version
author"Heiko Schlittermann" <hs@schlittermann.de>
Tue, 26 Nov 2013 19:50:16 +0000
changeset 0 63efa79af060
child 1 cf6a5ba00d83
initial version
ldap-backup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ldap-backup	Tue Nov 26 19:50:16 2013 +0000
@@ -0,0 +1,43 @@
+#! /bin/bash
+# to be used in /etc/cron.daily/
+# source: hg clone https://ssl.schlittermann.de/hg/ldap-backup
+# (c) 2013 Heiko Schlittermann <hs@schlittermann.de>
+
+set -e
+export LC_ALL=C
+
+
+if test -t 0; then
+	# terminal/interactive
+	destination=${1:?Need destination directory}
+else
+	# cron
+	destination=${1:-/var/backups/ldap}
+	exec &>/tmp/$(basename $0).log
+fi
+
+test -d "$destination" || {
+	echo "$0: \`$destination' is not a directory" >&2
+	exit
+}
+
+tag=$(date -I)
+tmpdir=$(mktemp -d --suffix=.$(basename $0))
+test "/tmp" = $(dirname $tmpdir) \
+	&& trap "rm -rf $tmpdir" EXIT
+
+cd $tmpdir
+dir="ldap.$tag"
+mkdir "$dir"
+
+# save the config db
+slapcat -n 0 >"$dir"/cn=config.ldif
+
+grep olcSuffix: "$dir"/cn=config.ldif | cut -f2 -d' ' \
+	| while read suffix; do
+		slapcat -b "$suffix" > "$dir/$suffix.ldif"
+		tar czf "$destination"/"$dir".tar.gz.$$ "$dir"
+		mv "$destination"/"$dir".tar.gz.$$ \
+		   "$destination"/"$dir".tar.gz
+
+done