summaryrefslogtreecommitdiffstats
path: root/ldap/admin/src/scripts/template-db2ldif.in
blob: 2f746703454d1bc01336e1501aa2987b81ff3f07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh

prefix="{{DS-ROOT}}"
if [ "$prefix" = "/" ] ; then
    prefix=""
fi
LD_LIBRARY_PATH=$prefix/{{SERVER-DIR}}:$prefix@nss_libdir@:$prefix@libdir@
if [ -n "$prefix" ] ; then
    LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:@nss_libdir@"
fi
export LD_LIBRARY_PATH
SHLIB_PATH=$LD_LIBRARY_PATH
export SHLIB_PATH

make_ldiffile()
{
    be=""
    while [ "$1" != "" ]
    do
        if [ "$1" = "-a" ]; then
            shift
            echo $1
            return 1
        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 {{LDIF-DIR}}/{{SERV-ID}}-`date +%Y_%m_%d_%H%M%S`.ldif
    else
        echo {{LDIF-DIR}}/{{SERV-ID}}-${be}-`date +%Y_%m_%d_%H%M%S`.ldif
    fi
    return 0
}

cd {{SERVERBIN-DIR}}
if [ "$#" -lt 2 ];
then
    echo "Usage: db2ldif {-n backend_instance}* | {-s includesuffix}*"
    echo "               [{-x excludesuffix}*] [-a outputfile]"
    echo "               [-N] [-r] [-C] [-u] [-U] [-m] [-M] [-1]"
    echo "Note: either \"-n backend_instance\" or \"-s includesuffix\" is required."
    exit 1
fi

ldif_file=`make_ldiffile $@`
rn=$?

echo "Exported ldif file: $ldif_file"
if [ $rn -eq 1 ]
then
./ns-slapd db2ldif -D {{CONFIG-DIR}} "$@"
else
./ns-slapd db2ldif -D {{CONFIG-DIR}} -a $ldif_file "$@"
fi