add "restore" command
This commit is contained in:
parent
294507627b
commit
85dcac0ca9
|
@ -0,0 +1,49 @@
|
|||
#!/bin/sh
|
||||
# Restore all ldap database from $1
|
||||
# Prerequisite: all ldap database are in /var/lib/ldap
|
||||
|
||||
MAXDB=30
|
||||
SERVICE="/usr/sbin/service slapd"
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "ERR: syntax: restore <directory>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BACKUPDIR=$1
|
||||
shift
|
||||
if [ ! -d "$BACKUPDIR" -o ! -f "$BACKUPDIR/config.ldif" ]; then
|
||||
echo "First argument must be a directory containing at least a config.ldif file"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo -n "WARNING! All current data will be erased. Are you sure? (type yes) "
|
||||
read ok
|
||||
if [ "x$ok" != "xyes" ]; then
|
||||
exit 3
|
||||
fi
|
||||
|
||||
${SERVICE} stop
|
||||
|
||||
echo -n "erasing current datas .."
|
||||
rm -rf /etc/ldap/slapd.d/*
|
||||
find /var/lib/ldap -type f -delete
|
||||
|
||||
echo ""
|
||||
echo "restoring config.ldif .."
|
||||
slapadd -n0 -F/etc/ldap/slapd.d/ -l"$BACKUPDIR/config.ldif"
|
||||
|
||||
echo ""
|
||||
for i in `seq 1 $MAXDB`; do
|
||||
if [ -f "$BACKUPDIR/db-$i.ldif" ]; then
|
||||
echo "restoring database $i .."
|
||||
slapadd -n$i -F/etc/ldap/slapd.d/ -l"$BACKUPDIR/db-$i.ldif"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
chown -R openldap:openldap /etc/ldap/slapd.d/ /var/lib/ldap/
|
||||
|
||||
${SERVICE} start
|
|
@ -0,0 +1,4 @@
|
|||
restore all ldap database from <directory>
|
||||
|
||||
Beware all current data will be erased !
|
||||
|
Reference in New Issue