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/* rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
COPY scripts/ /
COPY fixtures/ /usr/share/slapd/fixtures/ COPY fixtures/ /usr/share/slapd/fixtures/
ENTRYPOINT ["/entrypoint.sh"] 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 use authentication and authorization. Therefore you should think about
backing up the LDAP database in regular intervals. backing up the LDAP database in regular intervals.
**simply copying all the data from `data` MAY NOT WORK**, as there could ```shell
be race conditions leading to database corruption during the backup. # append database number, typically 0 for config and 1 for the main
The recommended way is to use the included script for backing up the database # database.
into a compact .ldif plain text file. $ 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: # .. or similary with docker-compose
* `conf.ldif` is a backup of the configuration. $ docker-compose exec ldap dump 1 > data_dump.ldif
* `data.ldif` contains all the saved datasets. ```

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: environment:
- "ROOTPW=pass" - "ROOTPW=pass"
- "ORGANIZATION=example" - "ORGANIZATION=example"
- "DATADIR=/data" - "CONFDIR=/etc/ldap/slapd.d"
- "CONFDIR=/conf" - "DATADIR=/var/lib/ldap"
volumes: volumes:
- conf:/etc/ldap/slapd.d - conf:/etc/ldap/slapd.d
- data:/var/lib/ldap - data:/var/lib/ldap

View file

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