Create openldap restore script in agent
This commit is contained in:
parent
00e32f8f5e
commit
a0b3ffe2c8
1 changed files with 42 additions and 0 deletions
|
@ -13,8 +13,50 @@ hook_check() {
|
||||||
hook_pre() {
|
hook_pre() {
|
||||||
hook_check
|
hook_check
|
||||||
mkdir -p "$ldapDir" || exit 1
|
mkdir -p "$ldapDir" || exit 1
|
||||||
|
pushd "$restoreDir" || exit 2
|
||||||
|
|
||||||
slapcat -n 0 -l "$ldapDir/config.ldif"
|
slapcat -n 0 -l "$ldapDir/config.ldif"
|
||||||
slapcat -n 1 -l "$ldapDir/data.ldif"
|
slapcat -n 1 -l "$ldapDir/data.ldif"
|
||||||
|
|
||||||
|
cat > ldaprestore.sh <<EOF
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ ! -d openldap ]]; then
|
||||||
|
echo "This needs to be run in the restore directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ ! -f openldap/config.ldif ]]; then
|
||||||
|
echo "This needs to be run in the restore directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
currDate="\$(date '+%Y-%m-%d')"
|
||||||
|
|
||||||
|
systemctl stop slapd
|
||||||
|
sleep 5
|
||||||
|
pkill slapd
|
||||||
|
|
||||||
|
if [[ -d /etc/ldap/slapd.d ]]; then
|
||||||
|
mv /etc/ldap/slapd.d "/etc/ldap/slapd.d.\$currDate"
|
||||||
|
mkdir -p /etc/ldap/slapd.d
|
||||||
|
slapadd -n 0 -F /etc/ldap/slapd.d -l openldap/config.ldif
|
||||||
|
chown -R ldap:ldap /etc/ldap/slapd.d
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -d /var/lib/ldab ]]; then
|
||||||
|
mv /var/lib/ldap "/var/lib/ldap.\$currDate"
|
||||||
|
mkdir -p /var/lib/ldap
|
||||||
|
|
||||||
|
if [[ -d /etc/ldap/slapd.d ]]; then
|
||||||
|
slapadd -n 1 -F /etc/ldap/slapd.d -l openldap/data.ldif -w
|
||||||
|
fi
|
||||||
|
chown -R ldap:ldap /var/lib/ldap
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Backups have been restored. If you see no errors above, then you can start your server back up."
|
||||||
|
EOF
|
||||||
|
|
||||||
|
popd || exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_post() {
|
hook_post() {
|
||||||
|
|
Loading…
Reference in a new issue