DO_MYSQL="n"
DO_POSTGRES="n"
+DO_LDAP="n"
declare -a REMOTE_HOSTS=()
+declare -a LDAP_ROOT_DNS=()
DESCRIPTION=$( cat <<-EOF
Macht mal eben so ein Backup.
#------------------------------------------------------------------------------
do_backup_ldap() {
- local dumpfile="${BACKUP_DIR}/ldap.dump.ldif.gz"
if ps -ef | grep slapd | grep -v grep >/dev/null ; then
:
return
fi
- empty_line
- info "Dumping OpenLDAP Datenbank -> '${CYAN}${dumpfile}${NORMAL}' ..."
+ local dumpfile="${BACKUP_DIR}/ldap-cfg.dump.ldif.gz"
- local cmd="ldapsearch -D \"${LDAP_DN}\" -x -h localhost"
+ empty_line
+ info "Dumping OpenLDAP Config -> '${CYAN}${dumpfile}${NORMAL}' ..."
+ local cmd="ldapsearch -Y EXTERNAL -Q -LLL -o ldif-wrap=no -H ldapi:/// -b \"cn=config\""
if [[ "${VERBOSE}" == "y" ]] ; then
- cmd+=" --verbose"
+ cmd+=" -v"
fi
- cmd+=" -z 10000 -w \"${LDAP_PW}\" -b \"${LDAP_SEARCH_BASE}\""
cmd+=" | gzip -9"
if [[ "${VERBOSE}" == "y" ]] ; then
cmd+=" --verbose"
cmd+=" > \"${dumpfile}\""
if [[ "${SIMULATE}" == "y" ]] ; then
info "Executing: ${cmd}"
- return
+ else
+ debug "Executing: ${cmd}"
+ eval ${cmd}
fi
- debug "Executing: ${cmd}"
- eval ${cmd}
+
+ local dn=
+ local clean_dn=
+
+ for dn in "${LDAP_ROOT_DNS[@]}" ; do
+
+ clean_dn=$( echo "${dn}" | sed -e 's/^[ ]*//' -e 's/[ ]*$//' -e 's/[ ][ ]*/_/g' )
+ dumpfile="${BACKUP_DIR}/ldap-db.${clean_dn}.dump.ldif.gz"
+
+ empty_line
+ info "Dumping OpenLDAP Datenbank '${CYAN}${dn}${NORMAL}' -> '${CYAN}${dumpfile}${NORMAL}' ..."
+
+ cmd="ldapsearch -Y EXTERNAL -Q -LLL -o ldif-wrap=no -H ldapi:///"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" -v"
+ fi
+ cmd+=" -b \"${dn}\" '+' '*' | gzip -9"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" --verbose"
+ fi
+ cmd+=" > \"${dumpfile}\""
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Executing: ${cmd}"
+ else
+ debug "Executing: ${cmd}"
+ eval ${cmd}
+ fi
+
+ done
+
debug "Finished LDAP dump."
}
info "Removing '${bdir}' ..."
RM --recursive "${bdir}"
-
done
}
#------------------------------------------------------------------------------
main() {
+ eval_config
get_options "$@"
umask 0022
if [[ "${DO_POSTGRES}" == "y" ]] ; then
do_postgres_backup
fi
- do_backup_ldap
+ if [[ "${DO_LDAP}" == "y" ]] ; then
+ do_backup_ldap
+ fi
create_checksums
clean_old_backups
sync_to_remote
}
+#------------------------------------------------------------------------------
+eval_config() {
+
+ local this_script_real=$( readlink -f "$0" )
+ local script_base=$( basename "${this_script_real}" ".sh" )
+ local bin_dir=$( dirname "${this_script_real}" )
+ local base_dir=$( dirname "${bin_dir}" )
+ local etc_dir="${base_dir}/etc"
+ local rc_file="${etc_dir}/${script_base}.rc"
+
+ debug "Searching for script config resource file '${CYAN}${rc_file}${NORMAL}' ..."
+
+ if [[ ! -d "${etc_dir}" ]] ; then
+ return
+ fi
+ if [[ ! -e "${rc_file}" ]] ; then
+ return
+ fi
+
+ if [[ ! -f "${rc_file}" ]] ; then
+ error "Script config resource file '${RED}${rc_file}${NORMAL}' exists, but is not a regular file."
+ return
+ fi
+
+ debug "Sourcing script config resource file '${CYAN}${rc_file}${NORMAL}' ..."
+ source "${rc_file}"
+
+}
+
# vim: filetype=sh ts=4 et list