openldap数据备份还原

数据备份
[root@Server ~]# slapcat -n 2 -l /root/ldapbackup_ilanni.ldif
脚本 -----

#!/bin/bash
# 备份脚本
PATH="/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
export PATH

BACKDIR=/sdata/usr/local/openldap/backups
DATE=`date '+%Y%m%d'`
BACKFILE=ldapbackup_${DATE}.ldif

DEBUG=1

# check of the backup directory exists.if not, create it
if [ -e $BACKDIR ]
then
echo Backups directory already exists
else
mkdir -p $BACKDIR
fi


echo Backing up LDAP entries…

if [ $DEBUG -eq 1 ]
then
slapcat -n 2 -l $BACKDIR/$BACKFILE 2>/dev/null
else
slapcat -n 2 -l $BACKDIR/$BACKFILE 2>/dev/null
fi

#只保留10天的数据
find $BACKDIR -mtime +10 -name "*.ldif" -exec rm -rf {} \;

 

数据还原

停止服务
[root@Server ~]# systemctl stop slapd
清空数据
[root@Server ~]# rm -rf /var/lib/ldap/*
导入数据
[root@Server ~]# slapadd -l /sdata/usr/local/openldap/backups/ldapbackup_********.ldif
[root@Server ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
[root@Server ~]# chown -R ldap:ldap /var/lib/ldap/*
[root@Server ~]# ls -al /var/lib/ldap/
[root@Server ~]# systemctl restart slapd
[root@Server ~]# systemctl status slapd

转载
https://www.cnblogs.com/ccdc/p/3356518.html
http://www.361way.com/openldap-bak-imp-move/2366.html
https://www.ilanni.com/?p=14065#%E5%9B%9B%E3%80%81%E9%AA%8C%E8%AF%81openldap%E6%95%B0%E6%8D%AE

你可能感兴趣的:(openldap数据备份还原)