]> git.sur5r.net Git - openldap/blob - doc/guide/admin/dbtools.sdf
3cd63893ee383b3b054a4d2c3dce984e361ec7a5
[openldap] / doc / guide / admin / dbtools.sdf
1 # $OpenLDAP$
2 # Copyright 1999-2000, The OpenLDAP Foundation, All Rights Reserved.
3 # COPYING RESTRICTIONS APPLY, see COPYRIGHT.
4
5 H1: Database Creation and Maintenance Tools
6
7 This section tells you how to create a slapd database from
8 scratch, and how to do trouble shooting if you run into
9 problems. There are two ways to create a database. First,
10 you can create the database on-line using LDAP. With this
11 method, you simply start up slapd and add entries using the
12 LDAP client of your choice. This method is fine for relatively
13 small databases (a few hundred or thousand entries,
14 depending on your requirements).  This method works for database
15 types which support updates.
16
17 The second method of database creation is to do it off-line
18 using special utilities provided with slapd. This method is
19 best if you have many thousands of entries to create, which
20 would take an unacceptably long time using the LDAP method,
21 or if you want to ensure the database is not accessed while
22 it is being created.  Note that not all database types support
23 these utilitites.
24
25
26 H2: Creating a database over LDAP
27
28 With this method, you use the LDAP client of your choice
29 (e.g., the ldapadd(1)) to add entries, just like you would
30 once the database is created. You should be sure to set the
31 following configuration options before starting slapd:
32
33 E:      suffix <dn>
34
35 As described in the preceding section, this option says what
36 entries are to be held by this database. You should set this
37 to the DN of the root of the subtree you are trying to create.
38 For example
39
40 E:      suffix "dc=example, dc=com"
41
42 You should be sure to specify a directory where the index
43 files should be created:
44
45 E:      directory <directory>
46
47 For example:
48
49 E:      directory /usr/local/var/openldap-ldbm
50
51 You need to create this directory with appropriate permissions
52 such that slapd can write to it.
53
54 You need to make it so you can connect to slapd as directory user
55 with permission to add entries.  You can configure the directory
56 to support a special {{super-user}} or {{root}} user just for
57 this purpose.   This is done through the following two options
58 in the database definition:
59
60 E:      rootdn <dn>
61 E:      rootpw <passwd>
62
63 For example:
64
65 E:      rootdn "cn=Manager, dc=example, dc=com"
66 E:      rootpw secret
67
68 These options specify a DN and password that can be used
69 to authenticate as the {{super-user}} entry of the database (i.e.,
70 the entry allowed to do anything).  The DN and password
71 specified here will always work, regardless of whether the
72 entry named actually exists or has the password given. This
73 solves the chicken-and-egg problem of how to authenticate
74 and add entries before any entries yet exist.
75
76 Finally, you should make sure that the database definition
77 contains the index definitions you want:
78
79 E:      index {<attrlist> | default} [pres,eq,approx,sub,none]
80
81 For example, to index the cn, sn, uid and objectclass
82 attributes the following index configuration lines could be
83 used.
84
85 E:      index cn,sn,uid
86 E:      index objectclass pres,eq
87
88 See Section 4 on the configuration file for more details on
89 this option. Once you have configured things to your liking,
90 start up slapd, connect with your LDAP client, and start
91 adding entries. For example, to add a the organizational entry
92 followed by a Postmaster entry using the {{I:ldapadd}} tool, you
93 could create an {{TERM:LDIF}} file called {{EX:entries.ldif}} with the
94 contents:
95
96 E: dc=example, dc=com
97 E: objectClass=dcObject
98 E: objectClass=organization
99 E: dc=example
100 E: o=Example Corporation
101 E: description=The Example Corporation
102 E:
103 E: cn=Postmaster, dc=example, dc=com
104 E: objectClass=organizationalRole
105 E: cn=Postmaster
106 E: description=OpenLDAP Postmaster <Postmaster@example.com>
107
108 and then use a command like this to actually create the
109 entry:
110
111 E: ldapadd -f entries.ldif -x -D "cn=Manager, dc=example, dc=com" -w secret
112
113 The above command assumes settings provided in the above
114 examples.
115
116
117 H2: Creating a database off-line
118
119 The second method of database creation is to do it off-line,
120 using the slapd database tools described below. This method is
121 best if you have many thousands of entries to create, which
122 would take an unacceptably long time using
123 the LDAP method described above. These tools read the
124 slapd configuration file and an input file containing a text
125 representation of the entries to add.  For database types which
126 support the tools, they produce the database files directly (otherwise
127 you must use the on-line method above). There are several important
128 configuration options you will want to be sure and set in the config
129 file database definition first:
130
131 E:      suffix <dn>
132
133 As described in the preceding section, this option says what
134 entries are to be held by this database. You should set this
135 to the DN of the root of the subtree you are trying to create.
136 For example
137
138 E:      suffix "dc=example, dc=com"
139
140 You should be sure to specify a directory where the index
141 files should be created:
142
143 E:      directory <directory>
144
145 For example:
146
147 E:      directory /usr/local/var/openldap-ldbm
148
149 Finally, you need to specify which indexes you want to build.
150 This is done by one or more index options.
151
152 E:      index {<attrlist> | default} [pres,eq,approx,sub,none]
153
154 For example:
155
156 E:      index cn,sn,uid pres,eq,approx
157 E:      index objectClass eq
158
159 This would create presence, equality and approximate
160 indexes for the cn, sn, and uid attributes and an equality
161 index for the objectClass attribute.  See the configuration
162 file section for more information on this option.
163
164 H3: The {{EX: slapadd}} program
165
166 Once you've configured things to your liking, you create the
167 primary database and associated indexes by running the
168 {{slapadd}}(8) program:
169
170 E:      slapadd -l <inputfile> -f <slapdconfigfile>
171 E:              [-d <debuglevel>] [-n <integer>|-b <suffix>]
172
173 The arguments have the following meanings:
174
175 E:      -l <inputfile>
176
177 Specifies the LDIF input file containing the entries to add in
178 text form (described below in Section 8.3).
179
180 E:      -f <slapdconfigfile>
181
182 Specifies the slapd configuration file that tells where to
183 create the indexes, what indexes to create, etc.
184
185 E:      -d <debuglevel>
186
187 Turn on debugging, as specified by {{EX: <debuglevel>}}. The
188 debug levels are the same as for slapd (see Section 6.1).
189
190 E:      -n <databasenumber>
191
192 An optional argument that specifies the configuration file
193 database for which to build. The first database listed
194 is "1", the second "2", etc. By default, the first ldbm database
195 in the configuration file is used.  Should not be used in
196 conjunction with {{EX:-b}}.
197
198 E: -b <suffix>
199
200 An optional argument that specifies the configuration file
201 database for which to build.  The provided suffix is matched
202 against database {{EX:suffix}} to determine the database
203 number.  Should not be used in conjunction with {{EX:-n}}.
204
205
206 H3: The {{EX: ldif2index}} program
207
208 Sometimes it may be necessary to regenerate indices (such
209 as after modifying {{slapd.conf}}(5)).  This is possible using
210 the {{slapindex}}(8) program. {{EX: slapindex}} is invoked
211 like this
212
213 E:      slapindex -f <slapdconfigfile>
214 E:              [-d <debuglevel>] [-n <databasenumber>|-b <suffix>]
215
216 Where the -f, -d, -n and -b options are the same as for the
217 {{slapadd}}(1) program.  slapindex rebuilds all indices based
218 upon the current database contents.
219
220
221 H3: The {{EX: slapcat}} program
222
223 The {{EX: slapcat}} program is dump the database to a {{TERM:LDIF}}
224 file.  This can be useful when you want to make a human-readable
225 backup of your database or for editing your database off-line.
226 The program is invoked like this:
227
228 E:      slapcat -l <filename> -f <slapdconfigfile>
229 E:              [-d <debuglevel>] [-n <databasenumber>|-b <suffix>]
230
231 where -n or -b is used to select the database in the slapd.conf(5)
232 specified using -f.  The corresponding LDIF output is written to
233 standard output or to the file specified using the -l option.
234
235
236 H3: The {{EX: ldif}} program
237
238 The ldif program is used to convert arbitrary data values to
239 LDIF format. This can be useful when writing a program or
240 script to create the LDIF file you will feed into the ldif2ldbm
241 program, or when writing a SHELL backend. ldif takes an
242 attribute name as an argument, and reads the attribute
243 value(s) from standard input. It produces the LDIF formatted
244 attribute line(s) on standard output. The usage is:
245
246 E:      ldif [-b] <attrname>
247
248 where {{EX: <attrname>}} is the name of the attribute. Without the
249 -b option, ldif considers each line of standard input to be a
250 separate value of the attribute.
251
252 The -b option can be used to force ldif to interpret its input
253 as a single raw binary value. This option is useful when
254 converting binary data such as a {{EX: jpegPhoto}} or {{EX: audio}}
255 attribute.
256
257
258 H2: The LDIF text entry format
259
260 The LDAP Data Interchange Format (LDIF) is used to
261 represent LDAP entries in a simple text format. The basic
262 form of an entry is:
263
264 E:      [<id>]
265 E:      dn: <distinguished name>
266 E:      <attrtype>: <attrvalue>
267 E:      <attrtype>: <attrvalue>
268 E:
269 E:      ...
270
271 where {{EX: <id>}} is the optional entry ID (a positive decimal
272 number). Normally, you would not supply the {{EX: <id>}}, allowing
273 the database creation tools to do that for you. The ldbmcat
274 program, however, produces an LDIF format that includes
275 {{EX: <id>}} so that new indexes created will be consistent.
276
277 A line may be continued by starting the next line with a
278 single space or tab character. e.g.,
279
280 E:      dn: cn=Barbara J Jensen, dc=example, dc=com
281
282 Multiple attribute values are specified on separate lines. e.g.,
283
284 E:      cn: Barbara J Jensen
285 E:      cn: Babs Jensen
286
287 If an {{EX: <attrvalue>}} contains a non-printing character, or
288 begins with a space or a colon `:', the {{EX: <attrtype>}} is followed
289 by a double colon and the value is encoded in base 64
290 notation. e.g., the value " begins with a space" would be
291 encoded like this:
292
293 E:      cn:: IGJlZ2lucyB3aXRoIGEgc3BhY2U=
294
295 Multiple entries within the same LDIF file are separated by
296 blank lines. Here's an example of an LDIF file containing
297 three entries.
298
299 E:      dn: cn=Barbara J Jensen, dc=example, dc=com
300 E:      cn: Barbara J Jensen
301 E:      cn: Babs Jensen
302 E:      objectclass: person
303 E:      sn: Jensen
304 E:
305 E:      dn: cn=Bjorn J Jensen, dc=example, dc=com
306 E:      cn: Bjorn J Jensen
307 E:      cn: Bjorn Jensen
308 E:      objectclass: person
309 E:      sn: Jensen
310 E:
311 E:      dn: cn=Jennifer J Jensen, dc=example, dc=com
312 E:      cn: Jennifer J Jensen
313 E:      cn: Jennifer Jensen
314 E:      objectclass: person
315 E:      sn: Jensen
316 E:      jpegPhoto:: /9j/4AAQSkZJRgABAAAAAQABAAD/2wBDABALD
317 E:      A4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQ
318 E:      ERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVG
319 E:      
320 E:      ...
321
322 Notice that the {{EX: jpegPhoto}} in Jennifer Jensen's entry is
323 encoded using base 64. The {{EX: ldif}} program (described in
324 Section 8.2.6) can be used to produce the LDIF format.
325
326 Note: Trailing spaces are not trimmed from values in an
327 LDIF file. Nor are multiple internal spaces compressed. If
328 you don't want them in your data, don't put them there.
329