source: n4d-ldap/trunk/fuentes/install/usr/sbin/llx-slapd-backup @ 149

Last change on this file since 149 was 149, checked in by hectorgh, 4 years ago

adding project files

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#!/bin/bash
2function usage(){
3        echo -e "usage\n"
4}
5if [ $# -lt 2 ]; then
6        usage
7fi
8
9capture_diagnostics() {                                                 # {{{
10# Run the command passed and capture the diagnostic output in a temporary
11# file. You can dump that file using release_diagnostics.
12
13        # Create the temporary file
14        local tmpfile
15        tmpfile=`mktemp`
16        exec 7<>"$tmpfile"
17        rm "$tmpfile"
18
19        # Run the program and capture stderr. If the program fails the
20        # function fails with the same status.
21        echo $tmpfile
22        "$@" 2>&7 || { rc=$?; echo $rc ; return $rc ;}
23}
24
25OPTION=$1
26BACKUPFILE=$2
27BACKUPDIR=$(mktemp -d)
28case $OPTION in
29dump)
30       
31        /etc/init.d/slapd stop
32        slapcat -n 0 > ${BACKUPDIR}/config.ldif
33        slapcat -n 1 > ${BACKUPDIR}/data.ldif
34        mkdir -p ${BACKUPDIR}/install/etc/default
35        mkdir -p ${BACKUPDIR}/install/etc/lliurex-secrets/passgen/
36        mkdir -p ${BACKUPDIR}/install/etc/ldap/ssl
37        rsync -ptgox /etc/ldap/ssl/slapd.cert ${BACKUPDIR}/install/etc/ldap/ssl/
38        rsync -ptgox /etc/ldap/ssl/slapd.key ${BACKUPDIR}/install/etc/ldap/ssl/
39        rsync -ptgox /etc/default/slapd  ${BACKUPDIR}/install/etc/default/
40        rsync -ptgox /etc/lliurex-secrets/passgen/ldap.secret ${BACKUPDIR}/install/etc/lliurex-secrets/passgen/
41        /etc/init.d/slapd start
42       
43        tar -czf $BACKUPFILE -C $BACKUPDIR .
44        # crear un tar.gz con los ficheros
45
46        ;;
47restore)
48
49        tar -xzf $BACKUPFILE -C $BACKUPDIR     
50
51        SLAPD_CONF="/etc/ldap/slapd.d"
52        SLAPD_DB_PATH="/var/lib/ldap"
53        SLAPD_USER="openldap"
54        SLAPD_GROUP="openldap"
55        SLAPD_RUN="/run/slapd"
56
57        /etc/init.d/slapd stop
58        rm -rf ${SLAPD_CONF} || true
59        mkdir -p -m 0755 $SLAPD_CONF
60        chown ${SLAPD_USER}:${SLAPD_GROUP} $SLAPD_CONF || die "On /etc/default/slapd aren't SLAPD_USER or SLAPD_GROUP variable"
61
62        rm -rf $SLAPD_DB_PATH || true
63        mkdir -m 0700 $SLAPD_DB_PATH || true
64        chown ${SLAPD_USER}:${SLAPD_GROUP} $SLAPD_DB_PATH || die "On /etc/default/slapd aren't SLAPD_USER or SLAPD_GROUP variable"
65
66        SLAPD_RUN="/run/slapd"
67        rm -rf $SLAPD_RUN || true
68        mkdir -m 0755 $SLAPD_RUN || true
69        chown ${SLAPD_USER}:${SLAPD_GROUP} $SLAPD_RUN || die "On /etc/default/slapd aren't SLAPD_USER or SLAPD_GROUP variable"
70
71
72        capture_diagnostics slapadd -F "${SLAPD_CONF}" -b "cn=config" -l ${BACKUPDIR}/config.ldif
73        chown -R ${SLAPD_USER}:${SLAPD_GROUP} $SLAPD_CONF || die "On /etc/default/slapd aren't SLAPD_USER or SLAPD_GROUP variable"
74
75        capture_diagnostics slapadd -l ${BACKUPDIR}/data.ldif
76        chown -R ${SLAPD_USER}:${SLAPD_GROUP} $SLAPD_DB_PATH || die "On /etc/default/slapd aren't SLAPD_USER or SLAPD_GROUP variable"
77
78        rsync -ax ${BACKUPDIR}/install/* /
79        chmod 600 /etc/lliurex-secrets/passgen/ldap.secret
80        /etc/init.d/slapd start
81       
82        ;;
83esac
84
85
Note: See TracBrowser for help on using the repository browser.