导入数据-by ldif文件
创建一个base.ldif文件,里面 包含用户数据,然后将其导入到ldap中
[root@localhost tmp]# cat /tmp/base.ldif
dn: dc=website80,dc=com
dc: website80
objectClass: top
objectClass: domain
dn: ou=People,dc=website80,dc=com
ou: People
objectClass: top
objectClass: organizationalUnit
dn: ou=Group,dc=website80,dc=com
ou: Group
objectClass: top
objectClass: organizationalUnit
dn: uid=user1,ou=People,dc=website80,dc=com
uid: oladmin
cn: oladmin
sn: oladmin
mail: [email protected]
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: top
objectClass: posixAccount
userPassword: passw0rd
uidNumber: 501
gidNumber: 501
homeDirectory: /home/oladmin
[root@localhost ldap]# ldapadd -H ldap://127.0.0.1 -x -D "cn=Manager,dc=website80,dc=com" -f /tmp/base.ldif -w secret
adding new entry "dc=website80,dc=com"
adding new entry "ou=People,dc=website80,dc=com"
adding new entry "ou=Group,dc=website80,dc=com"
adding new entry "uid=user1,ou=People,dc=website80,dc=com"
查看用户的信息,如下所示:
[root@localhost ldap]# ldapsearch -x -b "uid=user1,ou=People,dc=website80,dc=com"
# extended LDIF
#
# LDAPv3
# base <uid=user1,ou=People,dc=website80,dc=com> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
# user1, People, website80.com
dn: uid=user1,ou=People,dc=website80,dc=com
uid: oladmin
uid: user1
cn: oladmin
sn: oladmin
mail: [email protected]
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: top
objectClass: posixAccount
userPassword:: cGFzc3cwcmQ=
uidNumber: 501
gidNumber: 501
homeDirectory: /home/oladmin
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
用户的密码是明文存储的,做了基本的base64编码
数据库备份和恢复
执行命令备份数据库:
slapcat -v -l ldapbackup.ldif
创建正则过滤掉系统信息
cat slapcat.regex
/^creatorsName: /d
/^createTimestamp: /d
/^modifiersName: /d
/^modifyTimestamp: /d
/^structuralObjectClass: /d
/^entryUUID: /d
/^contextCSN: /d
/^entryCSN: /d
过滤掉备份数据库中系统信息
cat ldapback.ldif | sed -f slapcat.regex > slapdata.ldif
导入数据库
ldapadd -H ldap://127.0.0.1 -x -D "cn=Manager,dc=domain,dc=com" -f slapdata.ldif -w secret