diff --git a/Dockerfile b/Dockerfile index 3d3f757..66a513c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 4c9cbf9..45cdadb 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/contrib/create-backup.sh b/contrib/create-backup.sh deleted file mode 100644 index 36eda4d..0000000 --- a/contrib/create-backup.sh +++ /dev/null @@ -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 diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 165eff2..9c2daec 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -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 diff --git a/entrypoint.sh b/entrypoint.sh index 93d4872..e2501ca 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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" \ diff --git a/scripts/dump b/scripts/dump new file mode 100755 index 0000000..931c25f --- /dev/null +++ b/scripts/dump @@ -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 \ No newline at end of file