LDAP数据备份及同步检查脚本


#!/bin/bash
#OpenLDAP数据备份脚本

set -e

cd $(dirname $0)
echo dir=$(pwd)

mkdir /data/openldap-$(date "+%Y%m%d") 
mkdir /data/openldap-$(date "+%Y%m%d")/db 
mkdir /data/openldap-$(date "+%Y%m%d")/etc

cp -r /var/lib/ldap  /data/openldap-$(date "+%Y%m%d")/db/
cp -r /etc/openldap  /data/openldap-$(date "+%Y%m%d")/etc/

tar czf openldap-$(date "+%Y%m%d").tar.gz openldap-$(date "+%Y%m%d")
rm -rf /data/openldap-$(date "+%Y%m%d")

date >> rm.log
for i in $(find . -maxdepth 1 -mindepth 1  -mtime +90 -name "openldap-20*" |sed 's#./##')
do 
    echo rm -rf "/data/$i" >> rm.log
    rm -rf "/data/$i"
done
echo --------------------------------------- >> rm.log

#scp -r /data/openldap-$(date "+%Y%m%d").tar.gz root@192.168.200.101:/opt/backupdir/


#!/bin/bash
#OpenLDAP同步检查脚本

cmd_dir=$(
        cd $(dirname $0)
        pwd
)

cd $cmd_dir
date >>ldap-replication-check.log

tail -n20 /data/openldap/logs/slapd.log | grep "ldap_sasl_bind_s failed" >/dev/null 2>&1
if [ $? -eq 0 ]; then
        echo "LDAP客户端同步错误,重启LDAP服务!!" >>ldap-replication-check.log
        docker restart openldap-replicator >/dev/null 2>&1
        if [ $? -ne 0 ]; then
                echo "重启docker服务失败,请手动检查!!" >>ldap-replication-check.log
        fi
else
        echo "未发现错误..." >>ldap-replication-check.log
fi

echo "------------------------------------------------------------" >>ldap-replication-check.log