20110729 setindexespl for dsee7 - plembo/onemoretech GitHub Wiki

title: setindexes.pl for dsee7 link: https://onemoretech.wordpress.com/2011/07/29/setindexespl-for-dsee7/ author: lembobro description: post_id: 13 created: 2011/07/29 14:55:52 created_gmt: 2011/07/29 14:55:52 comment_status: open post_name: setindexespl-for-dsee7 status: publish post_type: post

setindexes.pl for dsee7

Remember the script from my last post? This one takes the output from that and creates the commands necessary to actually set those same indexes on another Directory Server Enterprise Edition. Of course you’re going to need to either modify the list of attributes excluded or manually edit the output to exclude attributes you already have created. This example includes a list of “excluded” attributes, ones that I didn’t want to create because they’re already on the directory. `

#!/usr/bin/perl
# setindexes.pl Create command file to set up DSEE 7 indexes
# Input has 2 comma-separated values, index name and bar-delimited
# properties (which later get made comma separated for parsing).
# Exclude elements you don't want.
# Created 5/21/2010 by P Lembo

use strict;
use Custom::Text::ParseWords;

my $dirHost = "localhost";
my $dirPort = "389";
my $basedn = "dc=example,dc=com";

my $HOME = $ENV{'HOME'};

my $infile = "$HOME/testindexes.csv";
my $outfile = "$HOME/setindexes-other.sh";

my $existing = "objectclass|objectclasses|uid|uniquemember";

open FH, "<$infile" or die $!;
open FH1, ">$outfile" or die $!;

print FH1 "#!/bin/shn";
print FH1 "# Commands to create prod indexesn";

while(<FH>) {
  chomp;

  my ($indexname,
         $indexprops

  ) = ( &parse_line(',',0,$_));

  print $indexname;

  if($indexname !~ /$existing/) {    
	print FH1 "dsconf create-index -e -i -h $dirHost -p $dirPort $basedn $indexnamen";
  }
  for ($indexprops) {
	s/|/ /g;
  }
  if($indexprops =~ / /g) {
    my @props = split(' ', $indexprops);
    foreach my $prop(@props) {
       print " $prop";
       if($prop eq 'sub') {
	print FH1 "dsconf set-index-prop -e -i -h $dirHost -p $dirPort $basedn $indexname $prop-enabled:onn";
       }
    }
  }

 print "n";
}

close FH1;
close FH;

__END__;

My apologies to the code formatting police, I was just trying like hell to fit everything nicely between the margins available. Output should look like this:dsconf create-index -e -i -w -h localhost -p 389 dc=example,dc=com odsconf set-index-prop -e -i -w -h localhost -p 389 dc=example,dc=com o sub-enabled:on dsconf create-index -e -i -w -h localhost -p 389 dc=example,dc=com ou dsconf set-index-prop -e -i -w -h localhost -p 389 dc=example,dc=com ou sub-enabled:on   The switches shown have the following meanings: -e, accept an unsecured channel -i, do not prompt for confirmation You would need “-w” or “–pwd_file” to indicate the location of a password file if you don’t have $LDAP_ADMIN_PWF set in your environment (you did do that, didn’t you?). Some possible variations here would be to include a line to actually reindex for the attribute in question, like:dsconf reindex -h localhost -p 389 -t ou dc=example,dc=comI didn’t include that because I’ll try doing a complete reindex of the tree when done:dsconf reindex -h localhost -p 389 dc=example,dc=com` Hopefully that won’t crash the directory server. Like it did last time. :-) Postscript: No, it didn’t crash the server. In fact things went quite well. When doing bulk indexing it’s always best to do as much as you can up front — before loading all your data. Makes for shorter coffee breaks, but also helps to let you knock off work before the kids have gone to bed.

Copyright 2004-2019 Phil Lembo