统计用户和组

user:
ldapsearch -x -D cn=admin,dc=rd,dc=hoperun,dc=com -w 123456aA -b "ou=Users,dc=rd,dc=hoperun,dc=com" cn | grep -v '#' | grep -v '^$' | grep -v dn   | grep cn groups
ldapsearch -x -D cn=admin,dc=rd,dc=hoperun,dc=com -w 123456aA -b "ou=groups,dc=rd,dc=hoperun,dc=com" cn | grep -v '#' | grep -v '^$' | grep -v dn   | grep cn 

乱码问题ldapsearch获取中文组织结构为加密过的字符串:

[root@localhost ldap]# echo "Y2496ZSA5ZSu566h55CG6YOoLG91PWdyb3VwcyxkYz1yZCxkYz1ob3BlcnVuLGRjPWNvbQ==" |  perl -MMIME::Base64 -ne 'print decode_base64($_)'
cn=销售管理部,ou=groups,dc=rd,dc=hoperun,dc=com[root@localhost ldap]# 
#!/bin/bashbasePath=$(cd `dirname $0`; pwd)tmpDir="${basePath}/tmp"
dataFile=${tmpDir}/ldap.outif [ ! -d "${tmpDir}" ]; thenmkdir ${tmpDir}
fildapsearch -LLL -x -h 172.16.10.1** -b "ou=groups,dc=rd,dc=hoperun,dc=com" "(objectClass=posixAccount)" dn | grep -v "^$"> $dataFile
while read line
dostr=`echo $line | awk -F '::' '{print $1}'`if [ "$str" == "dn" ]; thenresult=`echo $line | awk '{print $2}' | perl -MMIME::Base64 -ne 'print decode_base64($_)'| iconv -f utf8 | sed 's/,/ /g' | awk '{$NF=$(NF-1)="";print}'`elseresult=`echo $line | awk '{print $2}' | sed 's/,/ /g' | awk '{$NF=$(NF-1)="";print}'`fiecho $result
done < $dataFile

objectClass: groupOfNames:添加组

[root@localhost group]# cat addgroup_groupOfNames.ldif
dn: cn=jettoapi_group1,ou=groups,dc=rd,dc=hoperun,dc=com
objectClass: groupOfNames
cn: jettomanager_group1
member: cn=root,ou=Users,dc=rd,dc=hoperun,dc=com
member: cn=admin,ou=Users,dc=rd,dc=hoperun,dc=com
member: cn=jettoapi_user2,ou=Users,dc=rd,dc=hoperun,dc=com

objectClass:posixGroup:方式添加组

[root@localhost group]# cat addgroup_posixGroup.ldif
dn: cn=test_group,ou=groups,dc=rd,dc=hoperun,dc=com
objectClass:posixGroup
objectClass:top
gidNumber:1001
cn: test_group

组中添加用户

[root@localhost group]# cat u2g.ldif
dn: cn=test_group,ou=groups,dc=rd,dc=hoperun,dc=com
changetype: modify
add: member
member: cn=test,ou=Users,dc=rd,dc=hoperun,dc=com
adduser.ldif  addusermodify.ldif  readme
[root@localhost ldap]# cat adduser.ldif
dn: cn=test,ou=Users,dc=rd,dc=hoperun,dc=com
cn: test
displayName: test
mail: test@hoperun.com
sn: test
uid: test
objectClass: inetOrgPerson
objectClass: top
userPassword: 123456aA
[root@localhost ldap]# cat addusermodify.ldif
dn: cn=test,ou=Users,dc=rd,dc=hoperun,dc=com
changetype: add
cn: test
displayName: test
mail: test@hoperun.com
sn: test
uid: test
objectClass: inetOrgPerson
objectClass: top
userPassword: 123456aA
[root@localhost ldap]# cat readme
add:
ldapadd -x -D cn=admin,dc=rd,dc=hoperun,dc=com -w 123456aA -f adduser.ldif
或
ldapmodify -a -x -D "cn=admin,dc=rd,dc=hoperun,dc=com" -w 123456aA -f adduser.ldif
或 注意修改addusermodify文件
ldapmodify  -x -D "cn=admin,dc=rd,dc=hoperun,dc=com" -w 123456aA -f addusermodify.ldif[root@localhost ldap]# ldapsearch -x -D cn=admin,dc=rd,dc=hoperun,dc=com -w 123456aA -b "ou=Users,dc=rd,dc=hoperun,dc=com" cn=testdelete:
ldapdelete -x -D cn=admin,dc=rd,dc=hoperun,dc=com -w 123456aA  cn=test,ou=Users,dc=rd,dc=hoperun,dc=com

在添加用户的时候关键的objectclass是inetOrgPerson,而对于添加部门,关键信息则为organisationalUnit,添加两个OrganisationUnit的LDIF信息如下:

cat orgunits.ldif
加入组织People
dn: ou=People,dc=rd,dc=hoperun,dc=com
changetype: add
objectclass: top
objectclass: organizationalUnit
ou: People加入组织Servers
dn: ou=Servers,dc=rd,dc=hoperun,dc=com
changetype: add
objectclass: top
objectclass: organizationalUnit
ou: Servers组织Servers内加入人员test1
dn: cn=test1,ou=Servers,dc=rd,dc=hoperun,dc=com
changetype: add
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: test1
sn: test1
ou: Servers
description: beautiful
uid: test1

通过这个例子可以对LDIF进一步理解到可以是多段信息的结合,而在实际的项目中,对LDAP数据在不是很复杂的情况下,使用LIDF进行备份和恢复也是常用的方式。

ldapmodify:

[root@localhost ldap]# cat adduser.ldif
dn: cn=test,ou=Users,dc=rd,dc=hoperun,dc=com
cn: test
displayName: test
mail: test@hoperun.com
sn: test
uid: test
title: jettech
objectClass: inetOrgPerson
objectClass: top
userPassword: 123456aA[root@localhost ldap]# ldapmodify -a -x -D "cn=admin,dc=rd,dc=hoperun,dc=com" -w 123456aA -f adduser.ldif
adding new entry "cn=test,ou=Users,dc=rd,dc=hoperun,dc=com"[root@localhost ldap]# ldapsearch -x -D cn=admin,dc=rd,dc=hoperun,dc=com -w 123456aA -b "ou=Users,dc=rd,dc=hoperun,dc=com" cn=test
# extended LDIF
#
# LDAPv3
# base <ou=Users,dc=rd,dc=hoperun,dc=com> with scope subtree
# filter: cn=test
# requesting: ALL
## test, Users, rd.hoperun.com
dn: cn=test,ou=Users,dc=rd,dc=hoperun,dc=com
cn: test
displayName: test
mail: test@hoperun.com
sn: test
uid: test
title: jettech
objectClass: inetOrgPerson
objectClass: top
userPassword:: MTIzNDU2YUE=# search result
search: 2
result: 0 Success# numResponses: 2
# numEntries: 1

修改title:注意修改说明都可以.我这里只是修改了title

cn: test
displayName: test
mail: test@hoperun.com
uid: test
objectClass: inetOrgPerson
objectClass: top
userPassword:: MTIzNDU2YUE=
title: test
sn: test

[root@localhost ldap]# cat modifyuser.ldif
dn: cn=test,ou=Users,dc=rd,dc=hoperun,dc=com
changetype: modify
replace: title
title: wubo[root@localhost ldap]# ldapmodify -a -x -D "cn=admin,dc=rd,dc=hoperun,dc=com" -w 123456aA -f modifyuser.ldif
modifying entry "cn=test,ou=Users,dc=rd,dc=hoperun,dc=com"[root@localhost ldap]# ldapsearch -x -D cn=admin,dc=rd,dc=hoperun,dc=com -w 123456aA -b "ou=Users,dc=rd,dc=hoperun,dc=com" cn=test
# extended LDIF
#
# LDAPv3
# base <ou=Users,dc=rd,dc=hoperun,dc=com> with scope subtree
# filter: cn=test
# requesting: ALL
## test, Users, rd.hoperun.com
dn: cn=test,ou=Users,dc=rd,dc=hoperun,dc=com
cn: test
displayName: test
mail: test@hoperun.com
sn: test
uid: test
objectClass: inetOrgPerson
objectClass: top
userPassword:: MTIzNDU2YUE=
title: wubo# search result
search: 2
result: 0 Success# numResponses: 2
# numEntries: 1

添加字段:

[root@localhost ldap]# cat addmodifyuser.ldif
dn: cn=test,ou=Users,dc=rd,dc=hoperun,dc=com
changetype: modify
add: description
description: beijing description[root@localhost ldap]# ldapmodify -a -x -D "cn=admin,dc=rd,dc=hoperun,dc=com" -w 123456aA -f addusermodify.ldif

将test移动到ou=组中去

LDAP基础:7:使用ldapmodify和ldapdelete进行修改或删除_淼叔的博客-CSDN博客_ldapmodify

导入导出

1.导出

一:导出数据
[root@localhost ldap]# slapcat -v -l back.ldif

2. 过滤ldif文件中多余部分

cat >slapcat.regex <<EOF
/^creatorsName: /d
/^createTimestamp: /d
/^modifiersName: /d
/^modifyTimestamp: /d
/^structuralObjectClass: /d
/^entryUUID: /d
/^entryCSN: /d
EOF[root@localhost ldap]# cat back.ldif | sed -f slapcat.regex > back1.ldif

3:导入数据

ldapadd -H ldap://127.0.0.1 -x -D "用户" -f back1.idlf -w 密码

4:查看结果
ldapsearch -H ldap://127.0.0.1 -x -b "cn=admin,dc=rd,dc=hoperun,dc=com"

5:总结
注意过滤掉的ldif文件当中,可能还存在有多余部分,可能会导致导入失败,如果导入失败,请仔细查看文件中是否有多余部分,另外,导入的ldap数据库所拥有的目录结构必须与文件中的目录结构能够吻合,否则会出现no such object的错误。

其他方案:

  [方法1]

  关闭:kill -9 `cat /var/run/slapd.pid`
  启动:/usr/sbin/slapd
  备份:/usr/sbin/slapcat>mail_ldap.ldif
  导入:ldapadd -x -D "cn=admin,dc=rd,dc=hoperun,dc=com" -w xxxx -v -f mail_ldap.ldif
  关闭模式导入:
  slapadd -l mail_ldap.ldif -f /etc/openldap/sladp.conf

  [方法2]

  系统突然掉电或重启引起LDAP数据库意外关闭造成的。

  进入ldap数据目录(/openldap/var/openldap-data),执行db_recover,再启动服务.

  /var/lib/ldap slapd db_recover

 [方法3]

ldapsearch -x -b 'cn=admin,dc=rd,dc=hoperun,dc=com' -w xxxx > ldapbackup.ldif

使用ldapadd,ldapmodify,slapcat 进行数据增加,备份,导入导出数据ldapsearch获取中文组织结构为加密过的字符串相关推荐

  1. oracle导出数据视频教程,Oracle导入导出数据的几种方式

    oracle导入导出数据 1.导出dmp格式文件 --备份某几张表 !!!! exp smsc/smsc file=/data/oracle_bak/dmp/bakup0209_2.dmp table ...

  2. mysql导出数据代码_MySQL导入导出数据下令

    mysql导入导出数据命令 MySQL导出导入数据命令 博客分类: MySQL MySQL数据结构SQLDOS脚本. 1.导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导 ...

  3. hive向mysql导数据_Mysql Hive 导入导出数据

    ---王燕行转列sql select split(concat_ws(',',collect_set(cast(smzq as string))),',')[1] ,split(concat_ws(' ...

  4. mysql批量导入 导出数据_MySQL批量导入导出数据

    批量向mysql插入(文本)数据的方法有以下3种: 方法1. 可以先将要插入的数据统一保存在 .sql 文件中,各个insert 语句直接用分号分开.之后执行命令: source .sql 文件即可. ...

  5. PLSQL_数据泵Datapump导入导出数据IMPDP / EXPDP(概念)(Oracle数据导入导出工具)(转)...

    一.摘要 在平常备库和数据库迁移的时候,当遇到大的数据库的时候在用exp的时候往往是需要好几个小时,耗费大量时间.oracle10g以后可以用expdp来导出数据库花费的时间要远小于exp花费的时间, ...

  6. Postman 实现备份数据 Postman恢复数据 postman 导出导入数据 postman 导入导出数据

    Postman 实现备份数据 Postman恢复数据 postman 导出导入数据 postman 导入导出数据 一.需求描述 在使用postman调试接口时,若遇到内网的环境,无法通过账户同步数据: ...

  7. mysql数据库导出后乱码问题_MySQL导入导出数据出现乱码的解决办法

    在mysql导入导出数据时经常出现中文乱码的问题,大多是因类导入导出时编码设置不一致所引起的.本文介绍了不同平台下的编码转换方法,供大家参考. 在linux系统中默认的是utf8编码,而windows ...

  8. 如何在 MySQL / MariaDB 中导入导出数据,导入导出数据库文件、Excel、CSV

    文章目录 本教程将详细讲解 1. MySQL / MariaDB 数据库数据「导出」 2. MySQL / MariaDB 数据库数据「导入」 3. 使用「卡拉云」一键导入导出 MySQL / Mar ...

  9. 如何将mysql导出数据泵_Oracle数据库之ORACLE 数据泵导入导出数据

    本文主要向大家介绍了Oracle数据库之ORACLE 数据泵导入导出数据,通过具体的内容向大家展现,希望对大家学习Oracle数据库有所帮助. 一.摘要 在平常备库和数据库迁移的时候,当遇到大的数据库 ...

最新文章

  1. Boost源码剖析之:容器赋值-assign
  2. 安装 centos7
  3. 柴油发电机组常见故障及处理方法
  4. abap 调用外部web service 使用小结
  5. mysql复制文件迁移后看不到表_mysql 直接拷贝data 目录下文件 进行数据库迁移时遇到的一些问题??...
  6. 构建之法现代软件概述
  7. java web scala_spring boot+scala编写web接口
  8. 搭建redis主从结构
  9. 24岁大专非科班转行前端开发可行性有多少?
  10. 学院教务管理系统oracle设计,浙工院教学教务管理信息系统的设计与实现
  11. 设计模式之构造函数模式
  12. oracle10g_database安装教程,Oracle Database 10g数据库安装及配置教程
  13. ACL2021 | 任务型和开放域对话系统
  14. 京东、腾讯历经最难Q1
  15. Linux数据恢复的研究
  16. 【Android】自定义控件实现自动补齐邮箱后缀的输入框
  17. lenb和len的区别
  18. java 大臣的旅费_蓝桥杯 大臣的旅费(Java dfs)
  19. 推荐一个在线ide的网站
  20. 墨言教育:黄鹤楼1800年历史主题海报邀请展:传递历史文化积淀和新时代风采

热门文章

  1. Linux设置Tomcat开机自启动
  2. 对Lua中Userdata的理解
  3. 烽火HG680-MY/MC-通用-晨星MSO9385芯片_安卓9.0-当贝桌面卡刷固件包
  4. 初学ROS(VMware Ubuntu18.04)问题解决篇(一)
  5. PxlIpaFactory 转换pxl成为ipa
  6. 索引 Indexes
  7. 服务器运维 考什么证书,腾讯云运维工程师认证(TCA)考试费用、考试内容、证书有效期...
  8. Matlab app designer界面(一)
  9. 【java基础】-谈谈对面向对象理解
  10. 电压转电流,4-20mA输出电路