#OPEN LDAP database restore
echo $1
# LDAP installation directory
LDAPDIR=/usr/local/openldap
# ldapadd file path in
OPENLDP LDAPADD=$LDAPDIR/bin/ldapadd
# BACKDIR is the storage address of the database backup, which can be customized and modified to the remote address
BACKDIR=/home/backup/ldap
#OPENLDAP 账号密码
LDAPNAME="cn=Manager,dc=chinautrust,dc=com"
LDAPPWD="password12345"
echo $LDAPNAME
echo $LDAPPWD
TODAY=$1
# Restore the directory of data selection
RECOVERYDIR=$BACKDIR/$TODAY
echo $RECOVERYDIR
# Get all file names in the directory and save them to a variable
DBLIST_TMP=`ls -p $RECOVERYDIR`
echo $DBLIST_TMP
#Convert to collection object
DBLIST=($(echo $DBLIST_TMP))
echo "The elements in the set are: "+${DBLIST[@]}
if [ -n "$1" ] ;then
# Loop out the database name from the database list and perform the backup operation
for recoveryName in ${DBLIST[@]}
do
echo $RECOVERYDIR/$recoveryName
${LDAPADD} -x -c -D ${LDAPNAME} -w ${LDAPPWD} -f $RECOVERYDIR/$recoveryName
# Check the execution result, if the error code is 0, the output is successful, otherwise the output fails
[ $? -eq 0 ] && echo "${recoveryName} has been recoveried successful" || echo "${recoveryName} has been recovered failed"
# Wait for 3s, you can customize
/bin/sleep 3
done
else
echo 'The incoming parameter is empty'
fi