Compare commits
3 Commits
cee70f7ed8
...
823c7b098c
Author | SHA1 | Date |
---|---|---|
Asif Bacchus | 823c7b098c | |
Asif Bacchus | 8347b89725 | |
Asif Bacchus | 0f3f012fd7 |
|
@ -1,6 +1,6 @@
|
|||
#
|
||||
## openldap environment variables
|
||||
# version 3.0
|
||||
# version 3.2
|
||||
#
|
||||
|
||||
### Usage
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#
|
||||
### start openldap container using params file variables
|
||||
# version 3.1
|
||||
# version 3.2
|
||||
#
|
||||
|
||||
|
||||
|
@ -45,11 +45,13 @@ cyan=$(tput setaf 6)
|
|||
err=$(tput bold)$(tput setaf 1)
|
||||
magenta=$(tput setaf 5)
|
||||
norm=$(tput sgr0)
|
||||
red=$(tput setaf 1)
|
||||
yellow=$(tput setaf 3)
|
||||
width=$(tput cols)
|
||||
|
||||
### parameter defaults
|
||||
scriptName="$( basename "$0" )"
|
||||
clean=false
|
||||
restore=false
|
||||
container_name="ab-openldap"
|
||||
volume_data="ab-openldap_data"
|
||||
|
@ -91,6 +93,9 @@ scriptHelp () {
|
|||
textblock "${cyan}-s|--shell${norm}"
|
||||
textblock "Switch parameter. Enter the container using an interactive POSIX shell. This happens after startup operations but *before* openLDAP (slapd) is started. This is a great way to test out configuration changes or run custom queries. You can combine this with '--rm' for easy configuration checks or LDIF imports."
|
||||
printf "\n"
|
||||
textblock "${cyan}--clean${norm}"
|
||||
textblock "Switch parameter. This option will stop and remove ALL running openLDAP containers *AND DESTROY ALL VOLUMES*. This is meant to give you a 'clean start' if you've made configuration changes, etc."
|
||||
printf "\n"
|
||||
textblock "${cyan}--restore${norm}"
|
||||
textblock "Switch parameter. Restore a 'slapcat' backup to the data and ldif volumes in preparation for mounting them in a normal container. It is strongly recommended you review your '-t' '--data' and '--ldif' settings before proceeding with this option."
|
||||
printf "\n"
|
||||
|
@ -136,6 +141,10 @@ while [ $# -gt 0 ]; do
|
|||
# start shell instead of default CMD
|
||||
shell=true
|
||||
;;
|
||||
--clean)
|
||||
# stop if necessary, delete volumes
|
||||
clean=true
|
||||
;;
|
||||
--restore)
|
||||
# restore backup
|
||||
restore=true
|
||||
|
@ -191,8 +200,48 @@ done
|
|||
|
||||
|
||||
### process main operations
|
||||
if [ $clean = true ]; then
|
||||
# cleanup containers and volumes
|
||||
# display warning and confirm user's intentions
|
||||
printf "\nThis will stop and remove all ab-openldap containers %sAND REMOVE ALL PERSISTENT DATA VOLUMES%s. Please ensure you have a backup and understand how to restore your data.\n" \
|
||||
"$red" "$norm"
|
||||
printf "%sThis action CANNOT be undone!%s\n\n" \
|
||||
"$red" "$norm"
|
||||
prompt_yn
|
||||
|
||||
# get all ab-openldap containers
|
||||
containers=$(docker ps -a --no-trunc --filter "label=org.label-schema.name=ab-openldap" --format "{{ .Names }}")
|
||||
# check for null value -- no containers to remove
|
||||
if [ -z "$containers" ]; then
|
||||
consoleError '0' 'No openldap containers to remove.'
|
||||
fi
|
||||
|
||||
if [ $restore = true ]; then
|
||||
# iterate containers, stop them and remove straggling volumes
|
||||
set -- dummy $containers
|
||||
shift
|
||||
for container; do
|
||||
printf "\n%sFound %s -- processing:%s\n" \
|
||||
"$cyan" "$container" "$norm"
|
||||
# stop container
|
||||
printf "\t%sStopping container...%s\n" "$red" "$norm"
|
||||
docker stop ${container} > /dev/null 2>&1
|
||||
# find volumes
|
||||
volumes=$(docker inspect --format '{{ range .Mounts }}{{ println .Name }}{{ end }}' ${container})
|
||||
# remove container
|
||||
printf "\t%sRemoving container...%s\n" "$red" "$norm"
|
||||
docker rm -f ${container} > /dev/null 2>&1
|
||||
# pause to allow write flushing
|
||||
sleep 3
|
||||
# iterate volumes
|
||||
set -- dummy2 $volumes
|
||||
shift
|
||||
for volume; do
|
||||
printf "\t%sRemoving volume '%s'...%s\n" "$red" "$volume" "$norm"
|
||||
docker volume rm -f ${volume} > /dev/null 2>&1
|
||||
done
|
||||
printf "%s...done%s\n" "$cyan" "$norm"
|
||||
done
|
||||
elif [ $restore = true ]; then
|
||||
# automatically restore backups using a temp container to create volumes
|
||||
printf "%s\n*** Restoring Backup ***\n\n%s" "$magenta" "$norm"
|
||||
printf "To avoid errors due to existing files, this script will delete any volumes that have the following names (based on --data and --ldif):\n"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#######
|
||||
### openLDAP backup script parameters file
|
||||
### version 3.0
|
||||
### version 3.2
|
||||
#######
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#
|
||||
### backup openLDAP configuration and frontend database(s)
|
||||
# version 3.1
|
||||
# version 3.2
|
||||
#
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
1ee82b7c5f03b88b8c5d085e7dc66a60d5ed1c0134c31bdec703b74a705904a5 ab-openldap.sh
|
||||
52a06b492645eec6d3df31168060618a4f464e9d0d2e303d6c379b7b9173353c backup.sh
|
||||
3a6178a07571c14e3036aeede7bfb5fa7982faf682b7b919d2f05dbf07e080da ab-openldap.sh
|
||||
7e49710a156a2722b7f2dbf92b4f3e4b51bcfbf97403b4698ad4ef0216eadef6 backup.sh
|
||||
5f228bddbe83bbaa495ad4095a50778c865d3288179148829820b55d00511ca5 update.sh
|
||||
e0a20b8eef4e12c1770595c750ee58c0bedb55d0b735756b3637cd17b761e4d8 ab-openldap.params.template
|
||||
42d8a45d203bb729d5dadb9fa9a4b597d6f834468f65676a9f0f3cef92831c4c backup.params.template
|
||||
1be75b2ac18dbc7e7f9eeaedffac688d055435b170b00fadb5d5cb3b55398472 ab-openldap.params.template
|
||||
407e732d110cd0dea8e257e22953931fc51237d7583a69722da3b1d7843f0738 backup.params.template
|
||||
|
|
Loading…
Reference in New Issue