]> git.sur5r.net Git - openldap/blob - doc/guide/admin/dbtools.sdf
5d3cb4c3ba01011a7c91f70b2cf68ba01180ffbe
[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 options in the configuration file before starting slapd:
32
33 >       suffix <dn>
34
35 As described in the {{SECT:General Database Directives}} section,
36 this option defines which entries are to be held by this database.
37 You should set this to the DN of the root of the subtree you
38 are trying to create.  For example:
39
40 >       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 >       directory <directory>
46
47 For example:
48
49 >       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 configure slapd so that you can connect to it as a directory
55 user 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 >       rootdn <dn>
61 >       rootpw <passwd>
62
63 For example:
64
65 >       rootdn "cn=Manager, dc=example, dc=com"
66 >       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 >       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 >       index cn,sn,uid
86 >       index objectClass pres,eq
87
88 See {{SECT:The slapd Configuration File}} section 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 >       dc=example, dc=com
97 >       objectClass=dcObject
98 >       objectClass=organization
99 >       dc=example
100 >       o=Example Corporation
101 >       description=The Example Corporation
102 >
103 >       cn=Postmaster, dc=example, dc=com
104 >       objectClass=organizationalRole
105 >       cn=Postmaster
106 >       description=OpenLDAP Postmaster <Postmaster@example.com>
107
108 and then use a command like this to actually create the
109 entry:
110
111 >       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 to add 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 >       suffix <dn>
132
133 As described in the {{SECT:General Database Directives}} section,
134 this option defines which entries are to be held by this database.
135 You should set this to the DN of the root of the subtree you are
136 trying to create.  For example:
137
138 >       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 >       directory <directory>
144
145 For example:
146
147 >       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 >       index {<attrlist> | default} [pres,eq,approx,sub,none]
153
154 For example:
155
156 >       index cn,sn,uid pres,eq,approx
157 >       index objectClass eq
158
159 This would create presence, equality and approximate
160 indexes for the {{EX:cn}}, {{EX:sn}}, and {{EX:uid}} attributes
161 and an equality index for the {{EX:objectClass}} attribute. See
162 the configuration 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 >       slapadd -l <inputfile> -f <slapdconfigfile>
171 >               [-d <debuglevel>] [-n <integer>|-b <suffix>]
172
173 The arguments have the following meanings:
174
175 >       -l <inputfile>
176
177 Specifies the LDIF input file containing the entries to add in
178 text form (described below in the {{SECT:The LDIF text entry format}}
179 section).
180
181 >       -f <slapdconfigfile>
182
183 Specifies the slapd configuration file that tells where to
184 create the indexes, what indexes to create, etc.
185
186 >       -d <debuglevel>
187
188 Turn on debugging, as specified by {{EX:<debuglevel>}}. The
189 debug levels are the same as for slapd.  See
190 the {{SECT:Command-Line Options}} section in {{SECT:Running slapd}}.
191
192 >       -n <databasenumber>
193
194 An optional argument that specifies which database to modify.
195 The first database listed in the configuration file
196 is "1", the second "2", etc. By default, the first ldbm database
197 in the configuration file is used. Should not be used in
198 conjunction with {{EX:-b}}.
199
200 >       -b <suffix>
201
202 An optional argument that specifies which database to modify.
203 The provided suffix is matched against a database {{EX:suffix}}
204 directive to determine the database number. Should not be
205 used in conjunction with {{EX:-n}}.
206
207
208 H3: The {{EX:slapindex}} program
209
210 Sometimes it may be necessary to regenerate indices (such
211 as after modifying {{slapd.conf}}(5)). This is possible using
212 the {{slapindex}}(8) program.  {{slapindex}} is invoked
213 like this
214
215 >       slapindex -f <slapdconfigfile>
216 >               [-d <debuglevel>] [-n <databasenumber>|-b <suffix>]
217
218 Where the -f, -d, -n and -b options are the same as for the
219 {{slapadd}}(1) program. slapindex rebuilds all indices based
220 upon the current database contents.
221
222
223 H3: The {{EX:slapcat}} program
224
225 The {{EX:slapcat}} program is used to dump the database to an {{TERM:LDIF}}
226 file. This can be useful when you want to make a human-readable
227 backup of your database or when you want to edit your database off-line.
228 The program is invoked like this:
229
230 >       slapcat -l <filename> -f <slapdconfigfile>
231 >               [-d <debuglevel>] [-n <databasenumber>|-b <suffix>]
232
233 where -n or -b is used to select the database in the {{slapd.conf}}(5)
234 specified using -f. The corresponding LDIF output is written to
235 standard output or to the file specified using the -l option.
236
237
238 !if 0
239 H3: The {{EX:ldif}} program
240
241 The {{ldif}}(1) program is used to convert arbitrary data values to
242 {{TERM:LDIF}} format. This can be useful when writing a program or
243 script to create the LDIF file you will feed into the {{slapadd}}(8)
244 or {{ldapadd}}(1) program, or when writing a SHELL backend. {{ldif}}(1)
245 takes an attribute description as an argument and reads the attribute
246 value(s) from standard input. It produces the LDIF formatted
247 attribute line(s) on standard output. The usage is:
248
249 >       ldif [-b] <attrdesc>
250
251 where {{EX:<attrdesc>}} is an attribute description. Without the -b
252 option, ldif considers each line of standard input to be a separate
253 value of the attribute.
254
255 >       ldif description << EOF
256 >        leading space
257 >       # leading hash mark
258 >       EOF
259
260 The {{EX:-b}} option can be used to force ldif to interpret its input
261 as a single raw binary value. This option is useful when
262 converting binary data such as a {{EX:jpegPhoto}} or {{EX:audio}}
263 attribute.  For example:
264
265 >       ldif -b jpegPhoto < photo.jpeg
266 !endif
267
268
269 H2: The LDIF text entry format
270
271 The {{TERM[expand]LDIF}} (LDIF) is used to represent LDAP
272 entries in a simple text format.  This section provides a brief
273 description of the LDIF entry format which complements {{ldif}}(5)
274 and the technical specification {{REF:RFC2849}}.
275
276 The basic form of an entry is:
277
278 >       # comment
279 >       dn: <distinguished name>
280 >       <attrdesc>: <attrvalue>
281 >       <attrdesc>: <attrvalue>
282 >
283 >       ...
284
285 Lines starting with a '{{EX:#}}' character are
286 comments.  An attribute description may be a simple attribute
287 type like {{EX:cn}} or {{EX:objectClass}} or {{EX:1.2.3}} (an {{TERM:OID}}
288 associated with an attribute type) or may include options such
289 as {{EX:cn;lang_en_US}} or {{EX:userCertificate;binary}}.
290
291 A line may be continued by starting the next line with a
292 {{single}} space or tab character.  For example:
293
294 >       dn: cn=Barbara J Jensen, dc=example, dc=
295 >        com
296 >       cn: Barbara J
297 >         Jensen
298
299 is equivalent to:
300
301 >       dn: cn=Barbara J Jensen, dc=example, dc=com
302 >       cn: Barbara J Jensen
303
304 Multiple attribute values are specified on separate lines. e.g.,
305
306 >       cn: Barbara J Jensen
307 >       cn: Babs Jensen
308
309 If an {{EX:<attrvalue>}} contains non-printing characters or begins
310 with a space, a colon ('{{EX::}}'), or a less than ('{{EX:<}}'),
311 the {{EX:<attrdesc>}} is followed by a double colon and the base64
312 encoding of the value.
313 For example, the value "{{EX: begins with a space}}" would be
314 encoded like this:
315
316 >       cn:: IGJlZ2lucyB3aXRoIGEgc3BhY2U=
317
318 You can also specify a {{TERM:URL}} containing the attribute value.
319 For example, the following specifies the {{EX:jpegPhoto}} value
320 should be obtained from the file {{F:/path/to/file.jpeg}}.
321
322 >       cn:< file://path/to/file.jpeg
323
324 Multiple entries within the same LDIF file are separated by
325 blank lines. Here's an example of an LDIF file containing
326 three entries.
327
328 >       # First Entry
329 >       dn: cn=Barbara J Jensen, dc=example, dc=com
330 >       cn: Barbara J Jensen
331 >       cn: Babs Jensen
332 >       objectClass: person
333 >       sn: Jensen
334 >
335 >       # Second Entry
336 >       dn: cn=Bjorn J Jensen, dc=example, dc=com
337 >       cn: Bjorn J Jensen
338 >       cn: Bjorn Jensen
339 >       objectClass: person
340 >       sn: Jensen
341 >       # Base64 encoded JPEG photo
342 >       jpegPhoto:: /9j/4AAQSkZJRgABAAAAAQABAAD/2wBDABALD
343 >       A4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQ
344 >       ERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVG
345 >
346 >       # Third Entry
347 >       dn: cn=Jennifer J Jensen, dc=example, dc=com
348 >       cn: Jennifer J Jensen
349 >       cn: Jennifer Jensen
350 >       objectClass: person
351 >       sn: Jensen
352 >       # JPEG photo from file
353 >       jpegPhoto:< file://path/to/file.jpeg
354
355 Notice that the {{EX:jpegPhoto}} in Bjorn's entry is base 64 encoded
356 and the {{EX:jpegPhoto}} in Jennifer's entry is obtained from the
357 location indicated by the URL.
358
359 Note: Trailing spaces are not trimmed from values in an
360 LDIF file. Nor are multiple internal spaces compressed. If
361 you don't want them in your data, don't put them there.
362