--- /dev/null
+#!/bin/bash
+
+set -e
+set -u
+
+BASE_NAME="$( basename ${0} )"
+MY_REAL_NAME=$( readlink -f $0 )
+
+if [[ -f /usr/libexec/pixelpark/functions.rc ]] ; then
+ . /usr/libexec/pixelpark/functions.rc
+else
+ echo "Did not found /usr/libexec/pixelpark/functions.rc." >&2
+ exit 5
+fi
+
+HOSTNAME=$( hostname -s )
+CUR_DATE=$( date +'%Y-%m-%d' )
+
+EXP_DIR="/var/backup"
+DIRS2BACKUP="/home /var/log/dirsrv-backup /var/backup/dirsrv/* /etc/dirsrv /root"
+LOG_DIR="/var/log/dirsrv"
+BIN_DIR='/var/lib/dirsrv'
+
+detect_color
+
+set_locale "en_US.utf8"
+
+DESCRIPTION=$( cat <<-EOF
+ Creating backups of all relevant directories of a LDAP server host in '${EXP_DIR}',
+ so that they can copied outside, and the VM can be dismantled.
+
+ EOF
+)
+
+#------------------------------------------------------------------------------
+usage() {
+ cat <<-EOF
+ Usage: ${BASE_NAME} [Common Options]
+ ${BASE_NAME} [-h|--help]
+ ${BASE_NAME} [-V|--version]
+
+ Common Options:
+ STD_USAGE_MSG}
+ EOF
+
+}
+
+#------------------------------------------------------------------------------
+get_options() {
+
+ local tmp=
+ local base_dir=
+
+ set +e
+ tmp=$( getopt -o ${STD_SHORT_OPTIONS} \
+ --long ${STD_LONG_OPTIONS} \
+ -n "${BASE_NAME}" -- "$@" )
+
+ if [[ $? != 0 ]] ; then
+ echo "" >&2
+ usage >&2
+ exit 1
+ fi
+ set -e
+
+ # Note the quotes around `$TEMP': they are essential!
+ eval set -- "${tmp}"
+ eval_common_options "$@"
+
+ check_for_root
+
+}
+
+#------------------------------------------------------------------------------
+backup_dir() {
+
+ local dir2backup="$1"
+
+ empty_line
+
+ info "Backup of '${CYAN}${dir2backup}${NORMAL}' ...."
+
+ local backup_basename=$( echo "${dir2backup}" | sed -e 's|^/*||' -e 's|/|_|g' )
+ local backup_name="${EXP_DIR}/${backup_basename}.${HOSTNAME}.${CUR_DATE}.tar.bz2"
+
+ local cmd="tar --create"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" --verbose"
+ fi
+ cmd+=" --bzip2 --file \"${backup_name}\" \"${dir2backup}\""
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Simulate executing: ${cmd}" >&2
+ else
+ debug "Executing: ${cmd}" >&2
+ eval ${cmd}
+ fi
+ empty_line
+ sleep 0.3
+
+}
+
+#------------------------------------------------------------------------------
+stop_slapd_instance() {
+
+ local instance="$1"
+
+ local short_name=$( echo "${instance}" | sed -e 's/^slapd-//i' )
+ local service="dirsrv@${short_name}.service"
+
+ info "Stopping '${CYAN}${service}${NORMAL}' ..."
+
+ local cmd="systemctl stop ${service}"
+
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ info "Simulate executing: ${cmd}" >&2
+ else
+ debug "Executing: ${cmd}" >&2
+ eval ${cmd}
+ fi
+ empty_line
+ sleep 0.3
+
+ info "Status of '${CYAN}${service}${NORMAL}':"
+ systemctl status ${service} || true
+ empty_line
+ sleep 0.3
+}
+
+#------------------------------------------------------------------------------
+main() {
+
+ get_options "$@"
+
+ local slapd_instances
+ local dir
+ local inst
+
+ slapd_instances=$( dsctl -l )
+
+ for dir in ${DIRS2BACKUP} ; do
+ backup_dir "${dir}"
+ done
+
+ for inst in ${slapd_instances} ; do
+ stop_slapd_instance "${inst}"
+ done
+
+ backup_dir "${LOG_DIR}"
+ backup_dir "${BIN_DIR}"
+
+ if [[ "${QUIET}" != "y" ]] ; then
+ info "Created backups in '${CYAN}${EXP_DIR}${NORMAL}':"
+ ls -l -A --color=always "${EXP_DIR}"/*.tar.bz2 || true
+ fi
+
+ empty_line
+ info "Finished."
+
+}
+
+main "$@"
+
+exit 0
+
+# vim: ts=4 et shiftwidth=4 softtabstop=4 list