Create openldap restore script in agent

This commit is contained in:
Eric Renfro 2021-09-04 19:34:13 -04:00
parent 00e32f8f5e
commit a0b3ffe2c8
Signed by: psi-jack
GPG key ID: 14977F3A50D9A5BF

View file

@ -13,8 +13,50 @@ hook_check() {
hook_pre() {
hook_check
mkdir -p "$ldapDir" || exit 1
pushd "$restoreDir" || exit 2
slapcat -n 0 -l "$ldapDir/config.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() {