You can use the LDAP Data Interchange Format (LDIF) to import and export database entries into and out of the directory server. You can also back up your databases by exporting to an LDIF file. These topics are described in:
For a description of LDIF, see Chapter 2, "LDAP Data Interchange Format."
Exporting Databases to LDIF
Exporting your database to LDIF can be useful if you want to back up your database, copy your database to another directory server, export your database to another application, or add an index setting for a currently existing attribute. You can export your database to LDIF either by using the Directory Server Console, or by using the slapd (Windows NT) or ns-slapd (Unix) command-line utility. This section describes both these methods in the following sections:
Exporting to LDIF Using the Server Console
To export your database to LDIF from the Directory Server Console:
On the Directory Server Console select the Configuration tab.
From the Console menu select Export.
The Export Database dialog box displays.
If you are running the Directory Server Console on the server's host machine, skip to Step 4. Otherwise, if you want to export to a file on the local machine, select "Local machine". To export to a file on the server's host, select "Server machine."
Enter the full path and filename you want the server to use to store the LDIF file in the text box provided.
Netscape recommends that you use the
<NSHOME>/slapd-<serverID>/ldif directory on the server's host
machine to store LDIF files.
If you want to export the whole directory, select the "Entire database" radio button. If you want to export only a single suffix or a particular subtree, select the Subtree radio button and then enter the suffix or subtree you want to export in the Subtree text box. You can also click Browse to select a suffix or subtree.
Click OK.
Exporting to LDIF From the Command Line
You can export your database to LDIF using the slapd (Windows NT) or ns-slapd (Unix) command-line utility with the db2ldif keyword. For information on where you can find the command line utilities, see "Finding the Command-Line Utilities".
Use one of the following syntaxes to export your database to LDIF from the command-line. Parameters in brackets [ ] are optional.
On Windows NT:
slapd db2ldif -f <slapd.conf> -a <output_file> [-d <debug_level> -n -r -s <include_suffix> -x <exclude_suffix>]
On Unix:
ns-slapd db2ldif -f <slapd.conf> -a <output_file> [-d <debug_level> -n -r -s <include_suffix> -x <exclude_suffix>]
where <slapd.conf> is the location of your configuration file. The slapd.conf file is under <NSHOME>/slapd-<serverID>/config. Enter the full path to the slapd.conf file you want to use.
ns-slapd and slapd Parameters for Exporting Databases
-a. Defines the output file in which the server saves the exported LDIF. This file
is stored by default in the directory where the command-line utility resides.
-d. (Optional) Specifies the debug level to use during the db2ldif runtime.
Debug levels are defined in "Log Level".
-f. Specifies the slapd.conf configuration file to use for the conversion
process. Use the full path to the slapd.conf file with this argument. For
information on where to find directory server configuration files, see "Directory
Server Configuration Files".
-n. (Optional) Specifies that entry IDs are not to be included in the LDIF
output. The entry IDs are necessary only if the db2ldif output is to be used
as input to db2index.
-r.
(Optional) If you intend to import the LDIF file into a consumer server, you must specify this argument. -r causes the server to include the copiedFrom attribute and its contents in the LDIF output. The replication process requires this information. If you use -r, you also need to specify the suffix you want exported using the -s option. You must shut down the server before exporting using this option.
-s.
(Optional) Specifies the suffix or suffixes to include in the export. You may use multiple -s arguments. This parameter is optional. If you do not specify -s or -x, the server exports all suffixes within the database. If you use both -x and -s arguments with the same suffix, the -x operation takes precedence. Exclusion always takes precedence over inclusion. If you exclude one or more suffixes from the exported LDIF file, and you intend to import the LDIF file into your configuration directory, do not exclude o=NetscapeRoot. Also, if you use -s to specify a suffix to include, and you intend to import the LDIF file into your configuration directory, make sure that you also use -s to include o=NetscapeRoot.
-x.
(Optional) Specifies a suffix or suffixes to exclude in the export. You may use multiple -x arguments. This parameter is optional. If you do not specify -s or -x, the server exports all suffixes within the database. If you use both -x and -s arguments with the same suffix, the -x operation takes precedence. Exclusion always takes precedence over inclusion. If you intend to import the LDIF file into your configuration directory, do not exclude o=NetscapeRoot.
Database to LDIF Examples
Windows NT:
slapd db2ldif -f c:\Netscape\Server4\slapd-dirserver\config\slapd.conf -a output.ldif -s "o=airius.com" -s "o=NetscapeRoot"
Unix:
ns-slapd db2ldif -f /usr/Netscape/Server4/slapd-dirserver/config/slapd.conf -a output.ldif -s o=airius.com -s "o=NetscapeRoot"
Importing Databases From LDIF
You can import LDIF files into your database from the Directory Server Console or by using the slapd (Windows NT) or ns-slapd (Unix) command-line utility with the ldif2db keyword. This section describes both these methods. You can also import LDIF files using the ldif2db script.
When you import an LDIF file using the ldif2db script or by specifying the "Overwrite Entire Database" option (with "Preserve Configuration") through the Server Console, a snapshot of o=NetscapeRoot is saved to a file and stored in <NSHOME>/slapd-<serverID>/confbak. If you need to, you can restore the configuration information in the directory by importing the most recent file in this directory. The files are named according to the date on which the import took place as follows:
YYYY_MM_DD_HHMMSS.ldif
For example, if the file was saved at 42 seconds past 10 PM on July 30, 1998, it would be named:
1998_07_30_224244.ldif
In most cases, you will want to add the configuration information to the existing data instead of overwriting your existing data. To do this from the Directory Server Console, when you import the LDIF file, clear the "Overwrite Entire Database" option on the Import dialog box. You can also use ldapmodify as follows:
ldapmodify -D "<BindDN>" -w <BindDN password> -c -a -f <NSHOME>/slapd-<serverID>/confbak/filename.ldif
For example,
ldapmodify -D "cn=directory manager"
-w mypassword -c -a -f /Netscape/Server4/slapd-mydirserver/confbak/1998_07_30_224244.ldif
For better performance, you should use the server console to import an LDIF file only if the LDIF file contains a relatively small number of entries (less than 10,000), or if you are importing and overwriting the existing database. Otherwise, you should use the command line. This section describes:
Importing LDIF From the Server Console
You can use the Directory Server Console to import the LDIF file into a directory server database using the Import command. For best performance, you should use the server console to import an LDIF file only if the LDIF file contains a relatively small number of directory entries (less than 10,000), or if you intend to overwrite the existing database. Otherwise, you should use the command-line. For more information, see "Importing LDIF From the Command Line".
Note. You cannot import an LDIF file that contains a root entry unless you bind to the
directory as the Root DN (Directory Manager). This is because access to the
root entry, for example o=airius.com, is denied to everyone except the
Directory Manager (Root DN).
To import LDIF using the Directory Server Console:
On the Directory Server Console select the Configuration tab.
From the Console menu, select Import. This displays the Import Database dialog box.
If you are running the Directory Server Console on the server's host machine, skip to Step 4. Otherwise, if you want to import a file from the local machine, select "From local machine". If you want to import a file from the server's host, select "From server machine."
Enter the full path to the LDIF file in the field provided.
If you chose to import a file from the local machine, or if you are running
the Directory Server Console on the server's host machine, you can also
click Browse to select the file you want to import.
Select the import method you want the server to use. There are two options:
Overwrite Entire Database. You can only choose this option if you chose
to import a file on the server's host (in Step 3) or if you are running the
Directory Server Console on the server's host machine. When you import
using this option, the server deletes the entire contents of the database and
imports the LDIF file. If you do not want the server to overwrite the
o=NetscapeRoot suffix, select the Preserve Configuration checkbox.
If the directory server is running, you are prompted to shut it down.The
server must be shut down before you can import using this option.
Warning! The Netscape Administration Server uses the o=NetscapeRoot
suffix to store information about installed Netscape Servers. Deleting this
suffix could force you to reinstall all of your Netscape 4.x servers, including
the directory server. Netscape strongly recommends you choose to preserve
this configuration unless directed otherwise by Netscape Technical Support
or other procedures outlined in the directory server documentation.
Append Data to Database. When you import using this option, the server
does not delete the contents of the directory before adding the entries from
the LDIF file. You should only use this option if you are importing an LDIF
file with a relatively small number of entries (less than 10,000). The server
must be running to use this option.
You cannot import an LDIF file that creates a root entry (such as
o=airius.com) using the "Append Data to Database" option unless you
bind to the directory as the root DN, for example, cn=Directory
Manager. Instead, you must use the "Overwrite Entire Database" option.
The optional settings you can specify include:
- Add Only. LDIF file may contain modify and delete instructions in addition to the default add instructions. If you want the server to ignore operations other than add, select the "Add only" checkbox.
- Continue on Error. If you want the server to continue with the import even if errors occur, select the "Continue on error checkbox". You might want to use this option if you are importing an LDIF file that contains some entries that are already in the database in addition to new ones. The server notes existing entries in the rejects file (but otherwise ignores them) while adding all new entries.
- Read / Values From Files. If you want the server to interpret values that begin with a forward slash "/" or a drive letter "C:\" as file names, select the Read / values from files checkbox. If you select this option, the contents of these files, rather than the file names, will be stored in the directory.
- File for Rejects. The server keeps a record of all entries that it cannot import. This might happen, for example, if an entry already exists in the database or if there is no parent object for the entry you are trying to add. If you leave this field blank, the server will not record rejects. By default, the server stores the rejects file in the same directory where the LDIF file you are importing is stored. If you want, you can specify a full path where you want the server to store the file.
Click OK.
The server performs the import and also creates indexes. (For more information on indexes and index creation, refer to Chapter 7, "Managing Indexes.")
Importing LDIF From the Command Line
You can replace the contents of your ldbm database file with an LDIF file using the slapd (Windows NT) or ns-slapd (Unix) command-line utility with the ldif2db keyword. These utilities create the database in the location specified in the "directory" parameter in your slapd.ldbm.conf file and create the index files that are specified in the slapd.ldbm.conf "Attribute to be Indexed" parameter.
For more information, see the "Database" parameter and the "Attribute to be Indexed" parameter in Chapter 17, "Configuration Parameters."
For information on where you can find the command-line utilities in your directory server installation, see "Finding the Command-Line Utilities".
Warning! Importing LDIF files using ns-slapd or slapd deletes your existing database files and creates new ones. The Netscape Administration Server uses the o=NetscapeRoot suffix to store information about installed Netscape Servers. If you are importing the LDIF file into your configuration directory, make sure this suffix and its contents are included in your LDIF file before you import. If you do not, you may have to reinstall (or restore from backup) all of your Netscape 4.x servers, including the directory server.
To import LDIF from the command line:
From the command line, change to <NSHOME>/slapd-<serverID>/db. Where <NSHOME> is the directory where you installed the directory server and <serverID> is the name of your directory server. The directory server database must be stored in this directory.
Make a backup of all the files in the db directory. Although you can delete the files, you may want to move them to a backup location instead, because deleting these files deletes your directory database.
Change to <NSHOME>/bin/slapd/server.
Run the slapd (Windows NT) or ns-slapd (Unix) command-line utility as follows. Parameters in brackets [ ] are optional.
Windows NT:
slapd ldif2db -f <slapd.conf> -C -i <ldif_file>
[-d <debug_level> -n <backend_number> -O
-s <include_suffix> -x <exclude_suffix>]
Unix:
ns-slapd ldif2db -f <slapd.conf> -C -i <ldif_file>
[-d <debug_level> -n <backend_number> -O
-s <include_suffix> -x <exclude_suffix>]
where <ldif_file> is the name of the file containing the LDIF to be
imported and <slapd.conf> is the location of your configuration file.
You can find a demo LDIF file under
<NSHOME>/slapd-<serverID>/ldif. The slapd.conf file is under
<NSHOME>/slapd-<serverID>/config. Enter the full path to the
slapd.conf file you want to use.
slapd Parameters Used for LDIF Imports
The following ldif2db parameters are used to complete an LDIF file import:
-C.
Required. Used internally by the Directory Server.
-d. Optional. Specifies the debug level to use during runtime. Debug levels are
defined in "Log Level".
-f. Specifies the slapd.conf file to use for the import process. This parameter
is required. For information on where to find directory server configuration
files, see "Directory Server Configuration Files".
-i. Specifies the LDIF file to be imported. This parameter is required. You can
use multiple -i arguments to import more than one LDIF file at a time. When
you import multiple files, the server imports the LDIF files in the order in which
you specify them from the command line.
-n. Optional. Specifies the database in your slapd.conf file for which the
conversion is performed. If this parameter is not specified, then the server uses
the first database defined in the slapd.conf file.
-O.
Optional. When you use this argument, no attribute indexes are created for the imported database. If you specify this option and you want to restore the indexes later, you will need to recreate the indexes by hand. See Chapter 7, "Managing Indexes," for more information.
-s.
Optional. Specifies the suffix or suffixes within the LDIF file you want to import. If you use -s to specify a suffix to include, and you are importing the LDIF file into your configuration directory, make sure that you also use -s to include o=NetscapeRoot. You can use multiple -s arguments. If you use both -x and -s with the same suffix, -x takes precedence. Exclusion always takes precedence over inclusion. If you do not specify -x or -s, then all available suffixes will be imported from the LDIF file.
-x.
Optional. Allows you to specify suffixes within the LDIF file to exclude during the import. You can use multiple -x arguments. This option lets you selectively import portions of the LDIF file. If you use both -x and -s with the same suffix, -x takes precedence. Exclusion always takes precedence over inclusion. If you do not specify -x or -s, then all available suffixes will be imported from the LDIF file. If you are importing the LDIF file into your configuration directory, do not exclude o=NetscapeRoot.
Warning! If you are importing the LDIF file into your configuration directory, do not exclude the suffix o=NetscapeRoot. The Netscape Administration Server uses this suffix to store information about installed Netscape Servers. Deleting this suffix could force you to reinstall all of your Netscape 4.x servers, including the directory server.
LDIF to Database Examples
Warning! If you are importing the LDIF file into your configuration directory, make sure the o=NetscapeRoot suffix and its contents are included in your LDIF file before you import. Do not exclude the suffix o=NetscapeRoot using -s, -x, or a combination of the two. The Netscape Administration Server uses this suffix to store information about installed Netscape Servers. Failure to import o=NetscapeRoot into your configuration directory could force you to reinstall (or restore from backup) all of your Netscape 4.x servers including the directory server.
Windows NT:
slapd ldif2db -f c:\Netscape\Server4\slapd-dirserver\config\slapd.conf
-C -i c:\Netscape\Server4\slapd-dirserver\ldif\demo.ldif
-i c:\Netscape\Server4\slapd-dirserver\ldif\demo2.ldif
Unix:
ns-slapd ldif2db -f
/usr/Netscape/Server4/slapd-dirserver/config/slapd.conf -C
-i /usr/Netscape/Server4/slapd-dirserver/ldif/demo.ldif
-i /usr/Netscape/Server4/slapd-dirserver/ldif/demo2.ldif
Deleting LDIF Files
If you want, you can delete LDIF files you have created. The Directory Server Console does not provide functionality to do this. Instead, you need to delete the files from the command line or through your operating system's utilities.