Backup and restore of openldap on linux

In the past two days, Baidu backed up openldap according to the ldapsearch method, but the generated ldif file was empty. It took me a long time to study it. Later, the slapcat backup and slapadd restore methods were easier to use.

The backup script is as follows (the generated ldif file will contain some system information, which needs to be imported using slapadd):

echo 'Ready to start backup ldap'
DATEFORMATTYPE1=$(date +%Y-%m-%d)
DATEFORMATTYPE2=$(date +%Y%m%d%H%M%S)
echo $DATEFORMATTYPE1

#Use slapcat to backup
LDAPDIR=/usr/local/openldap

LDAPSCAT=$LDAPDIR/sbin/slapcat #Backup
directory
BACKDIR=/home/backup/ldap/$DATEFORMATTYPE1

${LDAPSCAT} -l ${BACKDIR}/before.ldif;

The restored command is as follows (note: openldap must be closed, and the root node before openldap, including dc=chinautrust, dc=com, will be deleted, otherwise an error will be reported ):

 

./slapadd -l /home/before.ldif

After the import is successful, restart openldap:

/usr/local/openldap/libexec/slapd $

 

View the process after restarting: 

ps -ef|grep openldap

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324408017&siteId=291194637