#!/bin/sh source @datadir@/@package_name@/data/DSSharedLib libpath_add "@libdir@/@package_name@/" libpath_add "@nss_libdir@" libpath_add "@libdir@" libpath_add "@pcre_libdir@" export LD_LIBRARY_PATH SHLIB_PATH=$LD_LIBRARY_PATH export SHLIB_PATH cwd=`pwd` usage() { echo "Usage: db2ldif [-Z serverID] {-n backend_instance}* | {-s includesuffix}* [{-x excludesuffix}*] [-a outputfile]" echo " [-E] [-r] [-u] [-U] [-m] [-1] [-q] [-h]" echo "Note: either \"-n backend\" or \"-s includesuffix\" is required." echo "Options:" echo " -Z serverID - Server instance identifier" echo " -n backend - Backend database name. Example: userRoot" echo " -s inclduesuffix - Suffix to include" echo " -x - Suffix to exclude" echo " -a outputfile - Name of the exported LDIF file" echo " -r - Include replication data" echo " -E - Decrypt attributes" echo " -u - Do not export the nsUniqueId attribute" echo " -U - Do not wrap long lines" echo " -m - Do not base64 encode values" echo " -1 - Do not include version text" echo " -q - Quiet mode - suppresses output" echo " -h - Display usage" } make_ldiffile() { be="" while [ "$1" != "" ] do if [ "$1" = "-a" ]; then shift if [ `expr "$1" : "/.*"` -gt 0 ]; then if [ `expr "$1" : "/.*"` -gt 0 ]; then # full path echo $1 return 1 else echo $cwd/$1 shift return 0 fi else echo $cwd/$1 shift return 0 fi elif [ "$1" = "-n" ]; then shift if [ "$be" = "" ]; then be="$1" else tmpbe="$be" be="${tmpbe}-$1" fi elif [ "$1" = "-s" ]; then shift if [ "$1" != "" ]; then rdn=`echo $1 | awk -F, '{print $1}'` rdnval=`echo $rdn | awk -F= '{print $2}'` if [ "$be" = "" ]; then be="$rdnval" else tmpbe="$be" be="${tmpbe}-$rdnval" fi fi elif [ "$1" = "-M" ]; then be="" fi if [ "$1" != "" ]; then shift fi done if [ "$be" = "" ]; then echo @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/ldif/$servid-`date +%Y_%m_%d_%H%M%S`.ldif else echo @localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/ldif/$servid-${be}-`date +%Y_%m_%d_%H%M%S`.ldif fi return 0 } if [ "$#" -lt 2 ]; then usage exit 1 fi while getopts "hZ:vd:D:ENa:rs:x:CSut:n:UmMo1qc:" flag do case $flag in h) usage exit 0;; Z) servid=$OPTARG;; n) benameopt="-n $OPTARG" required_param="yes";; s) includeSuffix="-s $OPTARG" required_param="yes";; x) excludeSuffix="-x $OPTARG";; a) outputFile="-a $OPTARG";; d) args=$args" -d $OPTARG";; D) args=$args" -D $OPTARG";; N) args=$args" -N";; E) args=$args" -E";; S) args=$args" -S";; v) args=$args" -v";; r) args=$args" -r";; C) args=$args" -C";; u) args=$args" -u";; U) args=$args" -U";; m) args=$args" -m";; M) args=$args" -M";; 1) args=$args" -1";; q) args=$args" -q";; c) cwd=$OPTARG;; ?) usage exit 1;; esac done if [ "$required_param" != "yes" ] then usage exit 1 fi initfile=$(get_init_file "@initconfigdir@" $servid) if [ $? == 1 ] then usage echo "You must supply a valid server instance identifier. Use -Z to specify instance name" echo "Available instances: $initfile" exit 1 fi servid=`normalize_server_id $initfile` . $initfile ldif_file=`make_ldiffile $@` rn=$? echo "Exported ldif file: $ldif_file" if [ $rn -eq 1 ] then @sbindir@/ns-slapd db2ldif -D $CONFIG_DIR $benameopt $includeSuffix $excludeSuffix $outputFile $args else @sbindir@/ns-slapd db2ldif -D $CONFIG_DIR $benameopt $includeSuffix $excludeSuffix $args -a $ldif_file fi