From 0ee90a135587a8e99440817551b7fe5d0f4cff1c Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 10 Nov 2019 09:53:21 +0100 Subject: [PATCH] Integrate and document backup scripts --- Dockerfile | 1 + README.md | 15 ++++++++------- contrib/create-backup.sh | 9 --------- docker-compose.yml.example | 4 ++-- entrypoint.sh | 1 + scripts/dump | 13 +++++++++++++ 6 files changed, 25 insertions(+), 18 deletions(-) delete mode 100644 contrib/create-backup.sh create mode 100755 scripts/dump 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