Integrate and document backup scripts

This commit is contained in:
paul 2019-11-10 09:53:21 +01:00
parent 141ab43caa
commit 0ee90a1355
6 changed files with 25 additions and 18 deletions

View file

@ -24,6 +24,7 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY entrypoint.sh /entrypoint.sh
COPY scripts/ /
COPY fixtures/ /usr/share/slapd/fixtures/
ENTRYPOINT ["/entrypoint.sh"]

View file

@ -64,11 +64,12 @@ State stored in this container is essential to many other services, that
use authentication and authorization. Therefore you should think about
backing up the LDAP database in regular intervals.
**simply copying all the data from `data` MAY NOT WORK**, as there could
be race conditions leading to database corruption during the backup.
The recommended way is to use the included script for backing up the database
into a compact .ldif plain text file.
```shell
# append database number, typically 0 for config and 1 for the main
# database.
$ docker exec -it ldap dump 0 > conf_dump.ldif
$ docker exec -it ldap dump 1 > data_dump.ldif
running `contrib/create-ldap-backup.sh` will create two files:
* `conf.ldif` is a backup of the configuration.
* `data.ldif` contains all the saved datasets.
# .. or similary with docker-compose
$ docker-compose exec ldap dump 1 > data_dump.ldif
```

View file

@ -1,9 +0,0 @@
#!/bin/bash
CONF_LOCATION=/data/slapd.d
CONTAINER_NAME=ldap
# dump configuration
docker exec -it ldap slapcat -F $CONF_LOCATION -n 0 > conf.ldif
# dump data
docker exec -it ldap slapcat -F $CONF_LOCATION -n 1 > data.ldif

View file

@ -14,8 +14,8 @@ services:
environment:
- "ROOTPW=pass"
- "ORGANIZATION=example"
- "DATADIR=/data"
- "CONFDIR=/conf"
- "CONFDIR=/etc/ldap/slapd.d"
- "DATADIR=/var/lib/ldap"
volumes:
- conf:/etc/ldap/slapd.d
- data:/var/lib/ldap

View file

@ -47,6 +47,7 @@ function init_fixtures {
echo "$0: running $f"; . "$f"
;;
*.ldif)
echo "$0: applying $f"
sed \
-e "s|@SUFFIX@|${SUFFIX}|g" \
-e "s|@PASSWORD@|${ROOTPW}|g" \

13
scripts/dump Executable file
View file

@ -0,0 +1,13 @@
#!/bin/bash
conf=${CONFDIR:-/data/slapd.d}
# typically, 0 is configuration, and 1 is the main database
db_id=${1:-1} # default value is 1.
if [ "${db_id}" -ge 0 && "${db_id}" -ls 10 ] ; then
slapcat -F ${conf} -n ${db_id}
else
echo "database number is invalid" > /dev/stderr
exit 1
fi