Previous Contents Index Next |
iPlanet Directory Server Resource Kit 5.1 Tools Reference |
Chapter 20 ldiffer.pl
The ldiffer.pl (LDAP difference) tool is a Perl script that detects differences between two LDAP directories and can perform modifications accordingly. Comparisons are based on attribute values so that directories with different DN structures and different schemas may be compared.When the tool detects comparable entries in each directory, it can be configured to add or modify attributes in either entry. The value of new or modified attributes is given as a regular expression involving other attribute values. This flexibility can be used to migrate data to a new schema or to import specific data from one directory into another.
This chapter contains the following sections:
Command Usage
Command Usage
The ldiffer.pl tool interacts with two directories. One is called "sequential" and can be considered the source of information. The other is called "random" and can be considered the target to be modified. However, the tool also allows some modifications to be made in the source directory.The script uses the ldapsearch tool (see Chapter 3) to extract a set of entries from both directories. The bind credentials, the base DN, and the filter for each search are specified separately, meaning that arbitrarily different sets of entries may be compared.
Entries from each set are matched based on equality between the value of one or more key attributes. This allows you to match entries that do not necessarily have the same DN. Because only values are compared, key attributes may also have different names in each directory.
Within a pair of matched entries, the tool then checks the values of one or more comparison attributes. A discrepancy between any of the comparison attribute values will trigger the tool to perform a set of update actions. An update action involves modifying an attribute in one of the entries based on the value of an attribute in its matched entry, after processing that value with a regular expression. The ldiffer.pl script uses the ldapmodify tool (see Chapter 4) to modify entries.
For example, an administrator may wish to migrate information from an old directory under the suffix o=Siroe.com,c=us to a new directory under dc=Siroe,dc=com. The key attribute might be employee login names that would be invariant. Then, ldiffer.pl could compare an attribute such as fax in a custom schema to facsimileTelephoneNumber in the standard schema of the new directory. Finally, the value of facsimileTelephoneNumber can be updated with the value of the fax attribute and with, for example, a new area code.
When matching entries are not found, the tool may also be configured to either delete the entry in the source directory, add it to the target directory, or both.
Due to the flexibility it offers, the ldiffer.pl script requires many parameters to describe the modifications of one or both target directories. These parameters are given in a configuration file that is named on the command line.
Syntax
The ldiffer.pl tool has the following syntax:
Where:
- ldiffer.pl configFile
configFile is the name of a file that contains all of the configuration parameters for binding to the directories, performing comparisons, and how to make any potential modifications. These parameters are described in "Configuration File Format".
All output from the script is written to log files with names and locations based on that of the configuration file:
configFile .timestamp .action.log - Displays the comparisons, additions, and modifications that were performed in a given run. Also, gives a count of the differences and lists the entries that were not successfully matched.
The ldiffer.pl script requires Perl version 5.005_03 or later. See "Where to Find Additional Information" for links to Perl resources.configFile .timestamp .debug.log - Records the commands that were executed while comparing and modifying the directories. This file is created only if the debugging parameter is specified.
If you customize the ldiffer.pl script for added functionality, we encourage you to share your work with other LDAP users. Please post a message to the iplanet.server.idsrk public news group with your ideas or your code.
Configuration File Format
The configuration file uses the following syntax:
The parameters may be given in any order, but are usually grouped according to the directory they affect. See the sample configuration file in "Configuration File Example".
- # line of comment
parameter :value
...
You will need to specify values for all of the parameters in the configuration file before running ldiffer.pl. Due to the potential complexity of comparisons and updates, we recommend testing your configuration files on mock directories with the debugging parameter turned on.
The global parameters in the following table affect the behavior of the tool.
All other parameters have one of the following prefixes:
sqn_ for parameters that apply to the "sequential," or source, directory.
The connection parameters determine the LDAP directories to operate upon and give the bind credentials for accessing them.rnd_ for parameters that apply to the "random," or target, directory.
The comparison parameters determine the set of entries to compare, how to match entries from each directory, and the attribute values that will trigger actions.
Table 20-3    Comparison Parameters in the ldiffer.pl Configuration File
Parameter
Purpose
Specify the base DN and filter string used to search each directory. The filter string should be an RFC 2254-compliant LDAP search filter (see "LDAP Search Filters" in Appendix B of the iPlanet Directory Server Administrator's Guide), for example: uid=*
These parameters determine the set of entries that will be compared from each directory. These parameter values are not necessarily identical, as the ldiffer.pl tool allows you to match entries based on any attribute values, not only the DN of an entry.
Specify the names of the key attributes whose values must be equal in order to match an entry from each directory. These parameters may contain multiple attribute names in a comma separated list.
These lists may contain different attribute names, but they must contain the same number of names. In order for two entries to match, all attribute values must match in the order that the attribute names are given in their respective list. To match entries based on their DN, specify the dn attribute in both parameters.
Specify the names of the comparison attributes for entries from each directory. These are also comma separated lists containing an equal number of attribute names.
When two entries match according to the key attributes, the values of the comparison attributes are compared, again in the order that the attribute names are given in their respective list. If any one of the comparison attribute values differ in the pair, the two entries will be modified according to the action parameters. To perform a DN-based comparison, specify the dn attribute in both lists.
If any one of the attributes does not exist in its respective entry, the comparison will fail but no action will be triggered.
If you wish to trigger an action for every pair of matching entries, you must specify a single attribute name in each list parameter that you know will have a value and be different on each entry.
The action parameters in the following table determine what modifications will be made when matching entries fail the comparison or when entries fail to match. These parameters are complex lists of the following format:
Where each Statement has the following syntax:
- Statement1 ,Statement2 ,...
The regularExpression must follow the syntax for Perl regular expressions. Regular expressions may also be omitted, but the punctuation of the list must be respected, for example:
- AttributeName ;otherAttribute ;regularExpression
All actions specified by parameters in the previous table will be triggered when a pair of matching entries fail the comparison. Thus, you may configure ldiffer.pl to add attributes or modify entries in both directories. Leave parameters blank if that specific action is not required. For example, if you do not wish to modify the source "sqn" directory, do not define the sqn_add_attrs or sqn_mod_attrs parameters.
- givenName;firstName;,sn;lastName;
The tool currently offers less flexibility for entries that do not match. After pairing up all entries in the chosen set from each directory, ldiffer.pl can only determine those entries from the source "sqn" directory that do have a match. These entries may optionally be removed from the "sqn" directory, added to the "rnd" directory, or both, according to the parameters in the following table.
Configuration File Example
The iPlanet DSRK installation includes a configuration file example named installDir /perl/ldiffer-sample.config:
This configuration example might be used in a hypothetical scenario where Siroe.com has undergone geographic expansion and has created a new LDAP directory using the standard schema. Some data has already been added to the new directory, such as employee uid and location (l). The rest of the needed information can be extracted from the legacy directory that has a custom schema.
- # Global parameters
ldapsearch:/opt/iPlanet/bin/idsrk51/ldapsearch
ldapmodify:/opt/iPlanet/bin/idsrk51/ldapmodify
debug:1
- # the delimiter should be a character that will not
# occur in the values of key attributes to match
delimiter:!
- # The "sequential" directory can be considered the source
sqn_h:legacy.siroe.com
sqn_p:389
sqn_D:cn=directory manager
sqn_w:bindPassword
sqn_b:o=Siroe.com,c=us
sqn_filter:login=*
sqn_key_attrs:login
sqn_comp_attrs:dn
sqn_add_attrs:branch;l;
sqn_mod_attrs:
sqn_del_unmatched:0
- # The "random" directory can be considered the target
rnd_h:ldap.siroe.com
rnd_p:389
rnd_D:cn=directory manager
rnd_w:bindPassword
rnd_b:dc=siroe,dc=com
rnd_filter:uid=*
rnd_key_attrs:uid
rnd_comp_attrs:dn
rnd_add_attrs:
rnd_mod_attrs:mail;email;,cn;fullName;,sn;fullName;s/.*\s//
rnd_add_unmatched:0
Running the ldiffer.pl tool with this configuration file will match entries based on the uid attribute. Then, data from the legacy directory can be used to set attributes with standard names (mail, cn, and sn) in the new directory. If these attributes do not exist in the new directory, they will be created. The value of the surname (sn) attribute is assumed to be the second word of the legacy fullName attribute, as extracted by the Perl regular expression s/.*\s//.
However, the legacy system is still in use by the human resources department, and now that Siroe.com has several offices, it needs to update the legacy directory. The tool will copy the employees' new locations into a new attribute called branch.
After the migration, Siroe.com might also wish to keep information in the legacy directory up to date, assuming that the latest modifications occur only in the new directory. The ldiffer.pl tool can be used to automate the transfer of information back into the schema of the legacy directory. Another configuration file would be needed for this scenario, in which the attribute values in the new "rnd" directory would be used to modify attributes in the legacy "sqn" directory.
Updating or creating new directories can be highly automated through the use of the ldifxform (see Chapter 18) and ldiffer.pl tools. Together, they can modify extracted information for complex operations such as porting existing data to a new schema. However, careful planning is necessary to perform a complicated sequence of transformations. Directory modifications of this scope will require special considerations such as turning off schema checking and disallowing other read and write requests while the data is in an intermediate state.
Previous Contents Index Next
Copyright 2002 Sun Microsystems, Inc.. All rights reserved.Last Updated April 15, 2002